public boolean isOpen() { //adjustFlushMode(); //don't adjust, can't be done on closed EM checkEntityManagerFactory(); try { if ( open ) { getSession().isOpen(); //to force enlistment in tx } return open; } catch (HibernateException he) { throwPersistenceException( he ); return false; } }
public EntityManager createEntityManager(Map map) { //TODO support discardOnClose, persistencecontexttype?, interceptor, return new EntityManagerImpl( sessionFactory, PersistenceContextType.EXTENDED, transactionType, discardOnClose, sessionInterceptorClass, map ); }
public EntityManagerImpl( SessionFactory sessionFactory, PersistenceContextType pcType, PersistenceUnitTransactionType transactionType, boolean discardOnClose, Map properties ) { super( pcType, transactionType, properties ); this.sessionFactory = sessionFactory; this.open = true; this.discardOnClose = discardOnClose; postInit(); }
public boolean isOpen() { //adjustFlushMode(); //don't adjust, can't be done on closed EM try { if ( open ) getSession().isOpen(); //to force enlistment in tx return open; } catch (HibernateException he) { throwPersistenceException( he ); return false; } }
public void close() { checkEntityManagerFactory(); if ( !open ) { throw new IllegalStateException( "EntityManager is closed" ); } if ( !discardOnClose && isTransactionInProgress() ) { //delay the closing till the end of the enlisted transaction getSession().getTransaction().registerSynchronization(new Synchronization() { public void beforeCompletion() { // nothing to do } public void afterCompletion( int i ) { if (session != null) if (session.isOpen()) { LOG.debugf("Closing entity manager after transaction completion"); session.close(); } else LOG.entityManagerClosedBySomeoneElse(Environment.AUTO_CLOSE_SESSION); // TODO session == null should not happen } }); } else { //close right now if ( session != null ) { session.close(); } } open = false; }
public void close() { if ( !discardOnClose && isTransactionInProgress() ) { getSession().getTransaction().registerSynchronization( new Synchronization() { public void beforeCompletion() {
public static Session getHibernateSession(EntityManager entityManager) { Session session; if (entityManager.getDelegate() instanceof EntityManagerImpl) { EntityManagerImpl entityManagerImpl = (EntityManagerImpl) entityManager.getDelegate(); session = entityManagerImpl.getSession(); } else { session = (Session) entityManager.getDelegate(); } return session; }
@Override protected Session getRawSession() { if ( session == null ) { SessionBuilder sessionBuilder = getEntityManagerFactory().getSessionFactory().withOptions(); if (sessionInterceptorClass != null) { try { Interceptor interceptor = (Interceptor) sessionInterceptorClass.newInstance(); sessionBuilder.interceptor( interceptor ); } catch (InstantiationException e) { throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e); } catch (IllegalAccessException e) { throw new PersistenceException("Unable to instanciate session interceptor: " + sessionInterceptorClass, e); } catch (ClassCastException e) { throw new PersistenceException("Session interceptor does not implement Interceptor: " + sessionInterceptorClass, e); } } sessionBuilder.autoJoinTransactions( getTransactionType() != PersistenceUnitTransactionType.JTA ); session = sessionBuilder.openSession(); if ( persistenceContextType == PersistenceContextType.TRANSACTION ) { ( (SessionImplementor) session ).setAutoClear( true ); } } return session; }
private void checkEntityManagerFactory() { if (! getEntityManagerFactory().isOpen()) { open = false; } } }
@Override public Session getSession() { if ( !open ) { throw new IllegalStateException( "EntityManager is closed" ); } return getRawSession(); }
public boolean isOpen() { //adjustFlushMode(); //don't adjust, can't be done on closed EM try { if ( open ) getSession().isOpen(); //to force enlistment in tx return open; } catch (HibernateException he) { throwPersistenceException( he ); return false; } }
public void close() { if ( !discardOnClose && isTransactionInProgress() ) { getSession().getTransaction().registerSynchronization( new Synchronization() { public void beforeCompletion() {
/** * Executes some DB work that require a DataSource instance. * <p> * If we cannot get a DataSource from the connection provider, we'll just provide a * dummy DataSource that returns the connection extracted from the EntityManager as * in doWork(Work). * @param work DsWork callback interface */ public void doWork(DsWork work) { // Flush the EntityManager to make sure we have all entities available //this.em.flush(); HibernateEntityManagerFactory factory = (HibernateEntityManagerFactory) this.em.unwrap(EntityManagerImpl.class).getEntityManagerFactory(); SessionFactoryImpl sessionFactory = (SessionFactoryImpl) factory.getSessionFactory(); ConnectionProvider connProvider = sessionFactory.getConnectionProvider(); DataSource ds = null; if (connProvider instanceof DatasourceConnectionProviderImpl) { ds = ((DatasourceConnectionProviderImpl) connProvider).getDataSource(); logger.debug("Using actual DataSource to execute DataSource work: " + ds); } else { ds = new ConnectionProviderDataSource(connProvider); logger.debug("Using ConnectionProviderDataSource to execute DataSource work."); } work.execute(ds); }
public Session getSession() { if ( !open ) throw new IllegalStateException( "EntityManager is closed" ); return getRawSession(); }
public EntityManager createEntityManager(Map map) { //TODO support discardOnClose, persistencecontexttype?, interceptor, return new EntityManagerImpl( sessionFactory, PersistenceContextType.EXTENDED, transactionType, discardOnClose, map ); }
public EntityManager createEntityManager(Map map) { //TODO support discardOnClose, persistencecontexttype?, interceptor, return new EntityManagerImpl( this, PersistenceContextType.EXTENDED, transactionType, discardOnClose, sessionInterceptorClass, map ); }