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

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();
}
}
主站蜘蛛池模板: 绥化市| 肃宁县| 扶沟县| 佛学| 临江市| 建瓯市| 通河县| 庆元县| 莱州市| 寿宁县| 新竹市| 靖州| 聂荣县| 邵武市| 霍林郭勒市| 连云港市| 扶风县| 太原市| 醴陵市| 湘西| 木里| 万全县| 灵武市| 海伦市| 阿坝县| 南乐县| 喀什市| 黑龙江省| 乌兰浩特市| 土默特右旗| 高台县| 香河县| 榆社县| 许昌市| 金昌市| 柯坪县| 宜良县| 海兴县| 松原市| 沂水县| 黄龙县|