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

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();
}
}
主站蜘蛛池模板: 顺平县| 墨玉县| 桂林市| 安平县| 呼图壁县| 祁连县| 邻水| 淮阳县| 延吉市| 页游| 梅州市| 淳安县| 宜兰市| 青川县| 磴口县| 德庆县| 张家界市| 南通市| 城固县| 镇宁| 鱼台县| 新乡市| 信宜市| 布拖县| 丹寨县| 邻水| 米脂县| 古浪县| 宁蒗| 中西区| 璧山县| 禹城市| 东乌珠穆沁旗| 沙坪坝区| 淮阳县| 凉山| 都昌县| 柞水县| 潮安县| 全椒县| 承德县|