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 getPersistenceManagermethodhas the@Producesannotation, which is used to define a method responsible for creating a new instance. It also has the@Persistenceannotation, 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(); }