- Java EE 8 Design Patterns and Best Practices
- Rhuan Rocha Jo?o Purifica??o
- 155字
- 2021-07-23 16:55:01
Implementing the TransactionFactory class
In the following code, we have the Transactional annotation, which is a Qualifier used to inject the Transaction class:
import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface Transactional {
}
In the preceding code block, we have the TransactionFactory class, which is responsible for creating new instances of the Transaction class. This class uses the @Singleton annotation, which is an EJB annotation used to create a singleton pattern with the Java EE mechanism. The getTransaction method has the @Produces annotation, used to define a method responsible for creating a new instance, and the @Transactional annotation, used as a qualify:
import javax.ejb.Singleton;
import javax.enterprise.inject.Produces;
@Singleton
public class TransactionFactory {
public @Produces @Transactional Transaction getTransaction(){
//Logic to create Transations.
return new Transaction();
}
}
推薦閱讀
- Linux設備驅動開發詳解:基于最新的Linux4.0內核
- 操作系統實用教程(Linux版)
- Implementing Cisco UCS Solutions
- 開源安全運維平臺OSSIM疑難解析:入門篇
- Linux自動化運維:Shell與Ansible(微課版)
- Learning Bootstrap
- 巧學活用Windows 7
- Dreamweaver CS5.5 Mobile and Web Development with HTML5,CSS3,and jQuery
- Learning Magento 2 Administration
- Delphi Programming Projects
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- Linux服務器配置與管理
- OpenSolaris設備驅動原理與開發
- Linux系統最佳實踐工具:命令行技術
- 統信UOS應用開發進階教程