HHH-8741 - More checkstyle cleanups
This commit is contained in:
parent
8ec17e68e7
commit
241868e1dd
|
@ -41,7 +41,9 @@ import java.util.ServiceLoader;
|
|||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.util.ClassLoaderHelper;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -50,11 +52,10 @@ import org.jboss.logging.Logger;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
||||
private static final Logger log = CoreLogging.logger( ClassLoaderServiceImpl.class );
|
||||
|
||||
private AggregatedClassLoader aggregatedClassLoader;
|
||||
|
||||
private final Map<Class, ServiceLoader> serviceLoaders = new HashMap<Class, ServiceLoader>();
|
||||
private AggregatedClassLoader aggregatedClassLoader;
|
||||
|
||||
/**
|
||||
* Constructs a ClassLoaderServiceImpl with standard set-up
|
||||
|
@ -92,7 +93,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
// normalize adding known class-loaders...
|
||||
// then the Hibernate class loader
|
||||
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );
|
||||
|
||||
|
||||
// then the TCCL, if one...
|
||||
final ClassLoader tccl = locateTCCL();
|
||||
if ( tccl != null ) {
|
||||
|
@ -157,7 +158,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
try {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
try {
|
||||
return ClassLoaderHelper.getContextClassLoader();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
|
||||
private AggregatedClassLoader(final LinkedHashSet<ClassLoader> orderedClassLoaderSet) {
|
||||
super( null );
|
||||
individualClassLoaders = orderedClassLoaderSet.toArray( new ClassLoader[ orderedClassLoaderSet.size() ] );
|
||||
individualClassLoaders = orderedClassLoaderSet.toArray( new ClassLoader[orderedClassLoaderSet.size()] );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -192,6 +193,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
|
||||
return new Enumeration<URL>() {
|
||||
final Iterator<URL> resourceUrlIterator = resourceUrls.iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
return resourceUrlIterator.hasNext();
|
||||
|
@ -228,13 +230,13 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
throw new ClassNotFoundException( "Could not load requested class : " + name );
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
individualClassLoaders = null;
|
||||
}
|
||||
}
|
||||
public void destroy() {
|
||||
individualClassLoaders = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <T> Class<T> classForName(String className) {
|
||||
try {
|
||||
return (Class<T>) Class.forName( className, true, aggregatedClassLoader );
|
||||
|
@ -250,13 +252,13 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
try {
|
||||
return new URL( name );
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
try {
|
||||
return aggregatedClassLoader.getResource( name );
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -269,17 +271,17 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
log.tracef( "trying via [new URL(\"%s\")]", name );
|
||||
return new URL( name ).openStream();
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
try {
|
||||
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", name );
|
||||
final InputStream stream = aggregatedClassLoader.getResourceAsStream( name );
|
||||
final InputStream stream = aggregatedClassLoader.getResourceAsStream( name );
|
||||
if ( stream != null ) {
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
final String stripped = name.startsWith( "/" ) ? name.substring( 1 ) : null;
|
||||
|
@ -289,7 +291,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
log.tracef( "trying via [new URL(\"%s\")]", stripped );
|
||||
return new URL( stripped ).openStream();
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -299,7 +301,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
return stream;
|
||||
}
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,13 +319,14 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch ( Exception ignore ) {
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
return urls;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
|
||||
ServiceLoader<S> serviceLoader;
|
||||
if ( serviceLoaders.containsKey( serviceContract ) ) {
|
||||
|
@ -333,7 +336,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
serviceLoader = ServiceLoader.load( serviceContract, aggregatedClassLoader );
|
||||
serviceLoaders.put( serviceContract, serviceLoader );
|
||||
}
|
||||
|
||||
|
||||
final LinkedHashSet<S> services = new LinkedHashSet<S>();
|
||||
for ( S service : serviceLoader ) {
|
||||
services.add( service );
|
||||
|
@ -341,18 +344,18 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
|||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
@Override
|
||||
public void stop() {
|
||||
for ( ServiceLoader serviceLoader : serviceLoaders.values() ) {
|
||||
serviceLoader.reload(); // clear service loader providers
|
||||
}
|
||||
serviceLoaders.clear();
|
||||
|
||||
|
||||
if ( aggregatedClassLoader != null ) {
|
||||
aggregatedClassLoader.destroy();
|
||||
aggregatedClassLoader = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// completely temporary !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
|
|
@ -30,22 +30,23 @@ import java.util.Map;
|
|||
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
|
||||
*/
|
||||
public class CollectionTracker {
|
||||
private Map<String, Integer> tracker;
|
||||
|
||||
private Map<String, Integer> tracker;
|
||||
public CollectionTracker() {
|
||||
tracker = new HashMap<String, Integer>();
|
||||
}
|
||||
|
||||
public CollectionTracker() {
|
||||
tracker = new HashMap<String, Integer>();
|
||||
}
|
||||
public void add(String name, int size) {
|
||||
tracker.put( name, size );
|
||||
}
|
||||
|
||||
public void add(String name, int size) {
|
||||
tracker.put(name, size);
|
||||
}
|
||||
|
||||
public int getSize(String name) {
|
||||
Integer size = tracker.get(name);
|
||||
if(size == null)
|
||||
return -1;
|
||||
else
|
||||
return size;
|
||||
}
|
||||
public int getSize(String name) {
|
||||
Integer size = tracker.get( name );
|
||||
if ( size == null ) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,55 +31,54 @@ import org.hibernate.engine.spi.CompositeOwner;
|
|||
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
|
||||
*/
|
||||
public class CompositeOwnerTracker {
|
||||
private String[] names;
|
||||
private CompositeOwner[] owners;
|
||||
private int size;
|
||||
|
||||
private String[] names;
|
||||
private CompositeOwner[] owners;
|
||||
private int size;
|
||||
public CompositeOwnerTracker() {
|
||||
names = new String[1];
|
||||
owners = new CompositeOwner[1];
|
||||
}
|
||||
|
||||
public CompositeOwnerTracker() {
|
||||
names = new String[1];
|
||||
owners = new CompositeOwner[1];
|
||||
}
|
||||
public void add(String name, CompositeOwner owner) {
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
if ( names[i].equals( name ) ) {
|
||||
owners[i] = owner;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( size >= names.length ) {
|
||||
String[] tmpNames = new String[size + 1];
|
||||
System.arraycopy( names, 0, tmpNames, 0, size );
|
||||
names = tmpNames;
|
||||
CompositeOwner[] tmpOwners = new CompositeOwner[size + 1];
|
||||
System.arraycopy( owners, 0, tmpOwners, 0, size );
|
||||
owners = tmpOwners;
|
||||
}
|
||||
names[size] = name;
|
||||
owners[size] = owner;
|
||||
size++;
|
||||
}
|
||||
|
||||
public void add(String name, CompositeOwner owner) {
|
||||
for(int i=0; i<size;i++) {
|
||||
if(names[i].equals(name)) {
|
||||
owners[i] = owner;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( size >= names.length) {
|
||||
String[] tmpNames = new String[size+1];
|
||||
System.arraycopy(names, 0, tmpNames, 0, size);
|
||||
names = tmpNames;
|
||||
CompositeOwner[] tmpOwners = new CompositeOwner[size+1];
|
||||
System.arraycopy(owners, 0, tmpOwners, 0, size);
|
||||
owners = tmpOwners;
|
||||
}
|
||||
names[size] = name;
|
||||
owners[size] = owner;
|
||||
size++;
|
||||
}
|
||||
public void callOwner(String fieldName) {
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
owners[i].$$_hibernate_trackChange( names[i] + fieldName );
|
||||
}
|
||||
}
|
||||
|
||||
public void callOwner(String fieldName) {
|
||||
for(int i=0; i < size;i++) {
|
||||
owners[i].$$_hibernate_trackChange(names[i]+fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOwner(String name) {
|
||||
for(int i=0; i<size;i++) {
|
||||
if(names[i].equals(name)) {
|
||||
if(i < size) {
|
||||
for(int j=i; j < size-1;j++) {
|
||||
names[j] = names[j+1];
|
||||
owners[j] = owners[j+1];
|
||||
}
|
||||
names[size-1] = null;
|
||||
owners[size-1] = null;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void removeOwner(String name) {
|
||||
for ( int i = 0; i < size; i++ ) {
|
||||
if ( names[i].equals( name ) ) {
|
||||
if ( i < size ) {
|
||||
for ( int j = i; j < size - 1; j++ ) {
|
||||
names[j] = names[j + 1];
|
||||
owners[j] = owners[j + 1];
|
||||
}
|
||||
names[size - 1] = null;
|
||||
owners[size - 1] = null;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,19 +28,18 @@ import javassist.CtField;
|
|||
|
||||
/**
|
||||
* The context for performing an enhancement. Enhancement can happen in any number of ways:<ul>
|
||||
* <li>Build time, via Ant</li>
|
||||
* <li>Build time, via Maven</li>
|
||||
* <li>Build time, via Gradle</li>
|
||||
* <li>Runtime, via agent</li>
|
||||
* <li>Runtime, via JPA constructs</li>
|
||||
* <li>Build time, via Ant</li>
|
||||
* <li>Build time, via Maven</li>
|
||||
* <li>Build time, via Gradle</li>
|
||||
* <li>Runtime, via agent</li>
|
||||
* <li>Runtime, via JPA constructs</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p/>
|
||||
* This interface isolates the code that actually does the enhancement from the underlying context in which
|
||||
* the enhancement is being performed.
|
||||
*
|
||||
* @todo Not sure its a great idea to expose Javassist classes this way. maybe wrap them in our own contracts?
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @todo Not sure its a great idea to expose Javassist classes this way. maybe wrap them in our own contracts?
|
||||
*/
|
||||
public interface EnhancementContext {
|
||||
/**
|
||||
|
@ -76,7 +75,7 @@ public interface EnhancementContext {
|
|||
* @param classDescriptor The descriptor of the class to check.
|
||||
*
|
||||
* @return {@code true} indicates that dirty checking should be in-lined within the entity; {@code false}
|
||||
* indicates it should not. In-lined is more easily serializable and probably more performant.
|
||||
* indicates it should not. In-lined is more easily serializable and probably more performant.
|
||||
*/
|
||||
public boolean doDirtyCheckingInline(CtClass classDescriptor);
|
||||
|
||||
|
@ -106,7 +105,7 @@ public interface EnhancementContext {
|
|||
/**
|
||||
* For fields which are persistent (according to {@link #isPersistentField}), determine the corresponding ordering
|
||||
* maintained within the Hibernate metamodel.
|
||||
|
||||
*
|
||||
* @param persistentFields The persistent field references.
|
||||
*
|
||||
* @return The ordered references.
|
||||
|
@ -122,10 +121,10 @@ public interface EnhancementContext {
|
|||
*/
|
||||
public boolean isLazyLoadable(CtField field);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param field the field to check
|
||||
* @return {@code true} if the field is mapped
|
||||
*/
|
||||
public boolean isMappedCollection(CtField field);
|
||||
/**
|
||||
* @param field the field to check
|
||||
*
|
||||
* @return {@code true} if the field is mapped
|
||||
*/
|
||||
public boolean isMappedCollection(CtField field);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -65,7 +65,7 @@ public class EnhancerConstants {
|
|||
|
||||
/**
|
||||
* Name of the field used to hold the previous {@link org.hibernate.engine.spi.ManagedEntity}.
|
||||
*
|
||||
* <p/>
|
||||
* Together, previous/next are used to define a "linked list"
|
||||
*
|
||||
* @see #NEXT_FIELD_NAME
|
||||
|
@ -88,7 +88,7 @@ public class EnhancerConstants {
|
|||
|
||||
/**
|
||||
* Name of the field used to hold the previous {@link org.hibernate.engine.spi.ManagedEntity}.
|
||||
*
|
||||
* <p/>
|
||||
* Together, previous/next are used to define a "linked list"
|
||||
*
|
||||
* @see #PREVIOUS_FIELD_NAME
|
||||
|
@ -128,53 +128,53 @@ public class EnhancerConstants {
|
|||
*/
|
||||
public static final String INTERCEPTOR_SETTER_NAME = "$$_hibernate_setInterceptor";
|
||||
|
||||
/**
|
||||
* Name of tracker field
|
||||
*/
|
||||
public static final String TRACKER_FIELD_NAME = "$$_hibernate_tracker";
|
||||
/**
|
||||
* Name of tracker field
|
||||
*/
|
||||
public static final String TRACKER_FIELD_NAME = "$$_hibernate_tracker";
|
||||
|
||||
/**
|
||||
* Name of method that add changed fields
|
||||
*/
|
||||
public static final String TRACKER_CHANGER_NAME = "$$_hibernate_trackChange";
|
||||
/**
|
||||
* Name of method that add changed fields
|
||||
*/
|
||||
public static final String TRACKER_CHANGER_NAME = "$$_hibernate_trackChange";
|
||||
|
||||
/**
|
||||
* Name of method to see if any fields has changed
|
||||
*/
|
||||
public static final String TRACKER_HAS_CHANGED_NAME = "$$_hibernate_hasDirtyAttributes";
|
||||
/**
|
||||
* Name of method to see if any fields has changed
|
||||
*/
|
||||
public static final String TRACKER_HAS_CHANGED_NAME = "$$_hibernate_hasDirtyAttributes";
|
||||
|
||||
/**
|
||||
* Name of method to fetch dirty attributes
|
||||
*/
|
||||
public static final String TRACKER_GET_NAME = "$$_hibernate_getDirtyAttributes";
|
||||
/**
|
||||
* Name of method to fetch dirty attributes
|
||||
*/
|
||||
public static final String TRACKER_GET_NAME = "$$_hibernate_getDirtyAttributes";
|
||||
|
||||
/**
|
||||
* Name of method to clear stored dirty attributes
|
||||
*/
|
||||
public static final String TRACKER_CLEAR_NAME = "$$_hibernate_clearDirtyAttributes";
|
||||
/**
|
||||
* Name of method to clear stored dirty attributes
|
||||
*/
|
||||
public static final String TRACKER_CLEAR_NAME = "$$_hibernate_clearDirtyAttributes";
|
||||
|
||||
/**
|
||||
* Name of method to check if collection fields are dirty
|
||||
*/
|
||||
public static final String TRACKER_COLLECTION_CHANGED_NAME = "$$_hibernate_areCollectionFieldsDirty";
|
||||
/**
|
||||
* Name of method to check if collection fields are dirty
|
||||
*/
|
||||
public static final String TRACKER_COLLECTION_CHANGED_NAME = "$$_hibernate_areCollectionFieldsDirty";
|
||||
|
||||
public static final String TRACKER_COLLECTION_NAME = "$$_hibernate_collectionTracker";
|
||||
/**
|
||||
* Name of method to get dirty collection field names
|
||||
*/
|
||||
public static final String TRACKER_COLLECTION_CHANGED_FIELD_NAME = "$$_hibernate_getCollectionFieldDirtyNames";
|
||||
public static final String TRACKER_COLLECTION_NAME = "$$_hibernate_collectionTracker";
|
||||
/**
|
||||
* Name of method to get dirty collection field names
|
||||
*/
|
||||
public static final String TRACKER_COLLECTION_CHANGED_FIELD_NAME = "$$_hibernate_getCollectionFieldDirtyNames";
|
||||
|
||||
public static final String TRACKER_COLLECTION_CLEAR_NAME = "$$_hibernate_clearDirtyCollectionNames";
|
||||
public static final String TRACKER_COLLECTION_CLEAR_NAME = "$$_hibernate_clearDirtyCollectionNames";
|
||||
|
||||
public static final String TRACKER_COMPOSITE_DIRTY_CHECK = "$$_hibernate_areCompositeFieldsDirty";
|
||||
public static final String TRACKER_COMPOSITE_DIRTY_CHECK = "$$_hibernate_areCompositeFieldsDirty";
|
||||
|
||||
public static final String TRACKER_COMPOSITE_DIRTY_FIELDS_GETTER = "$$_hibernate_getCompositeDirtyFields";
|
||||
public static final String TRACKER_COMPOSITE_DIRTY_FIELDS_GETTER = "$$_hibernate_getCompositeDirtyFields";
|
||||
|
||||
public static final String TRACKER_COMPOSITE_FIELD_NAME = "$$_hibernate_compositeOwners";
|
||||
public static final String TRACKER_COMPOSITE_FIELD_NAME = "$$_hibernate_compositeOwners";
|
||||
|
||||
public static final String TRACKER_COMPOSITE_SET_OWNER = "$$_hibernate_setOwner";
|
||||
public static final String TRACKER_COMPOSITE_SET_OWNER = "$$_hibernate_setOwner";
|
||||
|
||||
public static final String TRACKER_COMPOSITE_CLEAR_OWNER = "$$_hibernate_clearOwner";
|
||||
public static final String TRACKER_COMPOSITE_CLEAR_OWNER = "$$_hibernate_clearOwner";
|
||||
|
||||
private EnhancerConstants() {
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ import org.hibernate.type.AssociationType;
|
|||
* @see JoinFragment
|
||||
*/
|
||||
public class JoinSequence {
|
||||
private final SessionFactoryImplementor factory;
|
||||
private final SessionFactoryImplementor factory;
|
||||
|
||||
private final StringBuilder conditions = new StringBuilder();
|
||||
private final List<Join> joins = new ArrayList<Join>();
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import org.hibernate.engine.jdbc.internal.FormatStyle;
|
||||
import org.hibernate.engine.jdbc.internal.Formatter;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
|
||||
/**
|
||||
* Centralize logging for SQL statements.
|
||||
|
@ -35,8 +35,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SqlStatementLogger {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, "org.hibernate.SQL");
|
||||
private static final Logger LOG = CoreLogging.logger( "org.hibernate.SQL" );
|
||||
|
||||
private boolean logToStdout;
|
||||
private boolean format;
|
||||
|
|
|
@ -48,8 +48,8 @@ public class NativeSQLQuerySpecification {
|
|||
|
||||
public NativeSQLQuerySpecification(
|
||||
String queryString,
|
||||
NativeSQLQueryReturn[] queryReturns,
|
||||
Collection querySpaces) {
|
||||
NativeSQLQueryReturn[] queryReturns,
|
||||
Collection querySpaces) {
|
||||
this.queryString = queryString;
|
||||
this.queryReturns = queryReturns;
|
||||
if ( querySpaces == null ) {
|
||||
|
@ -83,7 +83,7 @@ public class NativeSQLQuerySpecification {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -91,16 +91,15 @@ public class NativeSQLQuerySpecification {
|
|||
return false;
|
||||
}
|
||||
|
||||
final NativeSQLQuerySpecification that = ( NativeSQLQuerySpecification ) o;
|
||||
final NativeSQLQuerySpecification that = (NativeSQLQuerySpecification) o;
|
||||
|
||||
return querySpaces.equals( that.querySpaces ) &&
|
||||
queryString.equals( that.queryString ) &&
|
||||
Arrays.equals( queryReturns, that.queryReturns );
|
||||
return querySpaces.equals( that.querySpaces )
|
||||
&& queryString.equals( that.queryString )
|
||||
&& Arrays.equals( queryReturns, that.queryReturns );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.hibernate.EntityMode;
|
|||
import org.hibernate.cache.spi.CacheKey;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.internal.CacheHelper;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
|
@ -50,7 +50,7 @@ import org.hibernate.persister.entity.EntityPersister;
|
|||
* @author Guenther Demetz
|
||||
*/
|
||||
public class BatchFetchQueue {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, BatchFetchQueue.class.getName() );
|
||||
private static final Logger LOG = CoreLogging.logger( BatchFetchQueue.class );
|
||||
|
||||
private final PersistenceContext context;
|
||||
|
||||
|
@ -334,8 +334,8 @@ public class BatchFetchQueue {
|
|||
if ( persister.hasCache() ) {
|
||||
CacheKey cacheKey = context.getSession().generateCacheKey(
|
||||
collectionKey,
|
||||
persister.getKeyType(),
|
||||
persister.getRole()
|
||||
persister.getKeyType(),
|
||||
persister.getRole()
|
||||
);
|
||||
return CacheHelper.fromSharedCache( context.getSession(), cacheKey, persister.getCacheAccessStrategy() ) != null;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.collection.internal.AbstractPersistentCollection;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
||||
|
@ -47,8 +47,7 @@ import org.hibernate.pretty.MessageHelper;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public final class CollectionEntry implements Serializable {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, CollectionEntry.class.getName());
|
||||
private static final Logger LOG = CoreLogging.logger( CollectionEntry.class );
|
||||
|
||||
//ATTRIBUTES MAINTAINED BETWEEN FLUSH CYCLES
|
||||
|
||||
|
@ -152,9 +151,9 @@ public final class CollectionEntry implements Serializable {
|
|||
*/
|
||||
private CollectionEntry(
|
||||
String role,
|
||||
Serializable snapshot,
|
||||
Serializable loadedKey,
|
||||
SessionFactoryImplementor factory) {
|
||||
Serializable snapshot,
|
||||
Serializable loadedKey,
|
||||
SessionFactoryImplementor factory) {
|
||||
this.role = role;
|
||||
this.snapshot = snapshot;
|
||||
this.loadedKey = loadedKey;
|
||||
|
@ -378,10 +377,10 @@ public final class CollectionEntry implements Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString() {
|
||||
String result = "CollectionEntry" +
|
||||
MessageHelper.collectionInfoString( loadedPersister.getRole(), loadedKey );
|
||||
if (currentPersister!=null) {
|
||||
if ( currentPersister != null ) {
|
||||
result += "->" +
|
||||
MessageHelper.collectionInfoString( currentPersister.getRole(), currentKey );
|
||||
}
|
||||
|
@ -429,18 +428,20 @@ public final class CollectionEntry implements Serializable {
|
|||
*
|
||||
* @param ois The stream from which to read the entry.
|
||||
* @param session The session being deserialized.
|
||||
*
|
||||
* @return The deserialized CollectionEntry
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public static CollectionEntry deserialize(
|
||||
ObjectInputStream ois,
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
return new CollectionEntry(
|
||||
( String ) ois.readObject(),
|
||||
( Serializable ) ois.readObject(),
|
||||
( Serializable ) ois.readObject(),
|
||||
( session == null ? null : session.getFactory() )
|
||||
(String) ois.readObject(),
|
||||
(Serializable) ois.readObject(),
|
||||
(Serializable) ois.readObject(),
|
||||
(session == null ? null : session.getFactory())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,8 @@ package org.hibernate.engine.spi;
|
|||
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
|
||||
*/
|
||||
public interface CompositeOwner {
|
||||
|
||||
/**
|
||||
* @param attributeName to be added to the dirty list
|
||||
*/
|
||||
void $$_hibernate_trackChange(String attributeName);
|
||||
/**
|
||||
* @param attributeName to be added to the dirty list
|
||||
*/
|
||||
void $$_hibernate_trackChange(String attributeName);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ package org.hibernate.engine.spi;
|
|||
*/
|
||||
public interface CompositeTracker {
|
||||
|
||||
void $$_hibernate_setOwner(String name, CompositeOwner tracker);
|
||||
void $$_hibernate_setOwner(String name, CompositeOwner tracker);
|
||||
|
||||
void $$_hibernate_clearOwner(String name);
|
||||
void $$_hibernate_clearOwner(String name);
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ import org.hibernate.type.Type;
|
|||
* Uniqueing information consists of the entity-name, the referenced
|
||||
* property name, and the referenced property value.
|
||||
*
|
||||
* @see EntityKey
|
||||
* @author Gavin King
|
||||
* @see EntityKey
|
||||
*/
|
||||
public class EntityUniqueKey implements Serializable {
|
||||
private final String uniqueKeyName;
|
||||
|
@ -52,18 +52,17 @@ public class EntityUniqueKey implements Serializable {
|
|||
|
||||
public EntityUniqueKey(
|
||||
final String entityName,
|
||||
final String uniqueKeyName,
|
||||
final Object semiResolvedKey,
|
||||
final Type keyType,
|
||||
final EntityMode entityMode,
|
||||
final SessionFactoryImplementor factory
|
||||
) {
|
||||
final String uniqueKeyName,
|
||||
final Object semiResolvedKey,
|
||||
final Type keyType,
|
||||
final EntityMode entityMode,
|
||||
final SessionFactoryImplementor factory) {
|
||||
this.uniqueKeyName = uniqueKeyName;
|
||||
this.entityName = entityName;
|
||||
this.key = semiResolvedKey;
|
||||
this.keyType = keyType.getSemiResolvedType(factory);
|
||||
this.keyType = keyType.getSemiResolvedType( factory );
|
||||
this.entityMode = entityMode;
|
||||
this.hashCode = generateHashCode(factory);
|
||||
this.hashCode = generateHashCode( factory );
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
|
@ -82,23 +81,26 @@ public class EntityUniqueKey implements Serializable {
|
|||
int result = 17;
|
||||
result = 37 * result + entityName.hashCode();
|
||||
result = 37 * result + uniqueKeyName.hashCode();
|
||||
result = 37 * result + keyType.getHashCode(key, factory);
|
||||
result = 37 * result + keyType.getHashCode( key, factory );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
EntityUniqueKey that = (EntityUniqueKey) other;
|
||||
return that.entityName.equals(entityName) &&
|
||||
that.uniqueKeyName.equals(uniqueKeyName) &&
|
||||
keyType.isEqual(that.key, key );
|
||||
return that.entityName.equals( entityName )
|
||||
&& that.uniqueKeyName.equals( uniqueKeyName )
|
||||
&& keyType.isEqual( that.key, key );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityUniqueKey" + MessageHelper.infoString(entityName, uniqueKeyName, key);
|
||||
return "EntityUniqueKey" + MessageHelper.infoString( entityName, uniqueKeyName, key );
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
|
@ -110,10 +112,10 @@ public class EntityUniqueKey implements Serializable {
|
|||
// The unique property value represented here may or may not be
|
||||
// serializable, so we do an explicit check here in order to generate
|
||||
// a better error message
|
||||
if ( key != null && ! Serializable.class.isAssignableFrom( key.getClass() ) ) {
|
||||
if ( key != null && !Serializable.class.isAssignableFrom( key.getClass() ) ) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot serialize an EntityUniqueKey which represents a non " +
|
||||
"serializable property value [" + entityName + "." + uniqueKeyName + "]"
|
||||
"serializable property value [" + entityName + "." + uniqueKeyName + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +125,7 @@ public class EntityUniqueKey implements Serializable {
|
|||
* Session/PersistenceContext for increased performance.
|
||||
*
|
||||
* @param oos The stream to which we should write the serial data.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void serialize(ObjectOutputStream oos) throws IOException {
|
||||
|
@ -140,20 +143,22 @@ public class EntityUniqueKey implements Serializable {
|
|||
*
|
||||
* @param ois The stream from which to read the entry.
|
||||
* @param session The session being deserialized.
|
||||
*
|
||||
* @return The deserialized EntityEntry
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public static EntityUniqueKey deserialize(
|
||||
ObjectInputStream ois,
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
SessionImplementor session) throws IOException, ClassNotFoundException {
|
||||
return new EntityUniqueKey(
|
||||
( String ) ois.readObject(),
|
||||
( String ) ois.readObject(),
|
||||
ois.readObject(),
|
||||
( Type ) ois.readObject(),
|
||||
( EntityMode ) ois.readObject(),
|
||||
session.getFactory()
|
||||
(String) ois.readObject(),
|
||||
(String) ois.readObject(),
|
||||
ois.readObject(),
|
||||
(Type) ois.readObject(),
|
||||
(EntityMode) ois.readObject(),
|
||||
session.getFactory()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,20 +33,20 @@ import org.hibernate.type.Type;
|
|||
/**
|
||||
* A FilterDefinition defines the global attributes of a dynamic filter. This
|
||||
* information includes its name as well as its defined parameters (name and type).
|
||||
*
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class FilterDefinition implements Serializable {
|
||||
private final String filterName;
|
||||
private final String defaultFilterCondition;
|
||||
private final Map<String,Type> parameterTypes = new HashMap<String,Type>();
|
||||
private final Map<String, Type> parameterTypes = new HashMap<String, Type>();
|
||||
|
||||
/**
|
||||
* Construct a new FilterDefinition instance.
|
||||
*
|
||||
* @param name The name of the filter for which this configuration is in effect.
|
||||
*/
|
||||
public FilterDefinition(String name, String defaultCondition, Map<String,Type> parameterTypes) {
|
||||
public FilterDefinition(String name, String defaultCondition, Map<String, Type> parameterTypes) {
|
||||
this.filterName = name;
|
||||
this.defaultFilterCondition = defaultCondition;
|
||||
this.parameterTypes.putAll( parameterTypes );
|
||||
|
@ -71,20 +71,21 @@ public class FilterDefinition implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retreive the type of the named parameter defined for this filter.
|
||||
* Retrieve the type of the named parameter defined for this filter.
|
||||
*
|
||||
* @param parameterName The name of the filter parameter for which to return the type.
|
||||
*
|
||||
* @return The type of the named parameter.
|
||||
*/
|
||||
public Type getParameterType(String parameterName) {
|
||||
return parameterTypes.get(parameterName);
|
||||
}
|
||||
public Type getParameterType(String parameterName) {
|
||||
return parameterTypes.get( parameterName );
|
||||
}
|
||||
|
||||
public String getDefaultFilterCondition() {
|
||||
return defaultFilterCondition;
|
||||
}
|
||||
|
||||
public Map<String,Type> getParameterTypes() {
|
||||
public Map<String, Type> getParameterTypes() {
|
||||
return parameterTypes;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.io.Serializable;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
|
||||
/**
|
||||
* A strategy for determining if an identifier value is an identifier of
|
||||
|
@ -38,8 +38,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class IdentifierValue implements UnsavedValueStrategy {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, IdentifierValue.class.getName());
|
||||
private static final Logger LOG = CoreLogging.logger( IdentifierValue.class );
|
||||
|
||||
private final Serializable value;
|
||||
|
||||
|
@ -52,10 +51,12 @@ public class IdentifierValue implements UnsavedValueStrategy {
|
|||
LOG.trace( "ID unsaved-value strategy ANY" );
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getDefaultValue(Object currentValue) {
|
||||
return (Serializable) currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SAVE_ANY";
|
||||
|
@ -71,10 +72,12 @@ public class IdentifierValue implements UnsavedValueStrategy {
|
|||
LOG.trace( "ID unsaved-value strategy NONE" );
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getDefaultValue(Object currentValue) {
|
||||
return (Serializable) currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SAVE_NONE";
|
||||
|
@ -89,12 +92,14 @@ public class IdentifierValue implements UnsavedValueStrategy {
|
|||
@Override
|
||||
public final Boolean isUnsaved(Object id) {
|
||||
LOG.trace( "ID unsaved-value strategy NULL" );
|
||||
return id==null;
|
||||
return id == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getDefaultValue(Object currentValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SAVE_NULL";
|
||||
|
@ -110,10 +115,12 @@ public class IdentifierValue implements UnsavedValueStrategy {
|
|||
LOG.trace( "ID unsaved-value strategy UNDEFINED" );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getDefaultValue(Object currentValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UNDEFINED";
|
||||
|
@ -135,11 +142,13 @@ public class IdentifierValue implements UnsavedValueStrategy {
|
|||
/**
|
||||
* Does the given identifier belong to a new instance?
|
||||
*/
|
||||
@Override
|
||||
public Boolean isUnsaved(Object id) {
|
||||
LOG.tracev( "ID unsaved-value: {0}", value );
|
||||
return id==null || id.equals(value);
|
||||
return id == null || id.equals( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable getDefaultValue(Object currentValue) {
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.QueryException;
|
||||
|
@ -38,19 +40,18 @@ import org.hibernate.ScrollMode;
|
|||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.query.spi.HQLQueryPlan;
|
||||
import org.hibernate.hql.internal.classic.ParserHelper;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.FilterImpl;
|
||||
import org.hibernate.internal.util.EntityPrinter;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.transform.ResultTransformer;
|
||||
import org.hibernate.type.Type;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public final class QueryParameters {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, QueryParameters.class.getName());
|
||||
private static final Logger LOG = CoreLogging.logger( QueryParameters.class );
|
||||
|
||||
private Type[] positionalParameterTypes;
|
||||
private Object[] positionalParameterValues;
|
||||
|
|
|
@ -67,7 +67,6 @@ public final class RowSelection {
|
|||
}
|
||||
|
||||
public boolean definesLimits() {
|
||||
return maxRows != null ||
|
||||
( firstRow != null && firstRow <= 0 );
|
||||
return maxRows != null || (firstRow != null && firstRow <= 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,19 +31,18 @@ import java.util.Set;
|
|||
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
|
||||
*/
|
||||
public interface SelfDirtinessTracker {
|
||||
/**
|
||||
* Return true if any fields has been changed
|
||||
*/
|
||||
boolean $$_hibernate_hasDirtyAttributes();
|
||||
|
||||
/**
|
||||
* Return true if any fields has been changed
|
||||
*/
|
||||
boolean $$_hibernate_hasDirtyAttributes();
|
||||
/**
|
||||
* Get the field names of all the fields thats been changed
|
||||
*/
|
||||
Set<String> $$_hibernate_getDirtyAttributes();
|
||||
|
||||
/**
|
||||
* Get the field names of all the fields thats been changed
|
||||
*/
|
||||
Set<String> $$_hibernate_getDirtyAttributes();
|
||||
|
||||
/**
|
||||
* Clear the stored dirty attributes
|
||||
*/
|
||||
void $$_hibernate_clearDirtyAttributes();
|
||||
/**
|
||||
* Clear the stored dirty attributes
|
||||
*/
|
||||
void $$_hibernate_clearDirtyAttributes();
|
||||
}
|
||||
|
|
|
@ -245,9 +245,8 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
|
|||
* Retrieves the SqlExceptionHelper in effect for this SessionFactory.
|
||||
*
|
||||
* @return The SqlExceptionHelper for this SessionFactory.
|
||||
*
|
||||
*/
|
||||
public SqlExceptionHelper getSQLExceptionHelper();
|
||||
public SqlExceptionHelper getSQLExceptionHelper();
|
||||
|
||||
public Settings getSettings();
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Disable automatic transaction joining. The really only has any effect for CMT transactions. The default
|
||||
* Hibernate behavior is to auto join any active JTA transaction (register {@link javax.transaction.Synchronization}).
|
||||
* JPA however defines an explicit join transaction operation.
|
||||
*
|
||||
* <p/>
|
||||
* See javax.persistence.EntityManager#joinTransaction
|
||||
*/
|
||||
public void disableTransactionAutoJoin();
|
||||
|
@ -124,22 +124,22 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Initialize the collection (if not already initialized)
|
||||
*/
|
||||
public void initializeCollection(PersistentCollection collection, boolean writing)
|
||||
throws HibernateException;
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Load an instance without checking if it was deleted.
|
||||
*
|
||||
* <p/>
|
||||
* When <tt>nullable</tt> is disabled this method may create a new proxy or
|
||||
* return an existing proxy; if it does not exist, throw an exception.
|
||||
*
|
||||
* <p/>
|
||||
* When <tt>nullable</tt> is enabled, the method does not create new proxies
|
||||
* (but might return an existing proxy); if it does not exist, return
|
||||
* <tt>null</tt>.
|
||||
*
|
||||
* <p/>
|
||||
* When <tt>eager</tt> is enabled, the object is eagerly fetched
|
||||
*/
|
||||
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
|
||||
throws HibernateException;
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Load an instance immediately. This method is only called when lazily initializing a proxy.
|
||||
|
@ -151,6 +151,7 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* System time before the start of the transaction
|
||||
*/
|
||||
public long getTimestamp();
|
||||
|
||||
/**
|
||||
* Get the creating <tt>SessionFactoryImplementor</tt>
|
||||
*/
|
||||
|
@ -160,18 +161,22 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Execute a <tt>find()</tt> query
|
||||
*/
|
||||
public List list(String query, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute an <tt>iterate()</tt> query
|
||||
*/
|
||||
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a <tt>scroll()</tt> query
|
||||
*/
|
||||
public ScrollableResults scroll(String query, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a criteria query
|
||||
*/
|
||||
public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode);
|
||||
|
||||
/**
|
||||
* Execute a criteria query
|
||||
*/
|
||||
|
@ -181,13 +186,16 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Execute a filter
|
||||
*/
|
||||
public List listFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Iterate a filter
|
||||
*/
|
||||
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters) throws HibernateException;
|
||||
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the <tt>EntityPersister</tt> for any instance
|
||||
*
|
||||
* @param entityName optional entity name
|
||||
* @param object the entity instance
|
||||
*/
|
||||
|
@ -224,67 +232,77 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Execute an SQL Query
|
||||
*/
|
||||
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute an SQL Query
|
||||
*/
|
||||
public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a native SQL query, and return the results as a fully built list.
|
||||
*
|
||||
* @param spec The specification of the native SQL query to execute.
|
||||
* @param queryParameters The parameters by which to perform the execution.
|
||||
*
|
||||
* @return The result list.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Execute a native SQL query, and return the results as a scrollable result.
|
||||
*
|
||||
* @param spec The specification of the native SQL query to execute.
|
||||
* @param queryParameters The parameters by which to perform the execution.
|
||||
*
|
||||
* @return The resulting scrollable result.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
throws HibernateException;
|
||||
|
||||
/**
|
||||
* Retreive the currently set value for a filter parameter.
|
||||
*
|
||||
* @param filterParameterName The filter parameter name in the format
|
||||
* {FILTER_NAME.PARAMETER_NAME}.
|
||||
*
|
||||
* @return The filter parameter value.
|
||||
*
|
||||
* @deprecated use #getLoadQueryInfluencers instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Object getFilterParameterValue(String filterParameterName);
|
||||
public Object getFilterParameterValue(String filterParameterName);
|
||||
|
||||
/**
|
||||
* Retreive the type for a given filter parrameter.
|
||||
* Retrieve the type for a given filter parameter.
|
||||
*
|
||||
* @param filterParameterName The filter parameter name in the format
|
||||
* {FILTER_NAME.PARAMETER_NAME}.
|
||||
*
|
||||
* @return The filter param type
|
||||
*
|
||||
* @deprecated use #getLoadQueryInfluencers instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Type getFilterParameterType(String filterParameterName);
|
||||
public Type getFilterParameterType(String filterParameterName);
|
||||
|
||||
/**
|
||||
* Return the currently enabled filters. The filter map is keyed by filter
|
||||
* name, with values corresponding to the {@link org.hibernate.internal.FilterImpl}
|
||||
* instance.
|
||||
*
|
||||
* @return The currently enabled filters.
|
||||
*
|
||||
* @deprecated use #getLoadQueryInfluencers instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Map getEnabledFilters();
|
||||
public Map getEnabledFilters();
|
||||
|
||||
public int getDontFlushFromFind();
|
||||
|
||||
|
@ -303,24 +321,33 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
/**
|
||||
* Execute a native SQL update or delete query
|
||||
*/
|
||||
int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException;
|
||||
int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters)
|
||||
throws HibernateException;
|
||||
|
||||
|
||||
// copied from Session:
|
||||
|
||||
public CacheMode getCacheMode();
|
||||
|
||||
public void setCacheMode(CacheMode cm);
|
||||
|
||||
public boolean isOpen();
|
||||
|
||||
public boolean isConnected();
|
||||
|
||||
public FlushMode getFlushMode();
|
||||
|
||||
public void setFlushMode(FlushMode fm);
|
||||
|
||||
public Connection connection();
|
||||
|
||||
public void flush();
|
||||
|
||||
/**
|
||||
* Get a Query instance for a named query or named native SQL query
|
||||
*/
|
||||
public Query getNamedQuery(String name);
|
||||
|
||||
/**
|
||||
* Get a Query instance for a named native SQL query
|
||||
*/
|
||||
|
@ -334,19 +361,21 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Get the <i>internal</i> fetch profile currently associated with this session.
|
||||
*
|
||||
* @return The current internal fetch profile, or null if none currently associated.
|
||||
*
|
||||
* @deprecated use #getLoadQueryInfluencers instead
|
||||
*/
|
||||
@Deprecated
|
||||
public String getFetchProfile();
|
||||
public String getFetchProfile();
|
||||
|
||||
/**
|
||||
* Set the current <i>internal</i> fetch profile for this session.
|
||||
*
|
||||
* @param name The internal fetch profile name to use
|
||||
*
|
||||
* @deprecated use {@link #getLoadQueryInfluencers} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setFetchProfile(String name);
|
||||
public void setFetchProfile(String name);
|
||||
|
||||
/**
|
||||
* Retrieve access to the session's transaction coordinator.
|
||||
|
@ -369,7 +398,7 @@ public interface SessionImplementor extends Serializable, LobCreationContext {
|
|||
* Get the load query influencers associated with this session.
|
||||
*
|
||||
* @return the load query influencers associated with this session;
|
||||
* should never be null.
|
||||
* should never be null.
|
||||
*/
|
||||
public LoadQueryInfluencers getLoadQueryInfluencers();
|
||||
|
||||
|
|
|
@ -42,13 +42,12 @@ public class SubselectFetch {
|
|||
private final Map namedParameterLocMap;
|
||||
|
||||
public SubselectFetch(
|
||||
//final String queryString,
|
||||
final String alias,
|
||||
final Loadable loadable,
|
||||
final QueryParameters queryParameters,
|
||||
final Set resultingEntityKeys,
|
||||
final Map namedParameterLocMap
|
||||
) {
|
||||
//final String queryString,
|
||||
final String alias,
|
||||
final Loadable loadable,
|
||||
final QueryParameters queryParameters,
|
||||
final Set resultingEntityKeys,
|
||||
final Map namedParameterLocMap) {
|
||||
this.resultingEntityKeys = resultingEntityKeys;
|
||||
this.queryParameters = queryParameters;
|
||||
this.namedParameterLocMap = namedParameterLocMap;
|
||||
|
@ -57,12 +56,11 @@ public class SubselectFetch {
|
|||
|
||||
//TODO: ugly here:
|
||||
final String queryString = queryParameters.getFilteredSQL();
|
||||
int fromIndex = queryString.indexOf(" from ");
|
||||
int orderByIndex = queryString.lastIndexOf("order by");
|
||||
this.queryString = orderByIndex>0 ?
|
||||
queryString.substring(fromIndex, orderByIndex) :
|
||||
queryString.substring(fromIndex);
|
||||
|
||||
int fromIndex = queryString.indexOf( " from " );
|
||||
int orderByIndex = queryString.lastIndexOf( "order by" );
|
||||
this.queryString = orderByIndex > 0
|
||||
? queryString.substring( fromIndex, orderByIndex )
|
||||
: queryString.substring( fromIndex );
|
||||
}
|
||||
|
||||
public QueryParameters getQueryParameters() {
|
||||
|
@ -77,20 +75,15 @@ public class SubselectFetch {
|
|||
}
|
||||
|
||||
public String toSubselectString(String ukname) {
|
||||
String[] joinColumns = ukname == null
|
||||
? StringHelper.qualify( alias, loadable.getIdentifierColumnNames() )
|
||||
: ( (PropertyMapping) loadable ).toColumns( alias, ukname );
|
||||
|
||||
String[] joinColumns = ukname==null ?
|
||||
StringHelper.qualify( alias, loadable.getIdentifierColumnNames() ) :
|
||||
( (PropertyMapping) loadable ).toColumns(alias, ukname);
|
||||
|
||||
return new StringBuilder()
|
||||
.append("select ")
|
||||
.append( StringHelper.join(", ", joinColumns) )
|
||||
.append(queryString)
|
||||
.toString();
|
||||
return "select " + StringHelper.join( ", ", joinColumns ) + queryString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString() {
|
||||
return "SubselectFetch(" + queryString + ')';
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
|
||||
/**
|
||||
* A strategy for determining if a version value is an version of
|
||||
|
@ -38,8 +38,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class VersionValue implements UnsavedValueStrategy {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, VersionValue.class.getName());
|
||||
private static final Logger LOG = CoreLogging.logger( VersionValue.class );
|
||||
|
||||
private final Object value;
|
||||
/**
|
||||
|
@ -50,17 +49,20 @@ public class VersionValue implements UnsavedValueStrategy {
|
|||
@Override
|
||||
public final Boolean isUnsaved(Object version) {
|
||||
LOG.trace( "Version unsaved-value strategy NULL" );
|
||||
return version==null;
|
||||
return version == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue(Object currentValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VERSION_SAVE_NULL";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Assume the transient instance is newly instantiated if the version
|
||||
* is null, otherwise defer to the identifier unsaved-value.
|
||||
|
@ -69,17 +71,20 @@ public class VersionValue implements UnsavedValueStrategy {
|
|||
@Override
|
||||
public final Boolean isUnsaved(Object version) {
|
||||
LOG.trace( "Version unsaved-value strategy UNDEFINED" );
|
||||
return version==null ? Boolean.TRUE : null;
|
||||
return version == null ? Boolean.TRUE : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue(Object currentValue) {
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VERSION_UNDEFINED";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Assume the transient instance is newly instantiated if the version
|
||||
* is negative, otherwise assume it is a detached instance.
|
||||
|
@ -89,18 +94,22 @@ public class VersionValue implements UnsavedValueStrategy {
|
|||
@Override
|
||||
public final Boolean isUnsaved(Object version) throws MappingException {
|
||||
LOG.trace( "Version unsaved-value strategy NEGATIVE" );
|
||||
if (version==null) return Boolean.TRUE;
|
||||
if ( version == null ) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if ( version instanceof Number ) {
|
||||
return ( (Number) version ).longValue() < 0l;
|
||||
return ((Number) version).longValue() < 0l;
|
||||
}
|
||||
throw new MappingException( "unsaved-value NEGATIVE may only be used with short, int and long types" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue(Object currentValue) {
|
||||
return IdentifierGeneratorHelper.getIntegralDataTypeHolder( currentValue.getClass() )
|
||||
.initialize( -1L )
|
||||
.makeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VERSION_NEGATIVE";
|
||||
|
@ -114,6 +123,7 @@ public class VersionValue implements UnsavedValueStrategy {
|
|||
/**
|
||||
* Assume the transient instance is newly instantiated if
|
||||
* its version is null or equal to <tt>value</tt>
|
||||
*
|
||||
* @param value value to compare to
|
||||
*/
|
||||
public VersionValue(Object value) {
|
||||
|
@ -121,9 +131,9 @@ public class VersionValue implements UnsavedValueStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean isUnsaved(Object version) throws MappingException {
|
||||
public Boolean isUnsaved(Object version) throws MappingException {
|
||||
LOG.tracev( "Version unsaved-value: {0}", value );
|
||||
return version==null || version.equals(value);
|
||||
return version == null || version.equals( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,7 +142,7 @@ public class VersionValue implements UnsavedValueStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString() {
|
||||
return "version unsaved-value: " + value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,14 +30,13 @@ import java.sql.Connection;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.ResourceClosedException;
|
||||
import org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.engine.transaction.spi.JoinStatus;
|
||||
import org.hibernate.engine.transaction.spi.SynchronizationRegistry;
|
||||
import org.hibernate.engine.transaction.spi.TransactionContext;
|
||||
|
@ -50,9 +49,9 @@ import org.hibernate.engine.transaction.synchronization.internal.RegisteredSynch
|
|||
import org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorNonTrackingImpl;
|
||||
import org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorTrackingImpl;
|
||||
import org.hibernate.engine.transaction.synchronization.spi.SynchronizationCallbackCoordinator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
|
||||
/**
|
||||
* Standard implementation of the Hibernate {@link TransactionCoordinator}
|
||||
|
@ -62,8 +61,7 @@ import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, TransactionCoordinatorImpl.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( TransactionCoordinatorImpl.class );
|
||||
|
||||
private final transient TransactionContext transactionContext;
|
||||
private final transient JdbcCoordinatorImpl jdbcCoordinator;
|
||||
|
@ -93,8 +91,8 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
reset();
|
||||
|
||||
final boolean registerSynchronization = transactionContext.isAutoCloseSessionEnabled()
|
||||
|| transactionContext.isFlushBeforeCompletionEnabled()
|
||||
|| transactionContext.getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION;
|
||||
|| transactionContext.isFlushBeforeCompletionEnabled()
|
||||
|| transactionContext.getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_TRANSACTION;
|
||||
if ( registerSynchronization ) {
|
||||
pulse();
|
||||
}
|
||||
|
@ -158,7 +156,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean isTransactionInProgress() {
|
||||
return open && getTransaction().isActive() && getTransaction().getJoinStatus() == JoinStatus.JOINED;
|
||||
}
|
||||
|
@ -183,7 +181,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
|
||||
@Override
|
||||
public TransactionImplementor getTransaction() {
|
||||
if ( ! open ) {
|
||||
if ( !open ) {
|
||||
throw new ResourceClosedException( "This TransactionCoordinator has been closed" );
|
||||
}
|
||||
pulse();
|
||||
|
@ -208,7 +206,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
getTransaction().resetJoinStatus();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@SuppressWarnings({"unchecked"})
|
||||
private void attemptToRegisterJtaSync() {
|
||||
if ( synchronizationRegistered ) {
|
||||
return;
|
||||
|
@ -221,7 +219,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
|
||||
if ( currentHibernateTransaction.getJoinStatus() != JoinStatus.JOINED ) {
|
||||
// the transaction is not (yet) joined, see if we should join...
|
||||
if ( ! transactionContext.shouldAutoJoinTransaction() ) {
|
||||
if ( !transactionContext.shouldAutoJoinTransaction() ) {
|
||||
// we are supposed to not auto join transactions; if the transaction is not marked for join
|
||||
// we cannot go any further in attempting to join (register sync).
|
||||
if ( currentHibernateTransaction.getJoinStatus() != JoinStatus.MARKED_FOR_JOINED ) {
|
||||
|
@ -249,7 +247,7 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
}
|
||||
|
||||
// Should we resister a synchronization
|
||||
if ( ! transactionFactory().isJoinableJtaTransaction( this, currentHibernateTransaction ) ) {
|
||||
if ( !transactionFactory().isJoinableJtaTransaction( this, currentHibernateTransaction ) ) {
|
||||
LOG.trace( "TransactionFactory reported no JTA transaction to join; skipping Synchronization registration" );
|
||||
return;
|
||||
}
|
||||
|
@ -299,13 +297,13 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean isTransactionJoinable() {
|
||||
return transactionFactory().isJoinableJtaTransaction( this, currentHibernateTransaction );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean isTransactionJoined() {
|
||||
return currentHibernateTransaction != null && currentHibernateTransaction.getJoinStatus() == JoinStatus.JOINED;
|
||||
}
|
||||
|
@ -374,7 +372,11 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator {
|
|||
for ( int i = 0; i < observerCount; i++ ) {
|
||||
observers.add( (TransactionObserver) ois.readObject() );
|
||||
}
|
||||
final TransactionCoordinatorImpl transactionCoordinator = new TransactionCoordinatorImpl( transactionContext, jdbcCoordinator, observers );
|
||||
final TransactionCoordinatorImpl transactionCoordinator = new TransactionCoordinatorImpl(
|
||||
transactionContext,
|
||||
jdbcCoordinator,
|
||||
observers
|
||||
);
|
||||
jdbcCoordinator.afterDeserialize( transactionCoordinator );
|
||||
return transactionCoordinator;
|
||||
}
|
||||
|
|
|
@ -25,15 +25,14 @@ package org.hibernate.engine.transaction.internal;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
|
||||
import org.hibernate.engine.transaction.spi.TransactionFactory;
|
||||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
/**
|
||||
|
@ -44,21 +43,18 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
|
|||
public class TransactionFactoryInitiator<T extends TransactionImplementor>
|
||||
implements StandardServiceInitiator<TransactionFactory> {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
TransactionFactoryInitiator.class.getName()
|
||||
);
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( TransactionFactoryInitiator.class );
|
||||
|
||||
public static final TransactionFactoryInitiator INSTANCE = new TransactionFactoryInitiator();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public Class<TransactionFactory> getServiceInitiated() {
|
||||
return TransactionFactory.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public TransactionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
final Object strategy = configurationValues.get( AvailableSettings.TRANSACTION_STRATEGY );
|
||||
|
||||
|
|
|
@ -26,13 +26,12 @@ package org.hibernate.engine.transaction.internal.jdbc;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
|
||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
import org.hibernate.engine.transaction.spi.IsolationDelegate;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jdbc.WorkExecutor;
|
||||
import org.hibernate.jdbc.WorkExecutorVisitable;
|
||||
|
@ -43,8 +42,7 @@ import org.hibernate.jdbc.WorkExecutorVisitable;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JdbcIsolationDelegate implements IsolationDelegate {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, JdbcIsolationDelegate.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JdbcIsolationDelegate.class );
|
||||
|
||||
private final TransactionCoordinator transactionCoordinator;
|
||||
|
||||
|
|
|
@ -30,13 +30,12 @@ import javax.transaction.TransactionManager;
|
|||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
|
||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||
import org.hibernate.engine.transaction.spi.IsolationDelegate;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jdbc.WorkExecutor;
|
||||
import org.hibernate.jdbc.WorkExecutorVisitable;
|
||||
|
@ -47,8 +46,7 @@ import org.hibernate.jdbc.WorkExecutorVisitable;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JtaIsolationDelegate implements IsolationDelegate {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, JtaIsolationDelegate.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JtaIsolationDelegate.class );
|
||||
|
||||
private final TransactionCoordinator transactionCoordinator;
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ import javax.transaction.SystemException;
|
|||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.TransactionException;
|
||||
import org.hibernate.engine.transaction.spi.AbstractTransactionImpl;
|
||||
|
@ -37,6 +35,7 @@ import org.hibernate.engine.transaction.spi.IsolationDelegate;
|
|||
import org.hibernate.engine.transaction.spi.JoinStatus;
|
||||
import org.hibernate.engine.transaction.spi.LocalStatus;
|
||||
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
|
@ -47,8 +46,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
* @author Les Hazlewood
|
||||
*/
|
||||
public class JtaTransaction extends AbstractTransactionImpl {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, JtaTransaction.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JtaTransaction.class );
|
||||
|
||||
private UserTransaction userTransaction;
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.TransactionException;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
|
||||
/**
|
||||
* Abstract support for creating {@link TransactionImplementor transaction} implementations
|
||||
|
@ -39,9 +39,7 @@ import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractTransactionImpl implements TransactionImplementor {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
AbstractTransactionImpl.class.getName());
|
||||
private static final Logger LOG = CoreLogging.logger( AbstractTransactionImpl.class );
|
||||
|
||||
private final TransactionCoordinator transactionCoordinator;
|
||||
|
||||
|
@ -81,9 +79,13 @@ public abstract class AbstractTransactionImpl implements TransactionImplementor
|
|||
protected abstract void doRollback();
|
||||
|
||||
protected abstract void afterTransactionBegin();
|
||||
|
||||
protected abstract void beforeTransactionCommit();
|
||||
|
||||
protected abstract void beforeTransactionRollBack();
|
||||
|
||||
protected abstract void afterTransactionCompletion(int status);
|
||||
|
||||
protected abstract void afterAfterCompletion();
|
||||
|
||||
/**
|
||||
|
@ -145,7 +147,7 @@ public abstract class AbstractTransactionImpl implements TransactionImplementor
|
|||
|
||||
@Override
|
||||
public void begin() throws HibernateException {
|
||||
if ( ! valid ) {
|
||||
if ( !valid ) {
|
||||
throw new TransactionException( "Transaction instance is no longer valid" );
|
||||
}
|
||||
if ( localStatus == LocalStatus.ACTIVE ) {
|
||||
|
@ -179,7 +181,7 @@ public abstract class AbstractTransactionImpl implements TransactionImplementor
|
|||
localStatus = LocalStatus.COMMITTED;
|
||||
afterTransactionCompletion( Status.STATUS_COMMITTED );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
catch (Exception e) {
|
||||
localStatus = LocalStatus.FAILED_COMMIT;
|
||||
afterTransactionCompletion( Status.STATUS_UNKNOWN );
|
||||
throw new TransactionException( "commit failed", e );
|
||||
|
@ -210,7 +212,7 @@ public abstract class AbstractTransactionImpl implements TransactionImplementor
|
|||
localStatus = LocalStatus.ROLLED_BACK;
|
||||
afterTransactionCompletion( Status.STATUS_ROLLEDBACK );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
catch (Exception e) {
|
||||
afterTransactionCompletion( Status.STATUS_UNKNOWN );
|
||||
throw new TransactionException( "rollback failed", e );
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@ import org.hibernate.engine.spi.Status;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.id.IdentifierGenerationException;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* A convenience bas class for listeners responding to save events.
|
||||
|
@ -58,12 +58,11 @@ import org.jboss.logging.Logger;
|
|||
* @author Steve Ebersole.
|
||||
*/
|
||||
public abstract class AbstractSaveEventListener extends AbstractReassociateEventListener {
|
||||
public enum EntityState{
|
||||
PERSISTENT, TRANSIENT, DETACHED, DELETED
|
||||
}
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractSaveEventListener.class );
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
AbstractSaveEventListener.class.getName());
|
||||
public static enum EntityState {
|
||||
PERSISTENT, TRANSIENT, DETACHED, DELETED
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the save call using the given requested id.
|
||||
|
@ -128,9 +127,11 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
else {
|
||||
// TODO: define toString()s for generators
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "Generated identifier: %s, using strategy: %s",
|
||||
LOG.debugf(
|
||||
"Generated identifier: %s, using strategy: %s",
|
||||
persister.getIdentifierType().toLoggableString( generatedId, source.getFactory() ),
|
||||
persister.getIdentifierGenerator().getClass().getName() );
|
||||
persister.getIdentifierGenerator().getClass().getName()
|
||||
);
|
||||
}
|
||||
|
||||
return performSave( entity, generatedId, persister, false, anything, source, true );
|
||||
|
@ -206,7 +207,7 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
// Try to do the callback now
|
||||
if ( persister.implementsLifecycle() ) {
|
||||
LOG.debug( "Calling onSave()" );
|
||||
if ( ( ( Lifecycle ) entity ).onSave( source ) ) {
|
||||
if ( ((Lifecycle) entity).onSave( source ) ) {
|
||||
LOG.debug( "Insertion vetoed by onSave()" );
|
||||
return true;
|
||||
}
|
||||
|
@ -292,14 +293,15 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
// that are not resolved until cascadeAfterSave() is executed
|
||||
cascadeAfterSave( source, persister, entity, anything );
|
||||
if ( useIdentityColumn && insert.isEarlyInsert() ) {
|
||||
if ( ! EntityIdentityInsertAction.class.isInstance( insert ) ) {
|
||||
if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) {
|
||||
throw new IllegalStateException(
|
||||
"Insert should be using an identity column, but action is of unexpected type: " +
|
||||
insert.getClass().getName() );
|
||||
insert.getClass().getName()
|
||||
);
|
||||
}
|
||||
id = ( ( EntityIdentityInsertAction ) insert ).getGeneratedId();
|
||||
|
||||
insert.handleNaturalIdPostSaveNotifications(id);
|
||||
id = ((EntityIdentityInsertAction) insert).getGeneratedId();
|
||||
|
||||
insert.handleNaturalIdPostSaveNotifications( id );
|
||||
}
|
||||
|
||||
markInterceptorDirty( entity, persister, source );
|
||||
|
@ -359,7 +361,12 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean visitCollectionsBeforeSave(Object entity, Serializable id, Object[] values, Type[] types, EventSource source) {
|
||||
protected boolean visitCollectionsBeforeSave(
|
||||
Object entity,
|
||||
Serializable id,
|
||||
Object[] values,
|
||||
Type[] types,
|
||||
EventSource source) {
|
||||
WrapVisitor visitor = new WrapVisitor( source );
|
||||
// substitutes into values by side-effect
|
||||
visitor.processEntityPropertyValues( values, types );
|
||||
|
@ -377,7 +384,7 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
* @param source The originating session
|
||||
*
|
||||
* @return True if the snapshot state changed such that
|
||||
* reinjection of the values into the entity is required.
|
||||
* reinjection of the values into the entity is required.
|
||||
*/
|
||||
protected boolean substituteValuesIfNecessary(
|
||||
Object entity,
|
||||
|
@ -501,8 +508,8 @@ public abstract class AbstractSaveEventListener extends AbstractReassociateEvent
|
|||
// the entity is not associated with the session, so
|
||||
// try interceptor and unsaved-value
|
||||
|
||||
if ( ForeignKeys.isTransient( entityName, entity, getAssumedUnsaved(), source )) {
|
||||
if ( traceEnabled ) {
|
||||
if ( ForeignKeys.isTransient( entityName, entity, getAssumedUnsaved(), source ) ) {
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Transient instance of: {0}", getLoggableName( entityName, entity ) );
|
||||
}
|
||||
return EntityState.TRANSIENT;
|
||||
|
|
|
@ -45,13 +45,13 @@ import org.hibernate.engine.spi.Status;
|
|||
import org.hibernate.event.spi.DeleteEvent;
|
||||
import org.hibernate.event.spi.DeleteEventListener;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.collections.IdentitySet;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Defines the default delete event listener used by hibernate for deleting entities
|
||||
|
@ -60,9 +60,7 @@ import org.jboss.logging.Logger;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultDeleteEventListener implements DeleteEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
DefaultDeleteEventListener.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultDeleteEventListener.class );
|
||||
|
||||
/**
|
||||
* Handle the given delete event.
|
||||
|
@ -125,7 +123,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
|
||||
entityEntry = persistenceContext.addEntity(
|
||||
entity,
|
||||
( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
|
||||
(persister.isMutable() ? Status.MANAGED : Status.READ_ONLY),
|
||||
persister.getPropertyValues( entity ),
|
||||
key,
|
||||
version,
|
||||
|
@ -159,8 +157,15 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
return;
|
||||
}
|
||||
|
||||
deleteEntity( source, entity, entityEntry, event.isCascadeDeleteEnabled(),
|
||||
event.isOrphanRemovalBeforeUpdates(), persister, transientEntities );
|
||||
deleteEntity(
|
||||
source,
|
||||
entity,
|
||||
entityEntry,
|
||||
event.isCascadeDeleteEnabled(),
|
||||
event.isOrphanRemovalBeforeUpdates(),
|
||||
persister,
|
||||
transientEntities
|
||||
);
|
||||
|
||||
if ( source.getFactory().getSettings().isIdentifierRollbackEnabled() ) {
|
||||
persister.resetIdentifier( entity, id, version, source );
|
||||
|
@ -233,7 +238,10 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
final Set transientEntities) {
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Deleting {0}", MessageHelper.infoString( persister, entityEntry.getId(), session.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Deleting {0}",
|
||||
MessageHelper.infoString( persister, entityEntry.getId(), session.getFactory() )
|
||||
);
|
||||
}
|
||||
|
||||
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
||||
|
@ -241,7 +249,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
final Object version = entityEntry.getVersion();
|
||||
|
||||
final Object[] currentState;
|
||||
if ( entityEntry.getLoadedState() == null ) { //ie. the entity came in from update()
|
||||
if ( entityEntry.getLoadedState() == null ) {
|
||||
//ie. the entity came in from update()
|
||||
currentState = persister.getPropertyValues( entity );
|
||||
}
|
||||
else {
|
||||
|
@ -270,7 +279,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
new Nullability( session ).checkNullability( entityEntry.getDeletedState(), persister, true );
|
||||
persistenceContext.getNullifiableEntityKeys().add( key );
|
||||
|
||||
if (isOrphanRemovalBeforeUpdates) {
|
||||
if ( isOrphanRemovalBeforeUpdates ) {
|
||||
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task
|
||||
// ordering is improved.
|
||||
session.getActionQueue().addAction(
|
||||
|
@ -321,7 +330,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener {
|
|||
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
|
||||
if ( persister.implementsLifecycle() ) {
|
||||
LOG.debug( "Calling onDelete()" );
|
||||
if ( ( ( Lifecycle ) entity ).onDelete( session ) ) {
|
||||
if ( ( (Lifecycle) entity ).onDelete( session ) ) {
|
||||
LOG.debug( "Deletion vetoed by onDelete()" );
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ package org.hibernate.event.internal;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.internal.Cascade;
|
||||
import org.hibernate.engine.internal.CascadePoint;
|
||||
|
@ -37,6 +35,7 @@ import org.hibernate.engine.spi.PersistenceContext;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.EvictEvent;
|
||||
import org.hibernate.event.spi.EvictEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -52,14 +51,13 @@ import org.hibernate.proxy.LazyInitializer;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultEvictEventListener implements EvictEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
DefaultEvictEventListener.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultEvictEventListener.class );
|
||||
|
||||
/**
|
||||
* Handle the given evict event.
|
||||
*
|
||||
* @param event The evict event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onEvict(EvictEvent event) throws HibernateException {
|
||||
|
@ -118,18 +116,22 @@ public class DefaultEvictEventListener implements EvictEventListener {
|
|||
}
|
||||
|
||||
protected void doEvict(
|
||||
final Object object,
|
||||
final EntityKey key,
|
||||
final EntityPersister persister,
|
||||
final EventSource session)
|
||||
throws HibernateException {
|
||||
final Object object,
|
||||
final EntityKey key,
|
||||
final EntityPersister persister,
|
||||
final EventSource session)
|
||||
throws HibernateException {
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Evicting {0}", MessageHelper.infoString( persister ) );
|
||||
}
|
||||
|
||||
if ( persister.hasNaturalIdentifier() ) {
|
||||
session.getPersistenceContext().getNaturalIdHelper().handleEviction( object, persister, key.getIdentifier() );
|
||||
session.getPersistenceContext().getNaturalIdHelper().handleEviction(
|
||||
object,
|
||||
persister,
|
||||
key.getIdentifier()
|
||||
);
|
||||
}
|
||||
|
||||
// remove all collections for the entity from the session-level cache
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.io.Serializable;
|
|||
import java.util.Arrays;
|
||||
|
||||
import org.hibernate.engine.spi.SelfDirtinessTracker;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
|
@ -75,16 +76,14 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
if ( persister.canExtractIdOutOfEntity() ) {
|
||||
|
||||
Serializable oid = persister.getIdentifier( object, session );
|
||||
if (id==null) {
|
||||
throw new AssertionFailure("null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)");
|
||||
if ( id == null ) {
|
||||
throw new AssertionFailure( "null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)" );
|
||||
}
|
||||
if ( !persister.getIdentifierType().isEqual( id, oid, session.getFactory() ) ) {
|
||||
throw new HibernateException(
|
||||
"identifier of an instance of " +
|
||||
persister.getEntityName() +
|
||||
" was altered from " + id +
|
||||
" to " + oid
|
||||
);
|
||||
"identifier of an instance of " + persister.getEntityName() + " was altered from "
|
||||
+ id + " to " + oid
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,12 +91,12 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
|
||||
private void checkNaturalId(
|
||||
EntityPersister persister,
|
||||
EntityEntry entry,
|
||||
Object[] current,
|
||||
Object[] loaded,
|
||||
SessionImplementor session) {
|
||||
EntityEntry entry,
|
||||
Object[] current,
|
||||
Object[] loaded,
|
||||
SessionImplementor session) {
|
||||
if ( persister.hasNaturalIdentifier() && entry.getStatus() != Status.READ_ONLY ) {
|
||||
if ( ! persister.getEntityMetamodel().hasImmutableNaturalId() ) {
|
||||
if ( !persister.getEntityMetamodel().hasImmutableNaturalId() ) {
|
||||
// SHORT-CUT: if the natural id is mutable (!immutable), no need to do the below checks
|
||||
// EARLY EXIT!!!
|
||||
return;
|
||||
|
@ -111,15 +110,15 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
? session.getPersistenceContext().getNaturalIdSnapshot( entry.getId(), persister )
|
||||
: session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( loaded, persister );
|
||||
|
||||
for ( int i=0; i<naturalIdentifierPropertiesIndexes.length; i++ ) {
|
||||
for ( int i = 0; i < naturalIdentifierPropertiesIndexes.length; i++ ) {
|
||||
final int naturalIdentifierPropertyIndex = naturalIdentifierPropertiesIndexes[i];
|
||||
if ( propertyUpdateability[ naturalIdentifierPropertyIndex ] ) {
|
||||
if ( propertyUpdateability[naturalIdentifierPropertyIndex] ) {
|
||||
// if the given natural id property is updatable (mutable), there is nothing to check
|
||||
continue;
|
||||
}
|
||||
|
||||
final Type propertyType = propertyTypes[naturalIdentifierPropertyIndex];
|
||||
if ( ! propertyType.isEqual( current[naturalIdentifierPropertyIndex], snapshot[i] ) ) {
|
||||
if ( !propertyType.isEqual( current[naturalIdentifierPropertyIndex], snapshot[i] ) ) {
|
||||
throw new HibernateException(
|
||||
String.format(
|
||||
"An immutable natural identifier of entity %s was altered from %s to %s",
|
||||
|
@ -134,7 +133,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,14 +150,14 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
final Status status = entry.getStatus();
|
||||
final Type[] types = persister.getPropertyTypes();
|
||||
|
||||
final boolean mightBeDirty = entry.requiresDirtyCheck(entity);
|
||||
final boolean mightBeDirty = entry.requiresDirtyCheck( entity );
|
||||
|
||||
final Object[] values = getValues( entity, entry, mightBeDirty, session );
|
||||
|
||||
event.setPropertyValues(values);
|
||||
event.setPropertyValues( values );
|
||||
|
||||
//TODO: avoid this for non-new instances where mightBeDirty==false
|
||||
boolean substitute = wrapCollections( session, persister, types, values);
|
||||
boolean substitute = wrapCollections( session, persister, types, values );
|
||||
|
||||
if ( isUpdateNecessary( event, mightBeDirty ) ) {
|
||||
substitute = scheduleUpdate( event ) || substitute;
|
||||
|
@ -166,12 +165,14 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
|
||||
if ( status != Status.DELETED ) {
|
||||
// now update the object .. has to be outside the main if block above (because of collections)
|
||||
if (substitute) persister.setPropertyValues( entity, values );
|
||||
if ( substitute ) {
|
||||
persister.setPropertyValues( entity, values );
|
||||
}
|
||||
|
||||
// Search for collections by reachability, updating their role.
|
||||
// We don't want to touch collections reachable from a deleted object
|
||||
if ( persister.hasCollections() ) {
|
||||
new FlushVisitor(session, entity).processEntityPropertyValues(values, types);
|
||||
new FlushVisitor( session, entity ).processEntityPropertyValues( values, types );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +188,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
//grab its state saved at deletion
|
||||
values = entry.getDeletedState();
|
||||
}
|
||||
else if ( !mightBeDirty && loadedState!=null ) {
|
||||
else if ( !mightBeDirty && loadedState != null ) {
|
||||
values = loadedState;
|
||||
}
|
||||
else {
|
||||
|
@ -217,9 +218,9 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
// don't dirty the container. Also, for versioned data, we
|
||||
// need to wrap before calling searchForDirtyCollections
|
||||
|
||||
WrapVisitor visitor = new WrapVisitor(session);
|
||||
WrapVisitor visitor = new WrapVisitor( session );
|
||||
// substitutes into values by side-effect
|
||||
visitor.processEntityPropertyValues(values, types);
|
||||
visitor.processEntityPropertyValues( values, types );
|
||||
return visitor.isSubstitutionRequired();
|
||||
}
|
||||
else {
|
||||
|
@ -229,10 +230,10 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
|
||||
private boolean isUpdateNecessary(final FlushEntityEvent event, final boolean mightBeDirty) {
|
||||
final Status status = event.getEntityEntry().getStatus();
|
||||
if ( mightBeDirty || status==Status.DELETED ) {
|
||||
if ( mightBeDirty || status == Status.DELETED ) {
|
||||
// compare to cached state (ignoring collections unless versioned)
|
||||
dirtyCheck(event);
|
||||
if ( isUpdateNecessary(event) ) {
|
||||
dirtyCheck( event );
|
||||
if ( isUpdateNecessary( event ) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -266,30 +267,41 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
if ( LOG.isTraceEnabled() ) {
|
||||
if ( status == Status.DELETED ) {
|
||||
if ( !persister.isMutable() ) {
|
||||
LOG.tracev( "Updating immutable, deleted entity: {0}",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Updating immutable, deleted entity: {0}",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() )
|
||||
);
|
||||
}
|
||||
else if ( !entry.isModifiableEntity() ) {
|
||||
LOG.tracev(
|
||||
"Updating non-modifiable, deleted entity: {0}",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() )
|
||||
);
|
||||
}
|
||||
else {
|
||||
LOG.tracev(
|
||||
"Updating deleted entity: ",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() )
|
||||
);
|
||||
}
|
||||
else if ( !entry.isModifiableEntity() )
|
||||
LOG.tracev( "Updating non-modifiable, deleted entity: {0}",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) );
|
||||
else
|
||||
LOG.tracev( "Updating deleted entity: ",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) );
|
||||
}
|
||||
else
|
||||
LOG.tracev( "Updating entity: {0}",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() ) );
|
||||
else {
|
||||
LOG.tracev(
|
||||
"Updating entity: {0}",
|
||||
MessageHelper.infoString( persister, entry.getId(), session.getFactory() )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final boolean intercepted = !entry.isBeingReplicated() && handleInterception( event );
|
||||
|
||||
// increment the version number (if necessary)
|
||||
final Object nextVersion = getNextVersion(event);
|
||||
final Object nextVersion = getNextVersion( event );
|
||||
|
||||
// if it was dirtied by a collection only
|
||||
int[] dirtyProperties = event.getDirtyProperties();
|
||||
if ( event.isDirtyCheckPossible() && dirtyProperties == null ) {
|
||||
if ( ! intercepted && !event.hasDirtyCollection() ) {
|
||||
if ( !intercepted && !event.hasDirtyCollection() ) {
|
||||
throw new AssertionFailure( "dirty, but no dirty properties" );
|
||||
}
|
||||
dirtyProperties = ArrayHelper.EMPTY_INT_ARRAY;
|
||||
|
@ -297,7 +309,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
|
||||
// check nullability but do not doAfterTransactionCompletion command execute
|
||||
// we'll use scheduled updates for that.
|
||||
new Nullability(session).checkNullability( values, persister, true );
|
||||
new Nullability( session ).checkNullability( values, persister, true );
|
||||
|
||||
// schedule the update
|
||||
// note that we intentionally do _not_ pass in currentPersistentState!
|
||||
|
@ -307,7 +319,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
values,
|
||||
dirtyProperties,
|
||||
event.hasDirtyCollection(),
|
||||
( status == Status.DELETED && ! entry.isModifiableEntity() ?
|
||||
( status == Status.DELETED && !entry.isModifiableEntity() ?
|
||||
persister.getPropertyValues( entity ) :
|
||||
entry.getLoadedState() ),
|
||||
entry.getVersion(),
|
||||
|
@ -316,8 +328,8 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
entry.getRowId(),
|
||||
persister,
|
||||
session
|
||||
)
|
||||
);
|
||||
)
|
||||
);
|
||||
|
||||
return intercepted;
|
||||
}
|
||||
|
@ -341,7 +353,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
else {
|
||||
dirtyProperties = persister.findDirty( values, entry.getLoadedState(), entity, session );
|
||||
}
|
||||
event.setDirtyProperties(dirtyProperties);
|
||||
event.setDirtyProperties( dirtyProperties );
|
||||
}
|
||||
|
||||
return intercepted;
|
||||
|
@ -375,7 +387,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
Object[] values = event.getPropertyValues();
|
||||
|
||||
if ( entry.isBeingReplicated() ) {
|
||||
return Versioning.getVersion(values, persister);
|
||||
return Versioning.getVersion( values, persister );
|
||||
}
|
||||
else {
|
||||
int[] dirtyProperties = event.getDirtyProperties();
|
||||
|
@ -385,13 +397,13 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
entry,
|
||||
persister,
|
||||
dirtyProperties
|
||||
);
|
||||
);
|
||||
|
||||
final Object nextVersion = isVersionIncrementRequired ?
|
||||
Versioning.increment( entry.getVersion(), persister.getVersionType(), event.getSession() ) :
|
||||
entry.getVersion(); //use the current version
|
||||
|
||||
Versioning.setVersion(values, nextVersion, persister);
|
||||
Versioning.setVersion( values, nextVersion, persister );
|
||||
|
||||
return nextVersion;
|
||||
}
|
||||
|
@ -408,14 +420,14 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
EntityPersister persister,
|
||||
int[] dirtyProperties
|
||||
) {
|
||||
final boolean isVersionIncrementRequired = entry.getStatus()!=Status.DELETED && (
|
||||
dirtyProperties==null ||
|
||||
Versioning.isVersionIncrementRequired(
|
||||
dirtyProperties,
|
||||
event.hasDirtyCollection(),
|
||||
persister.getPropertyVersionability()
|
||||
)
|
||||
);
|
||||
final boolean isVersionIncrementRequired = entry.getStatus() != Status.DELETED && (
|
||||
dirtyProperties == null ||
|
||||
Versioning.isVersionIncrementRequired(
|
||||
dirtyProperties,
|
||||
event.hasDirtyCollection(),
|
||||
persister.getPropertyVersionability()
|
||||
)
|
||||
);
|
||||
return isVersionIncrementRequired;
|
||||
}
|
||||
|
||||
|
@ -435,7 +447,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
else {
|
||||
|
||||
int[] dirtyProperties = event.getDirtyProperties();
|
||||
if ( dirtyProperties!=null && dirtyProperties.length!=0 ) {
|
||||
if ( dirtyProperties != null && dirtyProperties.length != 0 ) {
|
||||
return true; //TODO: suck into event class
|
||||
}
|
||||
else {
|
||||
|
@ -446,14 +458,14 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
}
|
||||
|
||||
private boolean hasDirtyCollections(FlushEntityEvent event, EntityPersister persister, Status status) {
|
||||
if ( isCollectionDirtyCheckNecessary(persister, status ) ) {
|
||||
if ( isCollectionDirtyCheckNecessary( persister, status ) ) {
|
||||
DirtyCollectionSearchVisitor visitor = new DirtyCollectionSearchVisitor(
|
||||
event.getSession(),
|
||||
persister.getPropertyVersionability()
|
||||
);
|
||||
);
|
||||
visitor.processEntityPropertyValues( event.getPropertyValues(), persister.getPropertyTypes() );
|
||||
boolean hasDirtyCollections = visitor.wasDirtyCollectionFound();
|
||||
event.setHasDirtyCollection(hasDirtyCollections);
|
||||
event.setHasDirtyCollection( hasDirtyCollections );
|
||||
return hasDirtyCollections;
|
||||
}
|
||||
else {
|
||||
|
@ -490,52 +502,53 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
);
|
||||
|
||||
if ( dirtyProperties == null ) {
|
||||
if(entity instanceof SelfDirtinessTracker) {
|
||||
if(((SelfDirtinessTracker) entity).$$_hibernate_hasDirtyAttributes()) {
|
||||
dirtyProperties = persister.resolveAttributeIndexes(((SelfDirtinessTracker) entity).$$_hibernate_getDirtyAttributes());
|
||||
}
|
||||
}
|
||||
else {
|
||||
// see if the custom dirtiness strategy can tell us...
|
||||
class DirtyCheckContextImpl implements CustomEntityDirtinessStrategy.DirtyCheckContext {
|
||||
int[] found;
|
||||
@Override
|
||||
public void doDirtyChecking(CustomEntityDirtinessStrategy.AttributeChecker attributeChecker) {
|
||||
found = new DirtyCheckAttributeInfoImpl( event ).visitAttributes( attributeChecker );
|
||||
if ( found != null && found.length == 0 ) {
|
||||
found = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
DirtyCheckContextImpl context = new DirtyCheckContextImpl();
|
||||
session.getFactory().getCustomEntityDirtinessStrategy().findDirty(
|
||||
entity,
|
||||
persister,
|
||||
(Session) session,
|
||||
context
|
||||
);
|
||||
dirtyProperties = context.found;
|
||||
}
|
||||
if ( entity instanceof SelfDirtinessTracker ) {
|
||||
if ( ( (SelfDirtinessTracker) entity ).$$_hibernate_hasDirtyAttributes() ) {
|
||||
dirtyProperties = persister.resolveAttributeIndexes( ( (SelfDirtinessTracker) entity ).$$_hibernate_getDirtyAttributes() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
// see if the custom dirtiness strategy can tell us...
|
||||
class DirtyCheckContextImpl implements CustomEntityDirtinessStrategy.DirtyCheckContext {
|
||||
int[] found;
|
||||
|
||||
@Override
|
||||
public void doDirtyChecking(CustomEntityDirtinessStrategy.AttributeChecker attributeChecker) {
|
||||
found = new DirtyCheckAttributeInfoImpl( event ).visitAttributes( attributeChecker );
|
||||
if ( found != null && found.length == 0 ) {
|
||||
found = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
DirtyCheckContextImpl context = new DirtyCheckContextImpl();
|
||||
session.getFactory().getCustomEntityDirtinessStrategy().findDirty(
|
||||
entity,
|
||||
persister,
|
||||
(Session) session,
|
||||
context
|
||||
);
|
||||
dirtyProperties = context.found;
|
||||
}
|
||||
}
|
||||
|
||||
event.setDatabaseSnapshot(null);
|
||||
event.setDatabaseSnapshot( null );
|
||||
|
||||
final boolean interceptorHandledDirtyCheck;
|
||||
boolean cannotDirtyCheck;
|
||||
|
||||
if ( dirtyProperties==null ) {
|
||||
if ( dirtyProperties == null ) {
|
||||
// Interceptor returned null, so do the dirtycheck ourself, if possible
|
||||
try {
|
||||
session.getEventListenerManager().dirtyCalculationStart();
|
||||
|
||||
interceptorHandledDirtyCheck = false;
|
||||
// object loaded by update()
|
||||
cannotDirtyCheck = loadedState==null;
|
||||
cannotDirtyCheck = loadedState == null;
|
||||
if ( !cannotDirtyCheck ) {
|
||||
// dirty check against the usual snapshot of the entity
|
||||
dirtyProperties = persister.findDirty( values, loadedState, entity, session );
|
||||
}
|
||||
else if ( entry.getStatus() == Status.DELETED && ! event.getEntityEntry().isModifiableEntity() ) {
|
||||
else if ( entry.getStatus() == Status.DELETED && !event.getEntityEntry().isModifiableEntity() ) {
|
||||
// A non-modifiable (e.g., read-only or immutable) entity needs to be have
|
||||
// references to transient entities set to null before being deleted. No other
|
||||
// fields should be updated.
|
||||
|
@ -557,11 +570,11 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
}
|
||||
else {
|
||||
// dirty check against the database snapshot, if possible/necessary
|
||||
final Object[] databaseSnapshot = getDatabaseSnapshot(session, persister, id);
|
||||
final Object[] databaseSnapshot = getDatabaseSnapshot( session, persister, id );
|
||||
if ( databaseSnapshot != null ) {
|
||||
dirtyProperties = persister.findModified(databaseSnapshot, values, entity, session);
|
||||
dirtyProperties = persister.findModified( databaseSnapshot, values, entity, session );
|
||||
cannotDirtyCheck = false;
|
||||
event.setDatabaseSnapshot(databaseSnapshot);
|
||||
event.setDatabaseSnapshot( databaseSnapshot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -577,9 +590,9 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
|
||||
logDirtyProperties( id, dirtyProperties, persister );
|
||||
|
||||
event.setDirtyProperties(dirtyProperties);
|
||||
event.setDirtyCheckHandledByInterceptor(interceptorHandledDirtyCheck);
|
||||
event.setDirtyCheckPossible(!cannotDirtyCheck);
|
||||
event.setDirtyProperties( dirtyProperties );
|
||||
event.setDirtyCheckHandledByInterceptor( interceptorHandledDirtyCheck );
|
||||
event.setDirtyCheckPossible( !cannotDirtyCheck );
|
||||
|
||||
}
|
||||
|
||||
|
@ -607,17 +620,17 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return persister.getPropertyNames()[ index ];
|
||||
return persister.getPropertyNames()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return persister.getPropertyTypes()[ index ];
|
||||
return persister.getPropertyTypes()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCurrentValue() {
|
||||
return event.getPropertyValues()[ index ];
|
||||
return event.getPropertyValues()[index];
|
||||
}
|
||||
|
||||
Object[] databaseSnapshot;
|
||||
|
@ -627,18 +640,18 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
if ( databaseSnapshot == null ) {
|
||||
databaseSnapshot = getDatabaseSnapshot( event.getSession(), persister, event.getEntityEntry().getId() );
|
||||
}
|
||||
return databaseSnapshot[ index ];
|
||||
return databaseSnapshot[index];
|
||||
}
|
||||
|
||||
public int[] visitAttributes(CustomEntityDirtinessStrategy.AttributeChecker attributeChecker) {
|
||||
databaseSnapshot = null;
|
||||
index = 0;
|
||||
|
||||
final int[] indexes = new int[ numberOfAttributes ];
|
||||
final int[] indexes = new int[numberOfAttributes];
|
||||
int count = 0;
|
||||
for ( ; index < numberOfAttributes; index++ ) {
|
||||
for (; index < numberOfAttributes; index++ ) {
|
||||
if ( attributeChecker.isDirty( this ) ) {
|
||||
indexes[ count++ ] = index;
|
||||
indexes[count++] = index;
|
||||
}
|
||||
}
|
||||
return Arrays.copyOf( indexes, count );
|
||||
|
@ -648,21 +661,23 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
|
|||
private void logDirtyProperties(Serializable id, int[] dirtyProperties, EntityPersister persister) {
|
||||
if ( dirtyProperties != null && dirtyProperties.length > 0 && LOG.isTraceEnabled() ) {
|
||||
final String[] allPropertyNames = persister.getPropertyNames();
|
||||
final String[] dirtyPropertyNames = new String[ dirtyProperties.length ];
|
||||
final String[] dirtyPropertyNames = new String[dirtyProperties.length];
|
||||
for ( int i = 0; i < dirtyProperties.length; i++ ) {
|
||||
dirtyPropertyNames[i] = allPropertyNames[ dirtyProperties[i]];
|
||||
dirtyPropertyNames[i] = allPropertyNames[dirtyProperties[i]];
|
||||
}
|
||||
LOG.tracev( "Found dirty properties [{0}] : {1}",
|
||||
LOG.tracev(
|
||||
"Found dirty properties [{0}] : {1}",
|
||||
MessageHelper.infoString( persister.getEntityName(), id ),
|
||||
dirtyPropertyNames );
|
||||
dirtyPropertyNames
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) {
|
||||
if ( persister.isSelectBeforeUpdateRequired() ) {
|
||||
Object[] snapshot = session.getPersistenceContext()
|
||||
.getDatabaseSnapshot(id, persister);
|
||||
if (snapshot==null) {
|
||||
.getDatabaseSnapshot( id, persister );
|
||||
if ( snapshot == null ) {
|
||||
//do we even really need this? the update will fail anyway....
|
||||
if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
|
||||
session.getFactory().getStatisticsImplementor()
|
||||
|
|
|
@ -36,34 +36,40 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.spi.InitializeCollectionEvent;
|
||||
import org.hibernate.event.spi.InitializeCollectionEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DefaultInitializeCollectionEventListener implements InitializeCollectionEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, DefaultInitializeCollectionEventListener.class.getName() );
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultInitializeCollectionEventListener.class );
|
||||
|
||||
/**
|
||||
* called by a collection that wants to initialize itself
|
||||
*/
|
||||
public void onInitializeCollection(InitializeCollectionEvent event)
|
||||
throws HibernateException {
|
||||
|
||||
public void onInitializeCollection(InitializeCollectionEvent event) throws HibernateException {
|
||||
PersistentCollection collection = event.getCollection();
|
||||
SessionImplementor source = event.getSession();
|
||||
|
||||
CollectionEntry ce = source.getPersistenceContext().getCollectionEntry(collection);
|
||||
if (ce==null) throw new HibernateException("collection was evicted");
|
||||
CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection );
|
||||
if ( ce == null ) {
|
||||
throw new HibernateException( "collection was evicted" );
|
||||
}
|
||||
if ( !collection.wasInitialized() ) {
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Initializing collection {0}",
|
||||
MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), source ) );
|
||||
LOG.tracev(
|
||||
"Initializing collection {0}",
|
||||
MessageHelper.collectionInfoString(
|
||||
ce.getLoadedPersister(),
|
||||
collection,
|
||||
ce.getLoadedKey(),
|
||||
source
|
||||
)
|
||||
);
|
||||
LOG.trace( "Checking second-level cache" );
|
||||
}
|
||||
|
||||
|
@ -72,7 +78,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
|
|||
ce.getLoadedPersister(),
|
||||
collection,
|
||||
source
|
||||
);
|
||||
);
|
||||
|
||||
if ( foundInCache ) {
|
||||
if ( traceEnabled ) {
|
||||
|
@ -91,7 +97,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
|
|||
if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
|
||||
source.getFactory().getStatisticsImplementor().fetchCollection(
|
||||
ce.getLoadedPersister().getRole()
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,8 +110,9 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
|
|||
* @param persister The collection persister
|
||||
* @param collection The collection to initialize
|
||||
* @param source The originating session
|
||||
*
|
||||
* @return true if we were able to initialize the collection from the cache;
|
||||
* false otherwise.
|
||||
* false otherwise.
|
||||
*/
|
||||
private boolean initializeCollectionFromCache(
|
||||
Serializable id,
|
||||
|
@ -113,22 +120,24 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
|
|||
PersistentCollection collection,
|
||||
SessionImplementor source) {
|
||||
|
||||
if ( !source.getLoadQueryInfluencers().getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( source ) ) {
|
||||
if ( !source.getLoadQueryInfluencers().getEnabledFilters().isEmpty()
|
||||
&& persister.isAffectedByEnabledFilters( source ) ) {
|
||||
LOG.trace( "Disregarding cached version (if any) of collection due to enabled filters" );
|
||||
return false;
|
||||
}
|
||||
|
||||
final boolean useCache = persister.hasCache() &&
|
||||
source.getCacheMode().isGetEnabled();
|
||||
final boolean useCache = persister.hasCache() && source.getCacheMode().isGetEnabled();
|
||||
|
||||
if (!useCache) return false;
|
||||
if ( !useCache ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final SessionFactoryImplementor factory = source.getFactory();
|
||||
final CacheKey ck = source.generateCacheKey( id, persister.getKeyType(), persister.getRole() );
|
||||
final SessionFactoryImplementor factory = source.getFactory();
|
||||
final CacheKey ck = source.generateCacheKey( id, persister.getKeyType(), persister.getRole() );
|
||||
final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );
|
||||
|
||||
if ( factory.getStatistics().isStatisticsEnabled() ) {
|
||||
if (ce == null) {
|
||||
if ( ce == null ) {
|
||||
factory.getStatisticsImplementor()
|
||||
.secondLevelCacheMiss( persister.getCacheAccessStrategy().getRegion().getName() );
|
||||
}
|
||||
|
@ -138,16 +147,19 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
|
|||
}
|
||||
}
|
||||
|
||||
if ( ce == null ) {
|
||||
if ( ce == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CollectionCacheEntry cacheEntry = (CollectionCacheEntry)persister.getCacheEntryStructure().destructure(ce, factory);
|
||||
CollectionCacheEntry cacheEntry = (CollectionCacheEntry) persister.getCacheEntryStructure().destructure(
|
||||
ce,
|
||||
factory
|
||||
);
|
||||
|
||||
final PersistenceContext persistenceContext = source.getPersistenceContext();
|
||||
cacheEntry.assemble(collection, persister, persistenceContext.getCollectionOwner(id, persister));
|
||||
persistenceContext.getCollectionEntry(collection).postInitialize(collection);
|
||||
// addInitializedCollection(collection, persister, id);
|
||||
return true;
|
||||
cacheEntry.assemble( collection, persister, persistenceContext.getCollectionOwner( id, persister ) );
|
||||
persistenceContext.getCollectionEntry( collection ).postInitialize( collection );
|
||||
// addInitializedCollection(collection, persister, id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ package org.hibernate.event.internal;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.NonUniqueObjectException;
|
||||
|
@ -53,6 +51,7 @@ import org.hibernate.event.spi.LoadEvent;
|
|||
import org.hibernate.event.spi.LoadEventListener;
|
||||
import org.hibernate.event.spi.PostLoadEvent;
|
||||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -70,28 +69,30 @@ import org.hibernate.type.TypeHelper;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener implements LoadEventListener {
|
||||
|
||||
public static final Object REMOVED_ENTITY_MARKER = new Object();
|
||||
public static final Object INCONSISTENT_RTN_CLASS_MARKER = new Object();
|
||||
public static final LockMode DEFAULT_LOCK_MODE = LockMode.NONE;
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
DefaultLoadEventListener.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultLoadEventListener.class );
|
||||
|
||||
|
||||
/**
|
||||
* Handle the given load event.
|
||||
*
|
||||
* @param event The load event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException {
|
||||
|
||||
final SessionImplementor source = event.getSession();
|
||||
|
||||
EntityPersister persister;
|
||||
if ( event.getInstanceToLoad() != null ) {
|
||||
persister = source.getEntityPersister( null, event.getInstanceToLoad() ); //the load() which takes an entity does not pass an entityName
|
||||
persister = source.getEntityPersister(
|
||||
null,
|
||||
event.getInstanceToLoad()
|
||||
);
|
||||
//the load() which takes an entity does not pass an entityName
|
||||
event.setEntityClassName( event.getInstanceToLoad().getClass().getName() );
|
||||
}
|
||||
else {
|
||||
|
@ -99,14 +100,11 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
}
|
||||
|
||||
if ( persister == null ) {
|
||||
throw new HibernateException(
|
||||
"Unable to locate persister: " +
|
||||
event.getEntityClassName()
|
||||
);
|
||||
throw new HibernateException( "Unable to locate persister: " + event.getEntityClassName() );
|
||||
}
|
||||
|
||||
final Class idClass = persister.getIdentifierType().getReturnedClass();
|
||||
if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
|
||||
if ( idClass != null && !idClass.isInstance( event.getEntityId() ) ) {
|
||||
// we may have the kooky jpa requirement of allowing find-by-id where
|
||||
// "id" is the "simple pk value" of a dependent objects parent. This
|
||||
// is part of its generally goofy "derived identity" "feature"
|
||||
|
@ -133,29 +131,30 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
}
|
||||
}
|
||||
throw new TypeMismatchException(
|
||||
"Provided id of the wrong type for class " + persister.getEntityName() + ". Expected: " + idClass + ", got " + event.getEntityId().getClass()
|
||||
"Provided id of the wrong type for class " + persister.getEntityName() + ". Expected: " + idClass
|
||||
+ ", got " + event.getEntityId().getClass()
|
||||
);
|
||||
}
|
||||
|
||||
final EntityKey keyToLoad = source.generateEntityKey( event.getEntityId(), persister );
|
||||
final EntityKey keyToLoad = source.generateEntityKey( event.getEntityId(), persister );
|
||||
|
||||
try {
|
||||
if ( loadType.isNakedEntityReturned() ) {
|
||||
//do not return a proxy!
|
||||
//(this option indicates we are initializing a proxy)
|
||||
event.setResult( load(event, persister, keyToLoad, loadType) );
|
||||
event.setResult( load( event, persister, keyToLoad, loadType ) );
|
||||
}
|
||||
else {
|
||||
//return a proxy if appropriate
|
||||
if ( event.getLockMode() == LockMode.NONE ) {
|
||||
event.setResult( proxyOrLoad(event, persister, keyToLoad, loadType) );
|
||||
event.setResult( proxyOrLoad( event, persister, keyToLoad, loadType ) );
|
||||
}
|
||||
else {
|
||||
event.setResult( lockAndLoad(event, persister, keyToLoad, loadType, source) );
|
||||
event.setResult( lockAndLoad( event, persister, keyToLoad, loadType, source ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(HibernateException e) {
|
||||
catch (HibernateException e) {
|
||||
LOG.unableToLoadCommand( e );
|
||||
throw e;
|
||||
}
|
||||
|
@ -185,32 +184,41 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param persister The persister corresponding to the entity to be loaded
|
||||
* @param keyToLoad The key of the entity to be loaded
|
||||
* @param options The defined load options
|
||||
*
|
||||
* @return The loaded entity.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
protected Object load(
|
||||
final LoadEvent event,
|
||||
final EntityPersister persister,
|
||||
final EntityKey keyToLoad,
|
||||
final LoadEventListener.LoadType options) {
|
||||
final LoadEvent event,
|
||||
final EntityPersister persister,
|
||||
final EntityKey keyToLoad,
|
||||
final LoadEventListener.LoadType options) {
|
||||
|
||||
if ( event.getInstanceToLoad() != null ) {
|
||||
if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
|
||||
throw new PersistentObjectException(
|
||||
"attempted to load into an instance that was already associated with the session: " +
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||
);
|
||||
MessageHelper.infoString(
|
||||
persister,
|
||||
event.getEntityId(),
|
||||
event.getSession().getFactory()
|
||||
)
|
||||
);
|
||||
}
|
||||
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() );
|
||||
}
|
||||
|
||||
Object entity = doLoad(event, persister, keyToLoad, options);
|
||||
Object entity = doLoad( event, persister, keyToLoad, options );
|
||||
|
||||
boolean isOptionalInstance = event.getInstanceToLoad() != null;
|
||||
|
||||
if ( !options.isAllowNulls() || isOptionalInstance ) {
|
||||
if ( entity == null ) {
|
||||
event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( event.getEntityClassName(), event.getEntityId() );
|
||||
event.getSession()
|
||||
.getFactory()
|
||||
.getEntityNotFoundDelegate()
|
||||
.handleEntityNotFound( event.getEntityClassName(), event.getEntityId() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,38 +237,41 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param persister The persister corresponding to the entity to be loaded
|
||||
* @param keyToLoad The key of the entity to be loaded
|
||||
* @param options The defined load options
|
||||
*
|
||||
* @return The result of the proxy/load operation.
|
||||
*/
|
||||
protected Object proxyOrLoad(
|
||||
final LoadEvent event,
|
||||
final EntityPersister persister,
|
||||
final EntityKey keyToLoad,
|
||||
final LoadEventListener.LoadType options) {
|
||||
final LoadEvent event,
|
||||
final EntityPersister persister,
|
||||
final EntityKey keyToLoad,
|
||||
final LoadEventListener.LoadType options) {
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Loading entity: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Loading entity: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||
);
|
||||
}
|
||||
|
||||
// this class has no proxies (so do a shortcut)
|
||||
if (!persister.hasProxy()) {
|
||||
return load(event, persister, keyToLoad, options);
|
||||
// this class has no proxies (so do a shortcut)
|
||||
if ( !persister.hasProxy() ) {
|
||||
return load( event, persister, keyToLoad, options );
|
||||
}
|
||||
|
||||
final PersistenceContext persistenceContext = event.getSession().getPersistenceContext();
|
||||
final PersistenceContext persistenceContext = event.getSession().getPersistenceContext();
|
||||
|
||||
// look for a proxy
|
||||
Object proxy = persistenceContext.getProxy(keyToLoad);
|
||||
if (proxy != null) {
|
||||
return returnNarrowedProxy(event, persister, keyToLoad, options, persistenceContext, proxy);
|
||||
Object proxy = persistenceContext.getProxy( keyToLoad );
|
||||
if ( proxy != null ) {
|
||||
return returnNarrowedProxy( event, persister, keyToLoad, options, persistenceContext, proxy );
|
||||
}
|
||||
|
||||
if (options.isAllowProxyCreation()) {
|
||||
return createProxyIfNecessary(event, persister, keyToLoad, options, persistenceContext);
|
||||
if ( options.isAllowProxyCreation() ) {
|
||||
return createProxyIfNecessary( event, persister, keyToLoad, options, persistenceContext );
|
||||
}
|
||||
|
||||
// return a newly loaded object
|
||||
return load(event, persister, keyToLoad, options);
|
||||
// return a newly loaded object
|
||||
return load( event, persister, keyToLoad, options );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,6 +284,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param options The defined load options
|
||||
* @param persistenceContext The originating session
|
||||
* @param proxy The proxy to narrow
|
||||
*
|
||||
* @return The created/existing proxy
|
||||
*/
|
||||
private Object returnNarrowedProxy(
|
||||
|
@ -291,7 +303,10 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
if ( !options.isAllowProxyCreation() ) {
|
||||
impl = load( event, persister, keyToLoad, options );
|
||||
if ( impl == null ) {
|
||||
event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier());
|
||||
event.getSession()
|
||||
.getFactory()
|
||||
.getEntityNotFoundDelegate()
|
||||
.handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier() );
|
||||
}
|
||||
}
|
||||
return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
|
||||
|
@ -307,6 +322,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param keyToLoad The key of the entity to be loaded
|
||||
* @param options The defined load options
|
||||
* @param persistenceContext The originating session
|
||||
*
|
||||
* @return The created/existing proxy
|
||||
*/
|
||||
private Object createProxyIfNecessary(
|
||||
|
@ -345,7 +361,9 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param keyToLoad The key of the entity to be loaded
|
||||
* @param options The defined load options
|
||||
* @param source The originating session
|
||||
*
|
||||
* @return The loaded entity
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
protected Object lockAndLoad(
|
||||
|
@ -370,7 +388,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
|
||||
Object entity;
|
||||
try {
|
||||
entity = load(event, persister, keyToLoad, options);
|
||||
entity = load( event, persister, keyToLoad, options );
|
||||
}
|
||||
finally {
|
||||
if ( persister.hasCache() ) {
|
||||
|
@ -392,6 +410,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param persister The persister for the entity being requested for load
|
||||
* @param keyToLoad The EntityKey representing the entity to be loaded.
|
||||
* @param options The load options.
|
||||
*
|
||||
* @return The loaded entity, or null.
|
||||
*/
|
||||
protected Object doLoad(
|
||||
|
@ -401,8 +420,12 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
final LoadEventListener.LoadType options) {
|
||||
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if ( traceEnabled ) LOG.tracev( "Attempting to resolve: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) );
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev(
|
||||
"Attempting to resolve: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||
);
|
||||
}
|
||||
|
||||
Object entity = loadFromSessionCache( event, keyToLoad, options );
|
||||
if ( entity == REMOVED_ENTITY_MARKER ) {
|
||||
|
@ -410,31 +433,48 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
return null;
|
||||
}
|
||||
if ( entity == INCONSISTENT_RTN_CLASS_MARKER ) {
|
||||
LOG.debug( "Load request found matching entity in context, but the matched entity was of an inconsistent return type; returning null" );
|
||||
LOG.debug(
|
||||
"Load request found matching entity in context, but the matched entity was of an inconsistent return type; returning null"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
if ( entity != null ) {
|
||||
if (traceEnabled) LOG.tracev("Resolved object in session cache: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) );
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev(
|
||||
"Resolved object in session cache: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||
);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
entity = loadFromSecondLevelCache(event, persister, options);
|
||||
entity = loadFromSecondLevelCache( event, persister, options );
|
||||
if ( entity != null ) {
|
||||
if ( traceEnabled ) LOG.tracev( "Resolved object in second-level cache: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) );
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev(
|
||||
"Resolved object in second-level cache: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( traceEnabled ) LOG.tracev( "Object not resolved in any cache: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) );
|
||||
entity = loadFromDatasource(event, persister, keyToLoad, options);
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev(
|
||||
"Object not resolved in any cache: {0}",
|
||||
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
|
||||
);
|
||||
}
|
||||
entity = loadFromDatasource( event, persister, keyToLoad, options );
|
||||
}
|
||||
|
||||
if (entity != null && persister.hasNaturalIdentifier()) {
|
||||
|
||||
if ( entity != null && persister.hasNaturalIdentifier() ) {
|
||||
event.getSession().getPersistenceContext().getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
|
||||
persister,
|
||||
event.getEntityId(),
|
||||
event.getSession().getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( entity, persister )
|
||||
event.getSession().getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues(
|
||||
entity,
|
||||
persister
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -450,6 +490,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param persister The persister for the entity being requested for load
|
||||
* @param keyToLoad The EntityKey representing the entity to be loaded.
|
||||
* @param options The load options.
|
||||
*
|
||||
* @return The object loaded from the datasource, or null if not found.
|
||||
*/
|
||||
protected Object loadFromDatasource(
|
||||
|
@ -464,7 +505,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
event.getLockOptions(),
|
||||
source
|
||||
);
|
||||
|
||||
|
||||
if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
|
||||
source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
|
||||
}
|
||||
|
@ -486,7 +527,9 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param event The load event
|
||||
* @param keyToLoad The EntityKey representing the entity to be loaded.
|
||||
* @param options The load options.
|
||||
*
|
||||
* @return The entity from the session-level cache, or null.
|
||||
*
|
||||
* @throws HibernateException Generally indicates problems applying a lock-mode.
|
||||
*/
|
||||
protected Object loadFromSessionCache(
|
||||
|
@ -507,8 +550,10 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
}
|
||||
}
|
||||
if ( options.isAllowNulls() ) {
|
||||
final EntityPersister persister = event.getSession().getFactory().getEntityPersister( keyToLoad.getEntityName() );
|
||||
if ( ! persister.isInstance( old ) ) {
|
||||
final EntityPersister persister = event.getSession()
|
||||
.getFactory()
|
||||
.getEntityPersister( keyToLoad.getEntityName() );
|
||||
if ( !persister.isInstance( old ) ) {
|
||||
return INCONSISTENT_RTN_CLASS_MARKER;
|
||||
}
|
||||
}
|
||||
|
@ -524,6 +569,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
* @param event The load event
|
||||
* @param persister The persister for the entity being requested for load
|
||||
* @param options The load options.
|
||||
*
|
||||
* @return The entity from the second-level cache, or null.
|
||||
*/
|
||||
protected Object loadFromSecondLevelCache(
|
||||
|
@ -534,9 +580,9 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
final SessionImplementor source = event.getSession();
|
||||
final boolean useCache = persister.hasCache()
|
||||
&& source.getCacheMode().isGetEnabled()
|
||||
&& event.getLockMode().lessThan(LockMode.READ);
|
||||
&& event.getLockMode().lessThan( LockMode.READ );
|
||||
|
||||
if ( ! useCache ) {
|
||||
if ( !useCache ) {
|
||||
// we can't use cache here
|
||||
return null;
|
||||
}
|
||||
|
@ -605,7 +651,11 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
entity = ( (ReferenceCacheEntryImpl) entry ).getReference();
|
||||
if ( entity == null ) {
|
||||
throw new IllegalStateException(
|
||||
"Reference cache entry contained null : " + MessageHelper.infoString( persister, entityId, factory )
|
||||
"Reference cache entry contained null : " + MessageHelper.infoString(
|
||||
persister,
|
||||
entityId,
|
||||
factory
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -640,7 +690,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
else {
|
||||
final Type[] types = subclassPersister.getPropertyTypes();
|
||||
// initializes the entity by (desired) side-effect
|
||||
values = ( (StandardCacheEntryImpl) entry).assemble(
|
||||
values = ( (StandardCacheEntryImpl) entry ).assemble(
|
||||
entity, entityId, subclassPersister, session.getInterceptor(), session
|
||||
);
|
||||
if ( ( (StandardCacheEntryImpl) entry ).isDeepCopyNeeded() ) {
|
||||
|
@ -659,7 +709,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
if ( proxy != null ) {
|
||||
// there is already a proxy for this impl
|
||||
// only set the status to read-only if the proxy is read-only
|
||||
isReadOnly = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().isReadOnly();
|
||||
isReadOnly = ( (HibernateProxy) proxy ).getHibernateLazyInitializer().isReadOnly();
|
||||
}
|
||||
else {
|
||||
isReadOnly = session.isDefaultReadOnly();
|
||||
|
@ -706,8 +756,10 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
final SessionFactoryImplementor factory = session.getFactory();
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Assembling entity from second-level cache: {0}",
|
||||
MessageHelper.infoString( persister, id, factory ) );
|
||||
LOG.tracev(
|
||||
"Assembling entity from second-level cache: {0}",
|
||||
MessageHelper.infoString( persister, id, factory )
|
||||
);
|
||||
}
|
||||
|
||||
EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
|
||||
|
@ -724,10 +776,16 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
entry.areLazyPropertiesUnfetched(),
|
||||
entry.getVersion(),
|
||||
session
|
||||
);
|
||||
);
|
||||
|
||||
Type[] types = subclassPersister.getPropertyTypes();
|
||||
Object[] values = entry.assemble( result, id, subclassPersister, session.getInterceptor(), session ); // intializes result by side-effect
|
||||
Object[] values = entry.assemble(
|
||||
result,
|
||||
id,
|
||||
subclassPersister,
|
||||
session.getInterceptor(),
|
||||
session
|
||||
); // intializes result by side-effect
|
||||
TypeHelper.deepCopy(
|
||||
values,
|
||||
types,
|
||||
|
@ -746,7 +804,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
if ( proxy != null ) {
|
||||
// there is already a proxy for this impl
|
||||
// only set the status to read-only if the proxy is read-only
|
||||
isReadOnly = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().isReadOnly();
|
||||
isReadOnly = ( (HibernateProxy) proxy ).getHibernateLazyInitializer().isReadOnly();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -26,8 +26,6 @@ package org.hibernate.event.internal;
|
|||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.ObjectDeletedException;
|
||||
|
@ -44,6 +42,7 @@ import org.hibernate.engine.spi.SessionImplementor;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.MergeEvent;
|
||||
import org.hibernate.event.spi.MergeEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
@ -58,37 +57,36 @@ import org.hibernate.type.TypeHelper;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class DefaultMergeEventListener extends AbstractSaveEventListener implements MergeEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
DefaultMergeEventListener.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultMergeEventListener.class );
|
||||
|
||||
@Override
|
||||
protected Map getMergeMap(Object anything) {
|
||||
return ( ( EventCache ) anything ).invertMap();
|
||||
protected Map getMergeMap(Object anything) {
|
||||
return ( (EventCache) anything ).invertMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the given merge event.
|
||||
*
|
||||
* @param event The merge event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onMerge(MergeEvent event) throws HibernateException {
|
||||
EventCache copyCache = new EventCache( event.getSession() );
|
||||
onMerge( event, copyCache );
|
||||
copyCache.clear();
|
||||
copyCache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the given merge event.
|
||||
*
|
||||
* @param event The merge event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onMerge(MergeEvent event, Map copiedAlready) throws HibernateException {
|
||||
|
||||
final EventCache copyCache = ( EventCache ) copiedAlready;
|
||||
final EventCache copyCache = (EventCache) copiedAlready;
|
||||
final EventSource source = event.getSession();
|
||||
final Object original = event.getOriginal();
|
||||
|
||||
|
@ -148,22 +146,22 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
entityState = getEntityState( entity, event.getEntityName(), entry, source );
|
||||
}
|
||||
|
||||
switch (entityState) {
|
||||
switch ( entityState ) {
|
||||
case DETACHED:
|
||||
entityIsDetached(event, copyCache);
|
||||
entityIsDetached( event, copyCache );
|
||||
break;
|
||||
case TRANSIENT:
|
||||
entityIsTransient(event, copyCache);
|
||||
entityIsTransient( event, copyCache );
|
||||
break;
|
||||
case PERSISTENT:
|
||||
entityIsPersistent(event, copyCache);
|
||||
entityIsPersistent( event, copyCache );
|
||||
break;
|
||||
default: //DELETED
|
||||
throw new ObjectDeletedException(
|
||||
"deleted instance passed to merge",
|
||||
null,
|
||||
getLoggableName( event.getEntityName(), entity )
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,12 +178,12 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
final EventSource source = event.getSession();
|
||||
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
|
||||
|
||||
( ( EventCache ) copyCache ).put( entity, entity, true ); //before cascade!
|
||||
( (EventCache) copyCache ).put( entity, entity, true ); //before cascade!
|
||||
|
||||
cascadeOnMerge(source, persister, entity, copyCache);
|
||||
copyValues(persister, entity, entity, source, copyCache);
|
||||
cascadeOnMerge( source, persister, entity, copyCache );
|
||||
copyValues( persister, entity, entity, source, copyCache );
|
||||
|
||||
event.setResult(entity);
|
||||
event.setResult( entity );
|
||||
}
|
||||
|
||||
protected void entityIsTransient(MergeEvent event, Map copyCache) {
|
||||
|
@ -200,27 +198,27 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
|
||||
final Serializable id = persister.hasIdentifierProperty() ?
|
||||
persister.getIdentifier( entity, source ) :
|
||||
null;
|
||||
null;
|
||||
if ( copyCache.containsKey( entity ) ) {
|
||||
persister.setIdentifier( copyCache.get( entity ), id, source );
|
||||
}
|
||||
else {
|
||||
( ( EventCache ) copyCache ).put( entity, source.instantiate( persister, id ), true ); //before cascade!
|
||||
( (EventCache) copyCache ).put( entity, source.instantiate( persister, id ), true ); //before cascade!
|
||||
}
|
||||
final Object copy = copyCache.get( entity );
|
||||
|
||||
// cascade first, so that all unsaved objects get their
|
||||
// copy created before we actually copy
|
||||
//cascadeOnMerge(event, persister, entity, copyCache, Cascades.CASCADE_BEFORE_MERGE);
|
||||
super.cascadeBeforeSave(source, persister, entity, copyCache);
|
||||
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT);
|
||||
super.cascadeBeforeSave( source, persister, entity, copyCache );
|
||||
copyValues( persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT );
|
||||
|
||||
saveTransientEntity( copy, entityName, event.getRequestedId(), source, copyCache );
|
||||
|
||||
// cascade first, so that all unsaved objects get their
|
||||
// copy created before we actually copy
|
||||
super.cascadeAfterSave(source, persister, entity, copyCache);
|
||||
copyValues(persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT);
|
||||
super.cascadeAfterSave( source, persister, entity, copyCache );
|
||||
copyValues( persister, entity, copy, source, copyCache, ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );
|
||||
|
||||
event.setResult( copy );
|
||||
}
|
||||
|
@ -234,7 +232,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
//this bit is only *really* absolutely necessary for handling
|
||||
//requestedId, but is also good if we merge multiple object
|
||||
//graphs, since it helps ensure uniqueness
|
||||
if (requestedId==null) {
|
||||
if ( requestedId == null ) {
|
||||
saveWithGeneratedId( entity, entityName, copyCache, source, false );
|
||||
}
|
||||
else {
|
||||
|
@ -265,13 +263,13 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
}
|
||||
|
||||
String previousFetchProfile = source.getFetchProfile();
|
||||
source.setFetchProfile("merge");
|
||||
source.setFetchProfile( "merge" );
|
||||
//we must clone embedded composite identifiers, or
|
||||
//we will get back the same instance that we pass in
|
||||
final Serializable clonedIdentifier = (Serializable) persister.getIdentifierType()
|
||||
.deepCopy( id, source.getFactory() );
|
||||
final Object result = source.get(entityName, clonedIdentifier);
|
||||
source.setFetchProfile(previousFetchProfile);
|
||||
final Object result = source.get( entityName, clonedIdentifier );
|
||||
source.setFetchProfile( previousFetchProfile );
|
||||
|
||||
if ( result == null ) {
|
||||
//TODO: we should throw an exception if we really *know* for sure
|
||||
|
@ -281,21 +279,21 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
// we got here because we assumed that an instance
|
||||
// with an assigned id was detached, when it was
|
||||
// really persistent
|
||||
entityIsTransient(event, copyCache);
|
||||
entityIsTransient( event, copyCache );
|
||||
}
|
||||
else {
|
||||
( ( EventCache ) copyCache ).put( entity, result, true ); //before cascade!
|
||||
( (EventCache) copyCache ).put( entity, result, true ); //before cascade!
|
||||
|
||||
final Object target = source.getPersistenceContext().unproxy(result);
|
||||
final Object target = source.getPersistenceContext().unproxy( result );
|
||||
if ( target == entity ) {
|
||||
throw new AssertionFailure("entity was not detached");
|
||||
throw new AssertionFailure( "entity was not detached" );
|
||||
}
|
||||
else if ( !source.getEntityName(target).equals(entityName) ) {
|
||||
else if ( !source.getEntityName( target ).equals( entityName ) ) {
|
||||
throw new WrongClassException(
|
||||
"class of the given object did not match class of persistent copy",
|
||||
event.getRequestedId(),
|
||||
entityName
|
||||
);
|
||||
);
|
||||
}
|
||||
else if ( isVersionChanged( entity, source, persister, target ) ) {
|
||||
if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
|
||||
|
@ -307,13 +305,13 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
|
||||
// cascade first, so that all unsaved objects get their
|
||||
// copy created before we actually copy
|
||||
cascadeOnMerge(source, persister, entity, copyCache);
|
||||
copyValues(persister, entity, target, source, copyCache);
|
||||
cascadeOnMerge( source, persister, entity, copyCache );
|
||||
copyValues( persister, entity, target, source, copyCache );
|
||||
|
||||
//copyValues works by reflection, so explicitly mark the entity instance dirty
|
||||
markInterceptorDirty( entity, target, persister );
|
||||
|
||||
event.setResult(result);
|
||||
event.setResult( result );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -328,7 +326,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
}
|
||||
|
||||
private boolean isVersionChanged(Object entity, EventSource source, EntityPersister persister, Object target) {
|
||||
if ( ! persister.isVersioned() ) {
|
||||
if ( !persister.isVersioned() ) {
|
||||
return false;
|
||||
}
|
||||
// for merging of versioned entities, we consider the version having
|
||||
|
@ -341,7 +339,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
// an entity to be merged during the same transaction
|
||||
// (though during a seperate operation) in which it was
|
||||
// originally persisted/saved
|
||||
boolean changed = ! persister.getVersionType().isSame(
|
||||
boolean changed = !persister.getVersionType().isSame(
|
||||
persister.getVersion( target ),
|
||||
persister.getVersion( entity )
|
||||
);
|
||||
|
@ -431,14 +429,18 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
* @param copyCache A cache of already copied instance.
|
||||
*/
|
||||
protected void cascadeOnMerge(
|
||||
final EventSource source,
|
||||
final EntityPersister persister,
|
||||
final Object entity,
|
||||
final Map copyCache
|
||||
final EventSource source,
|
||||
final EntityPersister persister,
|
||||
final Object entity,
|
||||
final Map copyCache
|
||||
) {
|
||||
source.getPersistenceContext().incrementCascadeLevel();
|
||||
try {
|
||||
new Cascade( getCascadeAction(), CascadePoint.BEFORE_MERGE, source ).cascade( persister, entity, copyCache );
|
||||
new Cascade( getCascadeAction(), CascadePoint.BEFORE_MERGE, source ).cascade(
|
||||
persister,
|
||||
entity,
|
||||
copyCache
|
||||
);
|
||||
}
|
||||
finally {
|
||||
source.getPersistenceContext().decrementCascadeLevel();
|
||||
|
@ -447,12 +449,12 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
|
||||
|
||||
@Override
|
||||
protected CascadingAction getCascadeAction() {
|
||||
protected CascadingAction getCascadeAction() {
|
||||
return CascadingActions.MERGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean getAssumedUnsaved() {
|
||||
protected Boolean getAssumedUnsaved() {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
|
@ -460,15 +462,15 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
|
|||
* Cascade behavior is redefined by this subclass, disable superclass behavior
|
||||
*/
|
||||
@Override
|
||||
protected void cascadeAfterSave(EventSource source, EntityPersister persister, Object entity, Object anything)
|
||||
throws HibernateException {
|
||||
protected void cascadeAfterSave(EventSource source, EntityPersister persister, Object entity, Object anything)
|
||||
throws HibernateException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cascade behavior is redefined by this subclass, disable superclass behavior
|
||||
*/
|
||||
@Override
|
||||
protected void cascadeBeforeSave(EventSource source, EntityPersister persister, Object entity, Object anything)
|
||||
throws HibernateException {
|
||||
protected void cascadeBeforeSave(EventSource source, EntityPersister persister, Object entity, Object anything)
|
||||
throws HibernateException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ package org.hibernate.event.internal;
|
|||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.ObjectDeletedException;
|
||||
import org.hibernate.PersistentObjectException;
|
||||
|
@ -40,6 +38,7 @@ import org.hibernate.event.spi.EventSource;
|
|||
import org.hibernate.event.spi.PersistEvent;
|
||||
import org.hibernate.event.spi.PersistEventListener;
|
||||
import org.hibernate.id.ForeignGenerator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -53,19 +52,15 @@ import org.hibernate.proxy.LazyInitializer;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class DefaultPersistEventListener extends AbstractSaveEventListener implements PersistEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
DefaultPersistEventListener.class.getName()
|
||||
);
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultPersistEventListener.class );
|
||||
|
||||
@Override
|
||||
protected CascadingAction getCascadeAction() {
|
||||
protected CascadingAction getCascadeAction() {
|
||||
return CascadingActions.PERSIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean getAssumedUnsaved() {
|
||||
protected Boolean getAssumedUnsaved() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
@ -73,16 +68,18 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
* Handle the given create event.
|
||||
*
|
||||
* @param event The create event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onPersist(PersistEvent event) throws HibernateException {
|
||||
onPersist( event, new IdentityHashMap(10) );
|
||||
onPersist( event, new IdentityHashMap( 10 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the given create event.
|
||||
*
|
||||
* @param event The create event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onPersist(PersistEvent event, Map createCache) throws HibernateException {
|
||||
|
@ -170,7 +167,7 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
protected void entityIsPersistent(PersistEvent event, Map createCache) {
|
||||
LOG.trace( "Ignoring persistent instance" );
|
||||
final EventSource source = event.getSession();
|
||||
|
@ -180,7 +177,7 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
|
||||
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
|
||||
|
||||
if ( createCache.put(entity, entity)==null ) {
|
||||
if ( createCache.put( entity, entity ) == null ) {
|
||||
justCascade( createCache, source, entity, persister );
|
||||
|
||||
}
|
||||
|
@ -188,8 +185,8 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
|
||||
private void justCascade(Map createCache, EventSource source, Object entity, EntityPersister persister) {
|
||||
//TODO: merge into one method!
|
||||
cascadeBeforeSave(source, persister, entity, createCache);
|
||||
cascadeAfterSave(source, persister, entity, createCache);
|
||||
cascadeBeforeSave( source, persister, entity, createCache );
|
||||
cascadeAfterSave( source, persister, entity, createCache );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,7 +195,7 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
* @param event The save event to be handled.
|
||||
* @param createCache The copy cache of entity instance to merge/copy instance.
|
||||
*/
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
protected void entityIsTransient(PersistEvent event, Map createCache) {
|
||||
LOG.trace( "Saving transient instance" );
|
||||
|
||||
|
@ -210,7 +207,7 @@ public class DefaultPersistEventListener extends AbstractSaveEventListener imple
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
@SuppressWarnings({"unchecked"})
|
||||
private void entityIsDeleted(PersistEvent event, Map createCache) {
|
||||
final EventSource source = event.getSession();
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ import java.io.Serializable;
|
|||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.PersistentObjectException;
|
||||
import org.hibernate.UnresolvableObjectException;
|
||||
|
@ -42,6 +40,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.RefreshEvent;
|
||||
import org.hibernate.event.spi.RefreshEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -56,12 +55,10 @@ import org.hibernate.type.Type;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultRefreshEventListener implements RefreshEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
DefaultRefreshEventListener.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultRefreshEventListener.class );
|
||||
|
||||
public void onRefresh(RefreshEvent event) throws HibernateException {
|
||||
onRefresh( event, new IdentityHashMap(10) );
|
||||
onRefresh( event, new IdentityHashMap( 10 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +70,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
|
||||
final EventSource source = event.getSession();
|
||||
|
||||
boolean isTransient = ! source.contains( event.getObject() );
|
||||
boolean isTransient = !source.contains( event.getObject() );
|
||||
if ( source.getPersistenceContext().reassociateIfUninitializedProxy( event.getObject() ) ) {
|
||||
if ( isTransient ) {
|
||||
source.setReadOnly( event.getObject(), source.isDefaultReadOnly() );
|
||||
|
@ -83,7 +80,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
|
||||
final Object object = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
|
||||
|
||||
if ( refreshedAlready.containsKey(object) ) {
|
||||
if ( refreshedAlready.containsKey( object ) ) {
|
||||
LOG.trace( "Already refreshed" );
|
||||
return;
|
||||
}
|
||||
|
@ -93,25 +90,43 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
final Serializable id;
|
||||
|
||||
if ( e == null ) {
|
||||
persister = source.getEntityPersister(event.getEntityName(), object); //refresh() does not pass an entityName
|
||||
persister = source.getEntityPersister(
|
||||
event.getEntityName(),
|
||||
object
|
||||
); //refresh() does not pass an entityName
|
||||
id = persister.getIdentifier( object, event.getSession() );
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Refreshing transient {0}", MessageHelper.infoString( persister, id, source.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Refreshing transient {0}", MessageHelper.infoString(
|
||||
persister,
|
||||
id,
|
||||
source.getFactory()
|
||||
)
|
||||
);
|
||||
}
|
||||
final EntityKey key = source.generateEntityKey( id, persister );
|
||||
if ( source.getPersistenceContext().getEntry(key) != null ) {
|
||||
if ( source.getPersistenceContext().getEntry( key ) != null ) {
|
||||
throw new PersistentObjectException(
|
||||
"attempted to refresh transient instance when persistent instance was already associated with the Session: " +
|
||||
MessageHelper.infoString(persister, id, source.getFactory() )
|
||||
);
|
||||
MessageHelper.infoString( persister, id, source.getFactory() )
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Refreshing ", MessageHelper.infoString( e.getPersister(), e.getId(), source.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Refreshing ", MessageHelper.infoString(
|
||||
e.getPersister(),
|
||||
e.getId(),
|
||||
source.getFactory()
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( !e.isExistsInDatabase() ) {
|
||||
throw new UnresolvableObjectException(e.getId(), "this instance does not yet exist as a row in the database" );
|
||||
throw new UnresolvableObjectException(
|
||||
e.getId(),
|
||||
"this instance does not yet exist as a row in the database"
|
||||
);
|
||||
}
|
||||
|
||||
persister = e.getPersister();
|
||||
|
@ -128,8 +143,10 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
|
||||
if ( e != null ) {
|
||||
final EntityKey key = source.generateEntityKey( id, persister );
|
||||
source.getPersistenceContext().removeEntity(key);
|
||||
if ( persister.hasCollections() ) new EvictVisitor( source ).process(object, persister);
|
||||
source.getPersistenceContext().removeEntity( key );
|
||||
if ( persister.hasCollections() ) {
|
||||
new EvictVisitor( source ).process( object, persister );
|
||||
}
|
||||
}
|
||||
|
||||
if ( persister.hasCache() ) {
|
||||
|
@ -149,7 +166,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
// Keep the same read-only/modifiable setting for the entity that it had before refreshing;
|
||||
// If it was transient, then set it to the default for the source.
|
||||
if ( result != null ) {
|
||||
if ( ! persister.isMutable() ) {
|
||||
if ( !persister.isMutable() ) {
|
||||
// this is probably redundant; it should already be read-only
|
||||
source.setReadOnly( result, true );
|
||||
}
|
||||
|
@ -157,7 +174,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
source.setReadOnly( result, ( e == null ? source.isDefaultReadOnly() : e.isReadOnly() ) );
|
||||
}
|
||||
}
|
||||
source.getLoadQueryInfluencers().setInternalFetchProfile(previousFetchProfile);
|
||||
source.getLoadQueryInfluencers().setInternalFetchProfile( previousFetchProfile );
|
||||
|
||||
UnresolvableObjectException.throwIfNull( result, id, persister.getEntityName() );
|
||||
|
||||
|
@ -168,15 +185,15 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
}
|
||||
|
||||
private void evictCachedCollections(Type[] types, Serializable id, SessionFactoryImplementor factory)
|
||||
throws HibernateException {
|
||||
for ( Type type : types ) {
|
||||
if ( type.isCollectionType() ) {
|
||||
factory.getCache().evictCollection( ( (CollectionType) type ).getRole(), id );
|
||||
}
|
||||
else if ( type.isComponentType() ) {
|
||||
CompositeType actype = (CompositeType) type;
|
||||
evictCachedCollections( actype.getSubtypes(), id, factory );
|
||||
}
|
||||
}
|
||||
throws HibernateException {
|
||||
for ( Type type : types ) {
|
||||
if ( type.isCollectionType() ) {
|
||||
factory.getCache().evictCollection( ( (CollectionType) type ).getRole(), id );
|
||||
}
|
||||
else if ( type.isComponentType() ) {
|
||||
CompositeType actype = (CompositeType) type;
|
||||
evictCachedCollections( actype.getSubtypes(), id, factory );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ package org.hibernate.event.internal;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.ReplicationMode;
|
||||
|
@ -41,6 +39,7 @@ import org.hibernate.engine.spi.Status;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.ReplicateEvent;
|
||||
import org.hibernate.event.spi.ReplicateEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -53,9 +52,7 @@ import org.hibernate.type.Type;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DefaultReplicateEventListener extends AbstractSaveEventListener implements ReplicateEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
DefaultReplicateEventListener.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultReplicateEventListener.class );
|
||||
|
||||
/**
|
||||
* Handle the given replicate event.
|
||||
|
@ -105,7 +102,13 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if ( oldVersion != null ) {
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Found existing row for {0}", MessageHelper.infoString( persister, id, source.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Found existing row for {0}", MessageHelper.infoString(
|
||||
persister,
|
||||
id,
|
||||
source.getFactory()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// HHH-2378
|
||||
|
@ -120,18 +123,22 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
|
||||
// if can replicate, will result in a SQL UPDATE
|
||||
// else do nothing (don't even reassociate object!)
|
||||
if ( canReplicate )
|
||||
if ( canReplicate ) {
|
||||
performReplication( entity, id, realOldVersion, persister, replicationMode, source );
|
||||
else if ( traceEnabled )
|
||||
}
|
||||
else if ( traceEnabled ) {
|
||||
LOG.trace( "No need to replicate" );
|
||||
}
|
||||
|
||||
//TODO: would it be better to do a refresh from db?
|
||||
}
|
||||
else {
|
||||
// no existing row - do an insert
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "No existing row, replicating new instance {0}",
|
||||
MessageHelper.infoString( persister, id, source.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"No existing row, replicating new instance {0}",
|
||||
MessageHelper.infoString( persister, id, source.getFactory() )
|
||||
);
|
||||
}
|
||||
|
||||
final boolean regenerate = persister.isIdentifierAssignedByInsert(); // prefer re-generation of identity!
|
||||
|
@ -151,7 +158,12 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean visitCollectionsBeforeSave(Object entity, Serializable id, Object[] values, Type[] types, EventSource source) {
|
||||
protected boolean visitCollectionsBeforeSave(
|
||||
Object entity,
|
||||
Serializable id,
|
||||
Object[] values,
|
||||
Type[] types,
|
||||
EventSource source) {
|
||||
//TODO: we use two visitors here, inefficient!
|
||||
OnReplicateVisitor visitor = new OnReplicateVisitor( source, id, entity, false );
|
||||
visitor.processEntityPropertyValues( values, types );
|
||||
|
@ -159,7 +171,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean substituteValuesIfNecessary(
|
||||
protected boolean substituteValuesIfNecessary(
|
||||
Object entity,
|
||||
Serializable id,
|
||||
Object[] values,
|
||||
|
@ -169,7 +181,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVersionIncrementDisabled() {
|
||||
protected boolean isVersionIncrementDisabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -222,7 +234,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp
|
|||
}
|
||||
|
||||
@Override
|
||||
protected CascadingAction getCascadeAction() {
|
||||
protected CascadingAction getCascadeAction() {
|
||||
return CascadingActions.REPLICATE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ package org.hibernate.event.internal;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
|
@ -45,6 +43,7 @@ import org.hibernate.engine.spi.Status;
|
|||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.event.spi.SaveOrUpdateEvent;
|
||||
import org.hibernate.event.spi.SaveOrUpdateEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -58,8 +57,7 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener implements SaveOrUpdateEventListener {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, DefaultSaveOrUpdateEventListener.class.getName() );
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultSaveOrUpdateEventListener.class );
|
||||
|
||||
/**
|
||||
* Handle the given update event.
|
||||
|
@ -75,7 +73,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
//assign the requested id to the proxy, *before*
|
||||
//reassociating the proxy
|
||||
if ( object instanceof HibernateProxy ) {
|
||||
( ( HibernateProxy ) object ).getHibernateLazyInitializer().setIdentifier( requestedId );
|
||||
( (HibernateProxy) object ).getHibernateLazyInitializer().setIdentifier( requestedId );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +155,10 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
}
|
||||
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Object already associated with session: {0}", MessageHelper.infoString( entityEntry.getPersister(), savedId, factory ) );
|
||||
LOG.tracev(
|
||||
"Object already associated with session: {0}",
|
||||
MessageHelper.infoString( entityEntry.getPersister(), savedId, factory )
|
||||
);
|
||||
}
|
||||
|
||||
return savedId;
|
||||
|
@ -282,33 +283,35 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
Object entity,
|
||||
EntityPersister persister) throws HibernateException {
|
||||
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
final boolean traceEnabled = LOG.isTraceEnabled();
|
||||
if ( traceEnabled && !persister.isMutable() ) {
|
||||
LOG.trace( "Immutable instance passed to performUpdate()" );
|
||||
}
|
||||
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Updating {0}",
|
||||
MessageHelper.infoString( persister, event.getRequestedId(), event.getSession().getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Updating {0}",
|
||||
MessageHelper.infoString( persister, event.getRequestedId(), event.getSession().getFactory() )
|
||||
);
|
||||
}
|
||||
|
||||
final EventSource source = event.getSession();
|
||||
final EntityKey key = source.generateEntityKey( event.getRequestedId(), persister );
|
||||
|
||||
source.getPersistenceContext().checkUniqueness(key, entity);
|
||||
source.getPersistenceContext().checkUniqueness( key, entity );
|
||||
|
||||
if (invokeUpdateLifecycle(entity, persister, source)) {
|
||||
reassociate(event, event.getObject(), event.getRequestedId(), persister);
|
||||
return;
|
||||
}
|
||||
if ( invokeUpdateLifecycle( entity, persister, source ) ) {
|
||||
reassociate( event, event.getObject(), event.getRequestedId(), persister );
|
||||
return;
|
||||
}
|
||||
|
||||
// this is a transient object with existing persistent state not loaded by the session
|
||||
|
||||
new OnUpdateVisitor(source, event.getRequestedId(), entity).process(entity, persister);
|
||||
new OnUpdateVisitor( source, event.getRequestedId(), entity ).process( entity, persister );
|
||||
|
||||
// TODO: put this stuff back in to read snapshot from
|
||||
// the second-level cache (needs some extra work)
|
||||
/*Object[] cachedState = null;
|
||||
// the second-level cache (needs some extra work)
|
||||
/*Object[] cachedState = null;
|
||||
|
||||
if ( persister.hasCache() ) {
|
||||
CacheEntry entry = (CacheEntry) persister.getCache()
|
||||
|
@ -320,7 +323,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
|
||||
source.getPersistenceContext().addEntity(
|
||||
entity,
|
||||
(persister.isMutable() ? Status.MANAGED : Status.READ_ONLY),
|
||||
( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
|
||||
null, // cachedState,
|
||||
key,
|
||||
persister.getVersion( entity ),
|
||||
|
@ -329,12 +332,18 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
persister,
|
||||
false,
|
||||
true // assume true, since we don't really know, and it doesn't matter
|
||||
);
|
||||
);
|
||||
|
||||
persister.afterReassociate(entity, source);
|
||||
persister.afterReassociate( entity, source );
|
||||
|
||||
if ( traceEnabled ) {
|
||||
LOG.tracev( "Updating {0}", MessageHelper.infoString( persister, event.getRequestedId(), source.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Updating {0}", MessageHelper.infoString(
|
||||
persister,
|
||||
event.getRequestedId(),
|
||||
source.getFactory()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
cascadeOnUpdate( event, persister, entity );
|
||||
|
@ -371,7 +380,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener
|
|||
}
|
||||
|
||||
@Override
|
||||
protected CascadingAction getCascadeAction() {
|
||||
protected CascadingAction getCascadeAction() {
|
||||
return CascadingActions.SAVE_UPDATE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
|
|||
private boolean[] propertyVersionability;
|
||||
|
||||
DirtyCollectionSearchVisitor(EventSource session, boolean[] propertyVersionability) {
|
||||
super(session);
|
||||
super( session );
|
||||
this.propertyVersionability = propertyVersionability;
|
||||
}
|
||||
|
||||
|
@ -51,16 +51,12 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
|
|||
return dirty;
|
||||
}
|
||||
|
||||
Object processCollection(Object collection, CollectionType type)
|
||||
throws HibernateException {
|
||||
|
||||
if (collection!=null) {
|
||||
|
||||
SessionImplementor session = getSession();
|
||||
|
||||
Object processCollection(Object collection, CollectionType type) throws HibernateException {
|
||||
if ( collection != null ) {
|
||||
final SessionImplementor session = getSession();
|
||||
final PersistentCollection persistentCollection;
|
||||
if ( type.isArrayType() ) {
|
||||
persistentCollection = session.getPersistenceContext().getCollectionHolder(collection);
|
||||
persistentCollection = session.getPersistenceContext().getCollectionHolder( collection );
|
||||
// if no array holder we found an unwrappered array (this can't occur,
|
||||
// because we now always call wrap() before getting to here)
|
||||
// return (ah==null) ? true : searchForDirtyCollections(ah, type);
|
||||
|
@ -74,7 +70,7 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
|
|||
}
|
||||
|
||||
if ( persistentCollection.isDirty() ) { //we need to check even if it was not initialized, because of delayed adds!
|
||||
dirty=true;
|
||||
dirty = true;
|
||||
return null; //NOTE: EARLY EXIT!
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +79,6 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor {
|
|||
}
|
||||
|
||||
boolean includeEntityProperty(Object[] values, int i) {
|
||||
return propertyVersionability[i] && super.includeEntityProperty(values, i);
|
||||
return propertyVersionability[i] && super.includeEntityProperty( values, i );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,10 @@ package org.hibernate.event.internal;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.action.internal.CollectionRemoveAction;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -42,8 +41,7 @@ import org.hibernate.type.Type;
|
|||
* @author Gavin King
|
||||
*/
|
||||
public abstract class ReattachVisitor extends ProxyVisitor {
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, ReattachVisitor.class.getName());
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( ReattachVisitor.class );
|
||||
|
||||
private final Serializable ownerIdentifier;
|
||||
private final Object owner;
|
||||
|
@ -76,7 +74,7 @@ public abstract class ReattachVisitor extends ProxyVisitor {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Object processComponent(Object component, CompositeType componentType) throws HibernateException {
|
||||
Object processComponent(Object component, CompositeType componentType) throws HibernateException {
|
||||
Type[] types = componentType.getSubtypes();
|
||||
if ( component == null ) {
|
||||
processValues( new Object[types.length], types );
|
||||
|
@ -94,12 +92,16 @@ public abstract class ReattachVisitor extends ProxyVisitor {
|
|||
* @param role The persister representing the collection to be removed.
|
||||
* @param collectionKey The collection key (differs from owner-id in the case of property-refs).
|
||||
* @param source The session from which the request originated.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
void removeCollection(CollectionPersister role, Serializable collectionKey, EventSource source) throws HibernateException {
|
||||
void removeCollection(CollectionPersister role, Serializable collectionKey, EventSource source)
|
||||
throws HibernateException {
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Collection dereferenced while transient {0}",
|
||||
MessageHelper.collectionInfoString( role, ownerIdentifier, source.getFactory() ) );
|
||||
LOG.tracev(
|
||||
"Collection dereferenced while transient {0}",
|
||||
MessageHelper.collectionInfoString( role, ownerIdentifier, source.getFactory() )
|
||||
);
|
||||
}
|
||||
source.getActionQueue().addAction( new CollectionRemoveAction( owner, role, collectionKey, false, source ) );
|
||||
}
|
||||
|
@ -111,13 +113,14 @@ public abstract class ReattachVisitor extends ProxyVisitor {
|
|||
* and thus we cannot rely on the owner's EntityEntry snapshot...
|
||||
*
|
||||
* @param role The persister for the collection role being processed.
|
||||
* @return
|
||||
*
|
||||
* @return The value from the owner that identifies the grouping into the collection
|
||||
*/
|
||||
final Serializable extractCollectionKeyFromOwner(CollectionPersister role) {
|
||||
if ( role.getCollectionType().useLHSPrimaryKey() ) {
|
||||
if ( role.getCollectionType().useLHSPrimaryKey() ) {
|
||||
return ownerIdentifier;
|
||||
}
|
||||
return (Serializable)role.getOwnerEntityPersister().getPropertyValue(
|
||||
return (Serializable) role.getOwnerEntityPersister().getPropertyValue(
|
||||
owner,
|
||||
role.getCollectionType().getLHSPropertyName()
|
||||
);
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.event.internal;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
|
@ -40,12 +38,12 @@ import org.hibernate.type.CompositeType;
|
|||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Wrap collections in a Hibernate collection
|
||||
* wrapper.
|
||||
* Wrap collections in a Hibernate collection wrapper.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class WrapVisitor extends ProxyVisitor {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( WrapVisitor.class );
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( WrapVisitor.class );
|
||||
|
||||
boolean substitute;
|
||||
|
||||
|
@ -54,35 +52,35 @@ public class WrapVisitor extends ProxyVisitor {
|
|||
}
|
||||
|
||||
WrapVisitor(EventSource session) {
|
||||
super(session);
|
||||
super( session );
|
||||
}
|
||||
|
||||
@Override
|
||||
Object processCollection(Object collection, CollectionType collectionType)
|
||||
throws HibernateException {
|
||||
Object processCollection(Object collection, CollectionType collectionType)
|
||||
throws HibernateException {
|
||||
|
||||
if ( collection!=null && (collection instanceof PersistentCollection) ) {
|
||||
if ( collection != null && ( collection instanceof PersistentCollection ) ) {
|
||||
|
||||
final SessionImplementor session = getSession();
|
||||
PersistentCollection coll = (PersistentCollection) collection;
|
||||
if ( coll.setCurrentSession(session) ) {
|
||||
if ( coll.setCurrentSession( session ) ) {
|
||||
reattachCollection( coll, collectionType );
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
else {
|
||||
return processArrayOrNewCollection(collection, collectionType);
|
||||
return processArrayOrNewCollection( collection, collectionType );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final Object processArrayOrNewCollection(Object collection, CollectionType collectionType)
|
||||
throws HibernateException {
|
||||
throws HibernateException {
|
||||
|
||||
final SessionImplementor session = getSession();
|
||||
|
||||
if (collection==null) {
|
||||
if ( collection == null ) {
|
||||
//do nothing
|
||||
return null;
|
||||
}
|
||||
|
@ -93,19 +91,21 @@ public class WrapVisitor extends ProxyVisitor {
|
|||
//TODO: move into collection type, so we can use polymorphism!
|
||||
if ( collectionType.hasHolder() ) {
|
||||
|
||||
if (collection==CollectionType.UNFETCHED_COLLECTION) return null;
|
||||
if ( collection == CollectionType.UNFETCHED_COLLECTION ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PersistentCollection ah = persistenceContext.getCollectionHolder(collection);
|
||||
if (ah==null) {
|
||||
ah = collectionType.wrap(session, collection);
|
||||
PersistentCollection ah = persistenceContext.getCollectionHolder( collection );
|
||||
if ( ah == null ) {
|
||||
ah = collectionType.wrap( session, collection );
|
||||
persistenceContext.addNewCollection( persister, ah );
|
||||
persistenceContext.addCollectionHolder(ah);
|
||||
persistenceContext.addCollectionHolder( ah );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
|
||||
PersistentCollection persistentCollection = collectionType.wrap(session, collection);
|
||||
PersistentCollection persistentCollection = collectionType.wrap( session, collection );
|
||||
persistenceContext.addNewCollection( persister, persistentCollection );
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
|
@ -121,30 +121,28 @@ public class WrapVisitor extends ProxyVisitor {
|
|||
}
|
||||
|
||||
@Override
|
||||
void processValue(int i, Object[] values, Type[] types) {
|
||||
void processValue(int i, Object[] values, Type[] types) {
|
||||
Object result = processValue( values[i], types[i] );
|
||||
if (result!=null) {
|
||||
if ( result != null ) {
|
||||
substitute = true;
|
||||
values[i] = result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Object processComponent(Object component, CompositeType componentType)
|
||||
throws HibernateException {
|
||||
|
||||
if (component!=null) {
|
||||
Object processComponent(Object component, CompositeType componentType) throws HibernateException {
|
||||
if ( component != null ) {
|
||||
Object[] values = componentType.getPropertyValues( component, getSession() );
|
||||
Type[] types = componentType.getSubtypes();
|
||||
boolean substituteComponent = false;
|
||||
for ( int i=0; i<types.length; i++ ) {
|
||||
for ( int i = 0; i < types.length; i++ ) {
|
||||
Object result = processValue( values[i], types[i] );
|
||||
if (result!=null) {
|
||||
if ( result != null ) {
|
||||
values[i] = result;
|
||||
substituteComponent = true;
|
||||
}
|
||||
}
|
||||
if (substituteComponent) {
|
||||
if ( substituteComponent ) {
|
||||
componentType.setPropertyValues( component, values, EntityMode.POJO );
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +151,7 @@ public class WrapVisitor extends ProxyVisitor {
|
|||
}
|
||||
|
||||
@Override
|
||||
void process(Object object, EntityPersister persister) throws HibernateException {
|
||||
void process(Object object, EntityPersister persister) throws HibernateException {
|
||||
final Object[] values = persister.getPropertyValues( object );
|
||||
final Type[] types = persister.getPropertyTypes();
|
||||
processEntityPropertyValues( values, types );
|
||||
|
|
|
@ -34,55 +34,56 @@ import org.hibernate.HibernateException;
|
|||
*/
|
||||
public interface LoadEventListener extends Serializable {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Handle the given load event.
|
||||
*
|
||||
* @param event The load event to be handled.
|
||||
* @throws HibernateException
|
||||
*/
|
||||
*
|
||||
* @param event The load event to be handled.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public void onLoad(LoadEvent event, LoadType loadType) throws HibernateException;
|
||||
|
||||
public static final LoadType RELOAD = new LoadType("GET")
|
||||
.setAllowNulls(false)
|
||||
.setAllowProxyCreation(false)
|
||||
.setCheckDeleted(true)
|
||||
.setNakedEntityReturned(false);
|
||||
public static final LoadType RELOAD = new LoadType( "GET" )
|
||||
.setAllowNulls( false )
|
||||
.setAllowProxyCreation( false )
|
||||
.setCheckDeleted( true )
|
||||
.setNakedEntityReturned( false );
|
||||
|
||||
public static final LoadType GET = new LoadType("GET")
|
||||
.setAllowNulls(true)
|
||||
.setAllowProxyCreation(false)
|
||||
.setCheckDeleted(true)
|
||||
.setNakedEntityReturned(false);
|
||||
|
||||
public static final LoadType LOAD = new LoadType("LOAD")
|
||||
.setAllowNulls(false)
|
||||
.setAllowProxyCreation(true)
|
||||
.setCheckDeleted(true)
|
||||
.setNakedEntityReturned(false);
|
||||
|
||||
public static final LoadType IMMEDIATE_LOAD = new LoadType("IMMEDIATE_LOAD")
|
||||
.setAllowNulls(true)
|
||||
.setAllowProxyCreation(false)
|
||||
.setCheckDeleted(false)
|
||||
.setNakedEntityReturned(true);
|
||||
|
||||
public static final LoadType INTERNAL_LOAD_EAGER = new LoadType("INTERNAL_LOAD_EAGER")
|
||||
.setAllowNulls(false)
|
||||
.setAllowProxyCreation(false)
|
||||
.setCheckDeleted(false)
|
||||
.setNakedEntityReturned(false);
|
||||
|
||||
public static final LoadType INTERNAL_LOAD_LAZY = new LoadType("INTERNAL_LOAD_LAZY")
|
||||
.setAllowNulls(false)
|
||||
.setAllowProxyCreation(true)
|
||||
.setCheckDeleted(false)
|
||||
.setNakedEntityReturned(false);
|
||||
|
||||
public static final LoadType INTERNAL_LOAD_NULLABLE = new LoadType("INTERNAL_LOAD_NULLABLE")
|
||||
.setAllowNulls(true)
|
||||
.setAllowProxyCreation(false)
|
||||
.setCheckDeleted(false)
|
||||
.setNakedEntityReturned(false);
|
||||
public static final LoadType GET = new LoadType( "GET" )
|
||||
.setAllowNulls( true )
|
||||
.setAllowProxyCreation( false )
|
||||
.setCheckDeleted( true )
|
||||
.setNakedEntityReturned( false );
|
||||
|
||||
public static final LoadType LOAD = new LoadType( "LOAD" )
|
||||
.setAllowNulls( false )
|
||||
.setAllowProxyCreation( true )
|
||||
.setCheckDeleted( true )
|
||||
.setNakedEntityReturned( false );
|
||||
|
||||
public static final LoadType IMMEDIATE_LOAD = new LoadType( "IMMEDIATE_LOAD" )
|
||||
.setAllowNulls( true )
|
||||
.setAllowProxyCreation( false )
|
||||
.setCheckDeleted( false )
|
||||
.setNakedEntityReturned( true );
|
||||
|
||||
public static final LoadType INTERNAL_LOAD_EAGER = new LoadType( "INTERNAL_LOAD_EAGER" )
|
||||
.setAllowNulls( false )
|
||||
.setAllowProxyCreation( false )
|
||||
.setCheckDeleted( false )
|
||||
.setNakedEntityReturned( false );
|
||||
|
||||
public static final LoadType INTERNAL_LOAD_LAZY = new LoadType( "INTERNAL_LOAD_LAZY" )
|
||||
.setAllowNulls( false )
|
||||
.setAllowProxyCreation( true )
|
||||
.setCheckDeleted( false )
|
||||
.setNakedEntityReturned( false );
|
||||
|
||||
public static final LoadType INTERNAL_LOAD_NULLABLE = new LoadType( "INTERNAL_LOAD_NULLABLE" )
|
||||
.setAllowNulls( true )
|
||||
.setAllowProxyCreation( false )
|
||||
.setCheckDeleted( false )
|
||||
.setNakedEntityReturned( false );
|
||||
|
||||
public static final class LoadType {
|
||||
private String name;
|
||||
|
@ -92,9 +93,9 @@ public interface LoadEventListener extends Serializable {
|
|||
private boolean checkDeleted;
|
||||
private boolean allowProxyCreation;
|
||||
|
||||
private LoadType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
private LoadType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isAllowNulls() {
|
||||
return allowNulls;
|
||||
|
@ -135,7 +136,8 @@ public interface LoadEventListener extends Serializable {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -32,13 +32,11 @@ import org.hibernate.persister.collection.CollectionPersister;
|
|||
* @author Gail Badner
|
||||
*/
|
||||
public class PostCollectionRemoveEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PostCollectionRemoveEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source,
|
||||
Object loadedOwner ) {
|
||||
super( collectionPersister, collection, source,
|
||||
loadedOwner,
|
||||
getOwnerIdOrNull( loadedOwner, source ) );
|
||||
public PostCollectionRemoveEvent(
|
||||
CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source,
|
||||
Object loadedOwner) {
|
||||
super( collectionPersister, collection, source, loadedOwner, getOwnerIdOrNull( loadedOwner, source ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,16 @@ import org.hibernate.persister.collection.CollectionPersister;
|
|||
* @author Gail Badner
|
||||
*/
|
||||
public class PostCollectionUpdateEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PostCollectionUpdateEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super( collectionPersister, collection, source,
|
||||
public PostCollectionUpdateEvent(
|
||||
CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super(
|
||||
collectionPersister,
|
||||
collection,
|
||||
source,
|
||||
getLoadedOwnerOrNull( collection, source ),
|
||||
getLoadedOwnerIdOrNull( collection, source ) );
|
||||
getLoadedOwnerIdOrNull( collection, source )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,11 +33,16 @@ import org.hibernate.persister.collection.CollectionPersister;
|
|||
*/
|
||||
public class PreCollectionRecreateEvent extends AbstractCollectionEvent {
|
||||
|
||||
public PreCollectionRecreateEvent(CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super( collectionPersister, collection, source,
|
||||
public PreCollectionRecreateEvent(
|
||||
CollectionPersister collectionPersister,
|
||||
PersistentCollection collection,
|
||||
EventSource source) {
|
||||
super(
|
||||
collectionPersister,
|
||||
collection,
|
||||
source,
|
||||
collection.getOwner(),
|
||||
getOwnerIdOrNull( collection.getOwner(), source ) );
|
||||
getOwnerIdOrNull( collection.getOwner(), source )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,18 +32,17 @@ import org.hibernate.secure.spi.PermissionCheckEntityInformation;
|
|||
/**
|
||||
* Represents a <tt>pre-delete</tt> event, which occurs just prior to
|
||||
* performing the deletion of an entity from the database.
|
||||
*
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PreDeleteEvent
|
||||
extends AbstractPreDatabaseOperationEvent
|
||||
implements PermissionCheckEntityInformation{
|
||||
implements PermissionCheckEntityInformation {
|
||||
|
||||
private Object[] deletedState;
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructs an event containing the pertinent information.
|
||||
*
|
||||
* @param entity The entity to be deleted.
|
||||
|
@ -58,7 +57,7 @@ public class PreDeleteEvent
|
|||
Object[] deletedState,
|
||||
EntityPersister persister,
|
||||
EventSource source) {
|
||||
super( source, entity, id, persister );
|
||||
super( source, entity, id, persister );
|
||||
this.deletedState = deletedState;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,27 +40,20 @@ import org.hibernate.sql.JoinFragment;
|
|||
* @author josh
|
||||
*/
|
||||
public final class CollectionSubqueryFactory {
|
||||
|
||||
//TODO: refactor to .sql package
|
||||
|
||||
private CollectionSubqueryFactory() {
|
||||
}
|
||||
|
||||
public static String createCollectionSubquery(
|
||||
JoinSequence joinSequence,
|
||||
Map enabledFilters,
|
||||
String[] columns) {
|
||||
Map enabledFilters,
|
||||
String[] columns) {
|
||||
try {
|
||||
JoinFragment join = joinSequence.toJoinFragment( enabledFilters, true );
|
||||
return new StringBuilder( "select " )
|
||||
.append( StringHelper.join( ", ", columns ) )
|
||||
.append( " from " )
|
||||
.append( join.toFromFragmentString().substring( 2 ) )// remove initial ", "
|
||||
.append( " where " )
|
||||
.append( join.toWhereFragmentString().substring( 5 ) )// remove initial " and "
|
||||
.toString();
|
||||
return "select " + StringHelper.join( ", ", columns )
|
||||
+ " from " + join.toFromFragmentString().substring( 2 )
|
||||
+ " where " + join.toWhereFragmentString().substring( 5 );
|
||||
}
|
||||
catch ( MappingException me ) {
|
||||
catch (MappingException me) {
|
||||
throw new QueryException( me );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,27 +28,23 @@ import java.util.ArrayList;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.hql.internal.classic.ParserHelper;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Provides query splitting methods, which were originally in QueryTranslator.
|
||||
* <br>
|
||||
* TODO: This will need to be refactored at some point.
|
||||
*
|
||||
* @author josh
|
||||
*/
|
||||
public final class QuerySplitter {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( QuerySplitter.class );
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, QuerySplitter.class.getName());
|
||||
|
||||
private static final Set BEFORE_CLASS_TOKENS = new HashSet();
|
||||
private static final Set NOT_AFTER_CLASS_TOKENS = new HashSet();
|
||||
private static final Set<String> BEFORE_CLASS_TOKENS = new HashSet<String>();
|
||||
private static final Set<String> NOT_AFTER_CLASS_TOKENS = new HashSet<String>();
|
||||
|
||||
static {
|
||||
BEFORE_CLASS_TOKENS.add( "from" );
|
||||
|
@ -82,14 +78,17 @@ public final class QuerySplitter {
|
|||
//TODO: this is one of the ugliest and most fragile pieces of code in Hibernate....
|
||||
|
||||
String[] tokens = StringHelper.split( StringHelper.WHITESPACE + "(),", query, true );
|
||||
if ( tokens.length == 0 ) return new String[]{query}; // just especially for the trivial collection filter
|
||||
ArrayList placeholders = new ArrayList();
|
||||
ArrayList replacements = new ArrayList();
|
||||
if ( tokens.length == 0 ) {
|
||||
// just especially for the trivial collection filter
|
||||
return new String[] { query };
|
||||
}
|
||||
ArrayList<String> placeholders = new ArrayList<String>();
|
||||
ArrayList<String[]> replacements = new ArrayList<String[]>();
|
||||
StringBuilder templateQuery = new StringBuilder( 40 );
|
||||
|
||||
int start = getStartingPositionFor(tokens, templateQuery);
|
||||
int start = getStartingPositionFor( tokens, templateQuery );
|
||||
int count = 0;
|
||||
String next = null;
|
||||
String next;
|
||||
String last = tokens[start - 1].toLowerCase();
|
||||
|
||||
for ( int i = start; i < tokens.length; i++ ) {
|
||||
|
@ -101,14 +100,14 @@ public final class QuerySplitter {
|
|||
continue;
|
||||
}
|
||||
|
||||
next = nextNonWhite(tokens, i).toLowerCase();
|
||||
next = nextNonWhite( tokens, i ).toLowerCase();
|
||||
|
||||
boolean process = isJavaIdentifier( token ) &&
|
||||
isPossiblyClassName( last, next );
|
||||
|
||||
last = token.toLowerCase();
|
||||
|
||||
if (process) {
|
||||
if ( process ) {
|
||||
String importedClassName = getImportedClass( token, factory );
|
||||
if ( importedClassName != null ) {
|
||||
String[] implementors = factory.getImplementors( importedClassName );
|
||||
|
@ -123,37 +122,45 @@ public final class QuerySplitter {
|
|||
templateQuery.append( token );
|
||||
|
||||
}
|
||||
String[] results = StringHelper.multiply( templateQuery.toString(), placeholders.iterator(), replacements.iterator() );
|
||||
String[] results = StringHelper.multiply(
|
||||
templateQuery.toString(),
|
||||
placeholders.iterator(),
|
||||
replacements.iterator()
|
||||
);
|
||||
if ( results.length == 0 ) {
|
||||
LOG.noPersistentClassesFound( query );
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
private static String nextNonWhite(String[] tokens, int start) {
|
||||
for ( int i = start + 1; i < tokens.length; i++ ) {
|
||||
if ( !ParserHelper.isWhitespace( tokens[i] ) ) return tokens[i];
|
||||
if ( !ParserHelper.isWhitespace( tokens[i] ) ) {
|
||||
return tokens[i];
|
||||
}
|
||||
}
|
||||
return tokens[tokens.length - 1];
|
||||
}
|
||||
|
||||
|
||||
private static int getStartingPositionFor(String[] tokens, StringBuilder templateQuery) {
|
||||
templateQuery.append( tokens[0] );
|
||||
if ( !"select".equals( tokens[0].toLowerCase() ) ) return 1;
|
||||
if ( !"select".equals( tokens[0].toLowerCase() ) ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// select-range is terminated by declaration of "from"
|
||||
for (int i = 1; i < tokens.length; i++ ) {
|
||||
if ( "from".equals( tokens[i].toLowerCase() ) ) return i;
|
||||
for ( int i = 1; i < tokens.length; i++ ) {
|
||||
if ( "from".equals( tokens[i].toLowerCase() ) ) {
|
||||
return i;
|
||||
}
|
||||
templateQuery.append( tokens[i] );
|
||||
}
|
||||
return tokens.length;
|
||||
}
|
||||
|
||||
private static boolean isPossiblyClassName(String last, String next) {
|
||||
return "class".equals( last ) || (
|
||||
BEFORE_CLASS_TOKENS.contains( last ) &&
|
||||
!NOT_AFTER_CLASS_TOKENS.contains( next )
|
||||
);
|
||||
return "class".equals( last )
|
||||
|| ( BEFORE_CLASS_TOKENS.contains( last ) && !NOT_AFTER_CLASS_TOKENS.contains( next ) );
|
||||
}
|
||||
|
||||
private static boolean isJavaIdentifier(String token) {
|
||||
|
|
Loading…
Reference in New Issue