- 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();
}
}
推薦閱讀
- Implementing Cisco UCS Solutions
- Mobile-first Bootstrap
- Linux Mint Essentials
- Haskell Financial Data Modeling and Predictive Analytics
- Ganglia系統監控
- 混沌工程實戰:手把手教你實現系統穩定性
- 完美應用RHEL 8
- Kali Linux高級滲透測試
- Windows Server 2008組網技術與實訓(第3版)
- Web Penetration Testing with Kali Linux(Third Edition)
- Java EE 8 High Performance
- Less Web Development Essentials
- 電腦辦公(Windows10+Office2016)從新手到高手
- 程序員必讀經典(算法基礎+計算機系統)
- Getting Started with Raspberry Pi Zero