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

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();

}


}
主站蜘蛛池模板: 衡山县| 昭觉县| 枣阳市| 灌阳县| 凤城市| 保靖县| 新泰市| 襄汾县| 九寨沟县| 邓州市| 泸州市| 凌海市| 绥滨县| 额尔古纳市| 鹰潭市| 宣威市| 沈丘县| 滕州市| 罗平县| 定南县| 怀安县| 通许县| 荥经县| 慈利县| 中超| 海阳市| 当阳市| 清流县| 安阳市| 乳山市| 乡宁县| 浦城县| 锦州市| 高州市| 长岛县| 方山县| 类乌齐县| 依兰县| 沁源县| 会同县| 玛纳斯县|