官术网_书友最值得收藏!

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();
}
}
主站蜘蛛池模板: 金平| 称多县| 延庆县| 阳东县| 隆昌县| 惠水县| 南投县| 白玉县| 安多县| 洛宁县| 河曲县| 绿春县| 林州市| 逊克县| 彩票| 紫阳县| 政和县| 富源县| 黑河市| 资兴市| 普定县| 依安县| 城口县| 青河县| 休宁县| 临邑县| 习水县| 洛南县| 崇左市| 天祝| 搜索| 乌兰县| 祁阳县| 洞头县| 敖汉旗| 府谷县| 青川县| 建瓯市| 泌阳县| 常州市| 广南县|