public Object get(String identifier) { Object object = environment.get(identifier); if ( object == null && delegate != null ) { object = this.delegate.get( identifier ); } return object; }
public void afterPropertiesSet() throws Exception { environment = EnvironmentFactory.newEnvironment(); if ( entityManagerFactory != null ) { environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, entityManagerFactory); } if ( transactionManager != null ){ environment.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager); } if ( globals != null ) { environment.set(EnvironmentName.GLOBALS, globals); } if ( dateFormats != null ) { environment.set(EnvironmentName.DATE_FORMATS, dateFormats); } if ( calendars != null ) { environment.set(EnvironmentName.CALENDARS, calendars); } if ( objectMarshallersOrder != null && objectMarshallersOrder.size() > 0 ) { List<ObjectMarshallingStrategy> strategies = getStrategies(); environment.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,strategies.toArray(new ObjectMarshallingStrategy[]{})); } if ( appScopedEntityManager != null ) { environment.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, appScopedEntityManager); } if ( cmdScopedEntityManager != null ) { environment.set(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, cmdScopedEntityManager); } }
public void beginCommandScopedEntityManager() { EntityManager cmdScopedEntityManager = (EntityManager) env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER ); if ( cmdScopedEntityManager == null || !cmdScopedEntityManager.isOpen() ) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( "cmdEM" ); EntityManager em = null; if ( emHolder == null ) { em = this.emf.createEntityManager(); emHolder = new EntityManagerHolder( em ); TransactionSynchronizationManager.bindResource( "cmdEM", emHolder ); } else { em = emHolder.getEntityManager(); } this.env.set( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, em ); } if (isJTA) { this.getCommandScopedPersistenceContext().joinTransaction(); this.appScopedEntityManager.joinTransaction(); } }
public void beginCommandScopedEntityManager() { EntityManager cmdScopedEntityManager = (EntityManager) env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER ); if ( cmdScopedEntityManager == null || !cmdScopedEntityManager.isOpen() ) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( "cmdEM" ); EntityManager em = null; if ( emHolder == null ) { em = this.emf.createEntityManager(); emHolder = new EntityManagerHolder( em ); TransactionSynchronizationManager.bindResource( "cmdEM", emHolder ); } else { em = emHolder.getEntityManager(); } this.env.set( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, em ); } if (isJTA) { this.getCommandScopedPersistenceContext().joinTransaction(); this.appScopedEntityManager.joinTransaction(); } }
/** * This method creates a entity manager. */ private EntityManager getEntityManager() { EntityManager em = (EntityManager) env.get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER); if (em != null) { sharedEM = true; return em; } EntityManagerFactory emf = (EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY); if (emf != null) { return emf.createEntityManager(); } throw new RuntimeException("Could not find EntityManager, both command-scoped EM and EMF in environment are null"); }
public void beginCommandScopedEntityManager() { EntityManager cmdScopedEntityManager = (EntityManager) env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER ); if ( cmdScopedEntityManager == null || !cmdScopedEntityManager.isOpen() ) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( "cmdEM" ); EntityManager em = null; if ( emHolder == null ) { em = this.emf.createEntityManager(); emHolder = new EntityManagerHolder( em ); TransactionSynchronizationManager.bindResource( "cmdEM", emHolder ); } else { em = emHolder.getEntityManager(); } this.env.set( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, em ); } if (isJTA) { this.getCommandScopedPersistenceContext().joinTransaction(); this.appScopedEntityManager.joinTransaction(); } }
public void afterPropertiesSet() throws Exception { environment = EnvironmentFactory.newEnvironment(); if ( entityManagerFactory != null ) { environment.set(EnvironmentName.ENTITY_MANAGER_FACTORY, entityManagerFactory); } if ( transactionManager != null ){ environment.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager); } if ( globals != null ) { environment.set(EnvironmentName.GLOBALS, globals); } if ( dateFormats != null ) { environment.set(EnvironmentName.DATE_FORMATS, dateFormats); } if ( calendars != null ) { environment.set(EnvironmentName.CALENDARS, calendars); } if ( objectMarshallersOrder != null && objectMarshallersOrder.size() > 0 ) { List<ObjectMarshallingStrategy> strategies = getStrategies(); environment.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,strategies.toArray(new ObjectMarshallingStrategy[]{})); } if ( appScopedEntityManager != null ) { environment.set(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, appScopedEntityManager); } if ( cmdScopedEntityManager != null ) { environment.set(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, cmdScopedEntityManager); } }
public DroolsSpringJpaManager(Environment env) { this.env = env; this.emf = (EntityManagerFactory) env.get( EnvironmentName.ENTITY_MANAGER_FACTORY ); isJTA = true; Boolean bool = (Boolean) env.get("IS_JTA_TRANSACTION"); if (bool != null) { isJTA = bool.booleanValue(); } getApplicationScopedPersistenceContext(); // we create this on initialisation so that we own the EMF reference // otherwise Spring will close it after the transaction finishes }
public PersistenceContext getApplicationScopedPersistenceContext() { if ( this.appScopedEntityManager == null ) { // Use the App scoped EntityManager if the user has provided it, and it is open. this.appScopedEntityManager = (EntityManager) this.env.get( EnvironmentName.APP_SCOPED_ENTITY_MANAGER ); if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) { throw new RuntimeException( "Provided APP_SCOPED_ENTITY_MANAGER is not open" ); } if ( this.appScopedEntityManager == null ) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( this.emf ); if ( emHolder == null ) { this.appScopedEntityManager = this.emf.createEntityManager(); emHolder = new EntityManagerHolder( this.appScopedEntityManager ); TransactionSynchronizationManager.bindResource( this.emf, emHolder ); internalAppScopedEntityManager = true; } else { this.appScopedEntityManager = emHolder.getEntityManager(); } this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER, emHolder.getEntityManager() ); } } if ( TransactionSynchronizationManager.isActualTransactionActive() && isJTA) { this.appScopedEntityManager.joinTransaction(); } return new JpaPersistenceContext( this.appScopedEntityManager, isJTA ); }
/** * Creates a new Environment with the specified overrides. * @param overrides the specified overrides * @return the environment */ public static Environment getEnvironment(Map<String, Object> overrides) { Environment env = EnvironmentFactory.newEnvironment(); // set the default global resolver env.set(EnvironmentName.GLOBALS, new MapGlobalResolver()); // apply any overrides if (overrides != null) { for (Map.Entry<String, Object> entry : overrides.entrySet()) { env.set(entry.getKey(), entry.getValue()); } } return env; }
public DroolsSpringJpaManager(Environment env) { this.env = env; this.emf = (EntityManagerFactory) env.get( EnvironmentName.ENTITY_MANAGER_FACTORY ); isJTA = true; Boolean bool = (Boolean) env.get("IS_JTA_TRANSACTION"); if (bool != null) { isJTA = bool.booleanValue(); } getApplicationScopedPersistenceContext(); // we create this on initialisation so that we own the EMF reference // otherwise Spring will close it after the transaction finishes }
public PersistenceContext getApplicationScopedPersistenceContext() { if ( this.appScopedEntityManager == null ) { // Use the App scoped EntityManager if the user has provided it, and it is open. this.appScopedEntityManager = (EntityManager) this.env.get( EnvironmentName.APP_SCOPED_ENTITY_MANAGER ); if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) { throw new RuntimeException( "Provided APP_SCOPED_ENTITY_MANAGER is not open" ); } if ( this.appScopedEntityManager == null ) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( this.emf ); if ( emHolder == null ) { this.appScopedEntityManager = this.emf.createEntityManager(); emHolder = new EntityManagerHolder( this.appScopedEntityManager ); TransactionSynchronizationManager.bindResource( this.emf, emHolder ); internalAppScopedEntityManager = true; } else { this.appScopedEntityManager = emHolder.getEntityManager(); } this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER, emHolder.getEntityManager() ); } } if ( TransactionSynchronizationManager.isActualTransactionActive() && isJTA) { this.appScopedEntityManager.joinTransaction(); } return new JpaPersistenceContext( this.appScopedEntityManager, isJTA ); }
public static Environment newEnvironment() { Environment env = new EnvironmentImpl(); env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[]{new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT)}); return env; // Environment environment = EnvironmentFactory.environment.get(); // if (environment == null) { // environment = new EnvironmentImpl(); // EnvironmentFactory.environment.set(environment); // } // return environment; }
public DroolsSpringJpaManager(Environment env) { this.env = env; this.emf = (EntityManagerFactory) env.get( EnvironmentName.ENTITY_MANAGER_FACTORY ); isJTA = true; Boolean bool = (Boolean) env.get("IS_JTA_TRANSACTION"); if (bool != null) { isJTA = bool.booleanValue(); } getApplicationScopedPersistenceContext(); // we create this on initialisation so that we own the EMF reference // otherwise Spring will close it after the transaction finishes }
public PersistenceContext getApplicationScopedPersistenceContext() { if ( this.appScopedEntityManager == null ) { // Use the App scoped EntityManager if the user has provided it, and it is open. this.appScopedEntityManager = (EntityManager) this.env.get( EnvironmentName.APP_SCOPED_ENTITY_MANAGER ); if ( this.appScopedEntityManager != null && !this.appScopedEntityManager.isOpen() ) { throw new RuntimeException( "Provided APP_SCOPED_ENTITY_MANAGER is not open" ); } if ( this.appScopedEntityManager == null ) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource( this.emf ); if ( emHolder == null ) { this.appScopedEntityManager = this.emf.createEntityManager(); emHolder = new EntityManagerHolder( this.appScopedEntityManager ); TransactionSynchronizationManager.bindResource( this.emf, emHolder ); internalAppScopedEntityManager = true; } else { this.appScopedEntityManager = emHolder.getEntityManager(); } this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER, emHolder.getEntityManager() ); } } if ( TransactionSynchronizationManager.isActualTransactionActive() && isJTA) { this.appScopedEntityManager.joinTransaction(); } return new JpaPersistenceContext( this.appScopedEntityManager, isJTA ); }
public void dispose() { logger.trace( "Disposing DroolsSpringJpaManager" ); if ( internalAppScopedEntityManager ) { //TransactionSynchronizationManager.unbindResource( "appEM" ); TransactionSynchronizationManager.unbindResource( this.emf ); if ( this.appScopedEntityManager != null && this.appScopedEntityManager.isOpen() ) { this.appScopedEntityManager.close(); this.internalAppScopedEntityManager = false; this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER, null ); this.appScopedEntityManager = null; } this.endCommandScopedEntityManager(); } }
public void clearPersistenceContext() { if ( TransactionSynchronizationManager.hasResource( "cmdEM" ) ) { EntityManager cmdScopedEntityManager = (EntityManager) this.env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER ); if ( cmdScopedEntityManager != null ) { cmdScopedEntityManager.clear(); } } }
actionQueue = new ConcurrentLinkedQueue<WorkingMemoryAction>(); Globals globals = (Globals) this.environment.get( EnvironmentName.GLOBALS ); if ( globals != null ) { if ( !(globals instanceof GlobalResolver) ) { this.dateFormats = (DateFormats) this.environment.get( EnvironmentName.DATE_FORMATS ); if ( this.dateFormats == null ) { this.dateFormats = new DateFormatsImpl(); this.environment.set( EnvironmentName.DATE_FORMATS, this.dateFormats );
public void dispose() { logger.trace( "Disposing DroolsSpringJpaManager" ); if ( internalAppScopedEntityManager ) { //TransactionSynchronizationManager.unbindResource( "appEM" ); TransactionSynchronizationManager.unbindResource( this.emf ); if ( this.appScopedEntityManager != null && this.appScopedEntityManager.isOpen() ) { this.appScopedEntityManager.close(); this.internalAppScopedEntityManager = false; this.env.set( EnvironmentName.APP_SCOPED_ENTITY_MANAGER, null ); this.appScopedEntityManager = null; } this.endCommandScopedEntityManager(); } }
public void clearPersistenceContext() { if ( TransactionSynchronizationManager.hasResource( "cmdEM" ) ) { EntityManager cmdScopedEntityManager = (EntityManager) this.env.get( EnvironmentName.CMD_SCOPED_ENTITY_MANAGER ); if ( cmdScopedEntityManager != null ) { cmdScopedEntityManager.clear(); } } }