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

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

}


}
主站蜘蛛池模板: 耿马| 蒲江县| 兴宁市| 上林县| 西平县| 天台县| 仙居县| 潼南县| 庆城县| 衡东县| 高邮市| 紫金县| 曲周县| 道孚县| 铅山县| 洛隆县| 咸丰县| 甘孜县| 炉霍县| 龙井市| 株洲市| 巧家县| 大新县| 虎林市| 阿拉尔市| 吉隆县| 锦屏县| 潞城市| 潍坊市| 即墨市| 万载县| 原阳县| 红原县| 积石山| 贞丰县| 汝城县| 山阴县| 蕲春县| 渑池县| 潍坊市| 永年县|