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

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();
}
}
主站蜘蛛池模板: 望江县| 陕西省| 临颍县| 和龙市| 柳州市| 武夷山市| 万源市| 梨树县| 临高县| 平塘县| 太湖县| 延吉市| 来安县| 江达县| 玛多县| 偏关县| 宿州市| 洛南县| 桂林市| 邢台市| 哈密市| 儋州市| 镇平县| 昂仁县| 东明县| 福海县| 繁昌县| 永州市| 客服| 永德县| 灵石县| 龙井市| 连江县| 曲松县| 府谷县| 霞浦县| 东宁县| 沙坪坝区| 勐海县| 江津市| 汝州市|