- 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版)
- 電腦組裝與系統安裝
- Windows Server 2012 Hyper-V:Deploying the Hyper-V Enterprise Server Virtualization Platform
- Kubernetes網絡權威指南:基礎、原理與實踐
- 玩到極致 iPhone 4S完全攻略
- Extending Bootstrap
- 奔跑吧 Linux內核(入門篇)
- macOS效率手冊
- 嵌入式系統及其應用(第三版)
- INSTANT Galleria Howto
- 新編電腦辦公(Windows 10+ Office 2013版)從入門到精通
- Learn SwiftUI
- Microsoft Azure Administrator:Exam Guide AZ-103
- 分布式實時處理系統:原理、架構與實現
- Embedded Systems Architecture