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

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();
}
}
主站蜘蛛池模板: 新营市| 徐汇区| 桂林市| 岫岩| 汽车| 白水县| 伊吾县| 会宁县| 刚察县| 蒲城县| 台南市| 卢湾区| 兴仁县| 景德镇市| 理塘县| 永吉县| 蒙自县| 夏邑县| 长海县| 龙陵县| 方正县| 荃湾区| 荆州市| 孝义市| 全椒县| 滦南县| 昌邑市| 城口县| 黄大仙区| 延寿县| 乌拉特后旗| 荆门市| 米泉市| 宽甸| 石屏县| 平罗县| 荃湾区| 阿坝县| 蓝山县| 确山县| 石景山区|