public SessionFactory findSessionFactory(String uuid, String name) { SessionFactory sessionFactory = getSessionFactory( uuid ); if ( sessionFactory == null && StringHelper.isNotEmpty( name ) ) { sessionFactory = getNamedSessionFactory( name ); } return sessionFactory; }
@Override public SessionFactoryImplementor resolve() { return (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.findSessionFactory( uuid, name ); } };
public void performAfterClassCallbacks(Object target) { performCallbacks( afterClassOnceMethods, target ); if ( SessionFactoryRegistry.INSTANCE.hasRegistrations() ) { log.warnf( "Open SessionFactory instances found after completion of test class [%s]; closing them", testClass.getName() ); SessionFactoryRegistry.INSTANCE.clearRegistrations(); } }
/** * Get a registered SessionFactory by name * * @param name The name * * @return The SessionFactory */ public SessionFactory getNamedSessionFactory(String name) { LOG.debugf( "Lookup: name=%s", name ); final String uuid = nameUuidXref.get( name ); // protect against NPE -- see HHH-8428 return uuid == null ? null : getSessionFactory( uuid ); }
SessionFactoryRegistry.INSTANCE.addSessionFactory( getUuid(), name,
SessionFactoryRegistry.INSTANCE.removeSessionFactory( getUuid(), name,
assertSame( factory, SessionFactoryRegistry.INSTANCE.getNamedSessionFactory( NAME ) );
public void performBeforeClassCallbacks(Object target) { if ( SessionFactoryRegistry.INSTANCE.hasRegistrations() ) { log.warnf( "Open SessionFactory instances found prior to start of test class [%s]", testClass.getName() ); } performCallbacks( beforeClassOnceMethods, target ); }
@Override public Object getObjectInstance(Object reference, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { LOG.debugf( "JNDI lookup: %s", name ); final String uuid = (String) ( (Reference) reference ).get( 0 ).getContent(); LOG.tracef( "Resolved to UUID = %s", uuid ); return INSTANCE.getSessionFactory( uuid ); } }
public OgmSessionFactoryImpl(SessionFactoryImplementor delegate) { super( delegate ); try { uuid = (String) UUID_GENERATOR.generate( null, null ); } catch (Exception e) { throw new AssertionFailure( "Could not generate UUID" ); } SessionFactoryRegistry.INSTANCE.addSessionFactory( uuid, delegate.getName(), delegate.getSessionFactoryOptions().isSessionFactoryNameAlsoJndiName(), this, delegate.getServiceRegistry().getService( JndiService.class ) ); }
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, name,
@Test public void testDuplicatedDiscriminatorValueSameHierarchy() { try { tryBuildingSessionFactory( Building.class, Building1.class, Building2.class ); Assert.fail( MappingException.class.getName() + " expected when two subclasses are mapped with the same discriminator value." ); } catch ( MappingException e ) { final String errorMsg = e.getCause().getMessage(); // Check if error message contains descriptive information. Assert.assertTrue( errorMsg.contains( Building1.class.getName() ) ); Assert.assertTrue( errorMsg.contains( Building2.class.getName() ) ); Assert.assertTrue( errorMsg.contains( "discriminator value '" + DISCRIMINATOR_VALUE + "'." ) ); } assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() ); }
private static SessionFactory locateSessionFactoryOnDeserialization(String uuid, String name) throws InvalidObjectException{ final SessionFactory uuidResult = SessionFactoryRegistry.INSTANCE.getSessionFactory( uuid ); if ( uuidResult != null ) { LOG.debugf( "Resolved SessionFactory by UUID [%s]", uuid ); return uuidResult; } // in case we were deserialized in a different JVM, look for an instance with the same name // (provided we were given a name) if ( name != null ) { final SessionFactory namedResult = SessionFactoryRegistry.INSTANCE.getNamedSessionFactory( name ); if ( namedResult != null ) { LOG.debugf( "Resolved SessionFactory by name [%s]", name ); return namedResult; } } throw new InvalidObjectException( "Could not find a SessionFactory [uuid=" + uuid + ",name=" + name + "]" ); }
private SharedSessionContractImplementor openTemporarySessionForLoading() { if ( sessionFactoryUuid == null ) { throwLazyInitializationException( "SessionFactory UUID not known to create temporary Session for loading" ); } final SessionFactoryImplementor sf = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid ); final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession(); session.getPersistenceContext().setDefaultReadOnly( true ); session.setFlushMode( FlushMode.MANUAL ); return session; }
SessionFactoryStub(HibernateService service) { this.service = service; this.name = service.getJndiName(); try { uuid = (String) UUID_GENERATOR.generate(null, null); } catch (Exception e) { throw new AssertionFailure("Could not generate UUID"); } SessionFactoryRegistry.INSTANCE.addSessionFactory( uuid, name, ConfigurationHelper.getBoolean( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, service.getProperties(), true ), this, new JndiServiceImpl( service.getProperties() ) ); }
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, name,
private Object readResolve() throws InvalidObjectException { if ( sessionFactory == null ) { if ( sessionFactoryName != null || sessionFactoryUuid != null ) { sessionFactory = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.findSessionFactory( sessionFactoryUuid, sessionFactoryName ); if ( sessionFactory == null ) { throw new HibernateException( "Could not find a SessionFactory [uuid=" + sessionFactoryUuid + ",name=" + sessionFactoryName + "]" ); } } } return this; } }
public SessionFactory findSessionFactory(String uuid, String name) { SessionFactory sessionFactory = getSessionFactory( uuid ); if ( sessionFactory == null && StringHelper.isNotEmpty( name ) ) { sessionFactory = getNamedSessionFactory( name ); } return sessionFactory; }
private SharedSessionContractImplementor openTemporarySessionForLoading(LazyInitializationWork lazyInitializationWork) { if ( consumer.getSessionFactoryUuid() == null ) { throwLazyInitializationException( Cause.NO_SF_UUID, lazyInitializationWork ); } final SessionFactoryImplementor sf = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.getSessionFactory( consumer.getSessionFactoryUuid() ); final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession(); session.getPersistenceContext().setDefaultReadOnly( true ); session.setHibernateFlushMode( FlushMode.MANUAL ); return session; } }
SessionFactoryStub(HibernateService service) { this.service = service; this.name = service.getJndiName(); try { uuid = (String) UUID_GENERATOR.generate(null, null); } catch (Exception e) { throw new AssertionFailure("Could not generate UUID"); } SessionFactoryRegistry.INSTANCE.addSessionFactory( uuid, name, ConfigurationHelper.getBoolean( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, service.getProperties(), true ), this, new JndiServiceImpl( service.getProperties() ) ); }