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

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();
}
}
主站蜘蛛池模板: 隆安县| 南京市| 兴和县| 修武县| 济阳县| 汤原县| 奎屯市| 临潭县| 会理县| 峨眉山市| 桐乡市| 连州市| 长汀县| 连南| 武隆县| 石楼县| 谷城县| 延长县| 泊头市| 沂水县| 山丹县| 雅安市| 清水河县| 治县。| 那曲县| 长沙市| 卫辉市| 都兰县| 安福县| 龙南县| 嘉禾县| 平乐县| 会同县| 琼结县| 惠州市| 双江| 美姑县| 霍林郭勒市| 阜宁县| 琼中| 平利县|