HHH-10097 - Expose the UUID from SessionFactoryImplementor
This commit is contained in:
parent
4d39b38342
commit
eaf28166d2
|
@ -10,7 +10,6 @@ package org.hibernate.bytecode.enhance.spi.interceptor;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.naming.NamingException;
|
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
|
import org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker;
|
||||||
|
@ -51,12 +50,7 @@ public class LazyAttributeLoader implements PersistentAttributeInterceptor, Cons
|
||||||
|
|
||||||
this.allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled();
|
this.allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled();
|
||||||
if ( this.allowLoadOutsideTransaction ) {
|
if ( this.allowLoadOutsideTransaction ) {
|
||||||
try {
|
this.sessionFactoryUuid = session.getFactory().getUuid();
|
||||||
this.sessionFactoryUuid = (String) session.getFactory().getReference().get( "uuid" ).getContent();
|
|
||||||
}
|
|
||||||
catch (NamingException e) {
|
|
||||||
log.debug( "Unable to determine SF UUID in preparation for `allowLoadOutsideTransaction`" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import javax.naming.NamingException;
|
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -39,7 +37,6 @@ import org.hibernate.internal.util.collections.IdentitySet;
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.pretty.MessageHelper;
|
import org.hibernate.pretty.MessageHelper;
|
||||||
import org.hibernate.type.ComponentType;
|
|
||||||
import org.hibernate.type.CompositeType;
|
import org.hibernate.type.CompositeType;
|
||||||
import org.hibernate.type.IntegerType;
|
import org.hibernate.type.IntegerType;
|
||||||
import org.hibernate.type.LongType;
|
import org.hibernate.type.LongType;
|
||||||
|
@ -601,12 +598,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
||||||
allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled();
|
allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled();
|
||||||
|
|
||||||
if ( allowLoadOutsideTransaction && sessionFactoryUuid == null ) {
|
if ( allowLoadOutsideTransaction && sessionFactoryUuid == null ) {
|
||||||
try {
|
sessionFactoryUuid = session.getFactory().getUuid();
|
||||||
sessionFactoryUuid = (String) session.getFactory().getReference().get( "uuid" ).getContent();
|
|
||||||
}
|
|
||||||
catch (NamingException e) {
|
|
||||||
//not much we can do if this fails...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,6 +407,11 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
|
||||||
return delegate.getReferencedPropertyType( className, propertyName );
|
return delegate.getReferencedPropertyType( className, propertyName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUuid() {
|
||||||
|
return delegate.getUuid();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Reference getReference() throws NamingException {
|
public Reference getReference() throws NamingException {
|
||||||
return delegate.getReference();
|
return delegate.getReference();
|
||||||
|
|
|
@ -69,6 +69,16 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
|
||||||
*/
|
*/
|
||||||
Properties getProperties();
|
Properties getProperties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UUID for this SessionFactory. The value is generated as a {@link java.util.UUID}, but kept
|
||||||
|
* as a String.
|
||||||
|
*
|
||||||
|
* @return The UUID for this SessionFactory.
|
||||||
|
*
|
||||||
|
* @see org.hibernate.internal.SessionFactoryRegistry#getSessionFactory
|
||||||
|
*/
|
||||||
|
String getUuid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the persister for the named entity
|
* Get the persister for the named entity
|
||||||
*
|
*
|
||||||
|
|
|
@ -719,6 +719,11 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -870,7 +875,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
LOG.debug( "Returning a Reference to the SessionFactory" );
|
LOG.debug( "Returning a Reference to the SessionFactory" );
|
||||||
return new Reference(
|
return new Reference(
|
||||||
SessionFactoryImpl.class.getName(),
|
SessionFactoryImpl.class.getName(),
|
||||||
new StringRefAddr("uuid", uuid),
|
new StringRefAddr("uuid", getUuid()),
|
||||||
SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
|
SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
package org.hibernate.proxy;
|
package org.hibernate.proxy;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.naming.NamingException;
|
|
||||||
|
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
@ -223,15 +222,10 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
||||||
|
|
||||||
protected void prepareForPossibleLoadingOutsideTransaction() {
|
protected void prepareForPossibleLoadingOutsideTransaction() {
|
||||||
if ( session != null ) {
|
if ( session != null ) {
|
||||||
allowLoadOutsideTransaction = session.getFactory().getSettings().isInitializeLazyStateOutsideTransactionsEnabled();
|
allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled();
|
||||||
|
|
||||||
if ( allowLoadOutsideTransaction && sessionFactoryUuid == null ) {
|
if ( allowLoadOutsideTransaction && sessionFactoryUuid == null ) {
|
||||||
try {
|
sessionFactoryUuid = session.getFactory().getUuid();
|
||||||
sessionFactoryUuid = (String) session.getFactory().getReference().get( "uuid" ).getContent();
|
|
||||||
}
|
|
||||||
catch (NamingException e) {
|
|
||||||
//not much we can do if this fails...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.junit.Test;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.SessionFactoryRegistry;
|
import org.hibernate.internal.SessionFactoryRegistry;
|
||||||
import org.hibernate.internal.util.SerializationHelper;
|
import org.hibernate.internal.util.SerializationHelper;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
@ -39,9 +40,7 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||||
// different VM
|
// different VM
|
||||||
Reference reference = factory.getReference();
|
String uuid = ( (SessionFactoryImplementor) factory ).getUuid();
|
||||||
StringRefAddr refAddr = (StringRefAddr) reference.get( "uuid" );
|
|
||||||
String uuid = (String) refAddr.getContent();
|
|
||||||
// deregister under this uuid...
|
// deregister under this uuid...
|
||||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, NAME, false, null );
|
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, NAME, false, null );
|
||||||
// and then register under a different uuid...
|
// and then register under a different uuid...
|
||||||
|
@ -66,9 +65,7 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||||
// different VM
|
// different VM
|
||||||
Reference reference = factory.getReference();
|
String uuid = ( (SessionFactoryImplementor) factory ).getUuid();
|
||||||
StringRefAddr refAddr = (StringRefAddr) reference.get( "uuid" );
|
|
||||||
String uuid = (String) refAddr.getContent();
|
|
||||||
// deregister under this uuid...
|
// deregister under this uuid...
|
||||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, null, false, null );
|
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, null, false, null );
|
||||||
// and then register under a different uuid...
|
// and then register under a different uuid...
|
||||||
|
|
Loading…
Reference in New Issue