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

Implementing the PersistenceManagerFactory class

In the following code, we have the qualify used to inject the PersistenceManager class:

import javax.inject.Qualifier;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})

public @interface Persistence {
}

Looking at the following code, we can see that we have the PersistenceManagerFactory class, which is responsible for creating new instances of PersistenceManager. This class uses the @Singleton annotation, which is an EJB annotation used to create a singleton pattern with the Java EE mechanism. The getPersistenceManager method has the @Produces annotation, which is used to define a method responsible for creating a new instance. It also has the @Persistence annotation, which is used as a qualify:

import javax.ejb.Singleton;
import javax.enterprise.inject.Produces;
import java.util.HashSet;
import java.util.Set;

@Singleton
public class PersistenceManagerFactory {

Set<StageManager> stateManagers = new HashSet<StageManager>();

public @Produces @Persistence PersistenceManager
getPersistenceManager(){

//Logic to build PersistenceManager
return new PersistenceManager();

}


}
主站蜘蛛池模板: 乌拉特后旗| 秦皇岛市| 泰兴市| 嵊州市| 浦江县| 柳河县| 鄂托克旗| 绍兴县| 曲沃县| 淮安市| 临夏县| 庄河市| 富裕县| 靖宇县| 故城县| 客服| 城固县| 封开县| 宿迁市| 黄陵县| 剑阁县| 商都县| 布拖县| 乌拉特后旗| 泸水县| 延安市| 沂源县| 安康市| 黄浦区| 东乡族自治县| 云阳县| 黔南| 定兴县| 开阳县| 榆林市| 赤峰市| 永新县| 荣成市| 武定县| 中宁县| 谷城县|