- 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系統(tǒng)開(kāi)發(fā):基于Yocto Project
- 嵌入式應(yīng)用程序設(shè)計(jì)綜合教程(微課版)
- Docker+Kubernetes應(yīng)用開(kāi)發(fā)與快速上云
- Windows 7中文版從入門到精通(修訂版)
- 突破平面3ds Max動(dòng)畫設(shè)計(jì)與制作
- Mastering Reactive JavaScript
- Windows Server 2012網(wǎng)絡(luò)操作系統(tǒng)項(xiàng)目教程(第4版)
- OpenSolaris設(shè)備驅(qū)動(dòng)原理與開(kāi)發(fā)
- Python UNIX和Linux系統(tǒng)管理指南
- Angular權(quán)威教程
- Docker容器技術(shù)與運(yùn)維
- 每天5分鐘玩轉(zhuǎn)Docker容器技術(shù)
- 樹(shù)莓派+傳感器:創(chuàng)建智能交互項(xiàng)目的實(shí)用方法、工具及最佳實(shí)踐
- Instant Responsive Web Design
- Android Telephony原理解析與開(kāi)發(fā)指南