HHH-9336 Avoid creation of TypedValue objects in

AbstractPersistentCollection#getOrphans(Collection, Collection,
String, SessionImplementor) for some ID types.
This commit is contained in:
Andrej Golovnin 2014-11-27 21:01:21 +01:00 committed by Steve Ebersole
parent 4615ae1018
commit a381e368eb
1 changed files with 18 additions and 2 deletions

View File

@ -55,7 +55,13 @@ import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper; import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.ComponentType; import org.hibernate.type.ComponentType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
import org.hibernate.type.PostgresUUIDType;
import org.hibernate.type.StringType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.UUIDBinaryType;
import org.hibernate.type.UUIDCharType;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
/** /**
@ -1117,6 +1123,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
final EntityPersister entityPersister = session.getFactory().getEntityPersister( entityName ); final EntityPersister entityPersister = session.getFactory().getEntityPersister( entityName );
final Type idType = entityPersister.getIdentifierType(); final Type idType = entityPersister.getIdentifierType();
final boolean useIdDirect = mayUseIdDirect( idType );
// create the collection holding the Orphans // create the collection holding the Orphans
final Collection res = new ArrayList(); final Collection res = new ArrayList();
@ -1136,7 +1143,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
current, current,
session session
); );
currentIds.add( new TypedValue( idType, currentId ) ); currentIds.add( useIdDirect ? currentId : new TypedValue( idType, currentId ) );
} }
} }
} }
@ -1145,7 +1152,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
for ( Object old : oldElements ) { for ( Object old : oldElements ) {
if ( !currentSaving.contains( old ) ) { if ( !currentSaving.contains( old ) ) {
final Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session ); final Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session );
if ( !currentIds.contains( new TypedValue( idType, oldId ) ) ) { if ( !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) {
res.add( old ); res.add( old );
} }
} }
@ -1154,6 +1161,15 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
return res; return res;
} }
private static boolean mayUseIdDirect(Type idType) {
return idType == StringType.INSTANCE
|| idType == IntegerType.INSTANCE
|| idType == LongType.INSTANCE
|| idType == UUIDBinaryType.INSTANCE
|| idType == UUIDCharType.INSTANCE
|| idType == PostgresUUIDType.INSTANCE;
}
/** /**
* Removes entity entries that have an equal identifier with the incoming entity instance * Removes entity entries that have an equal identifier with the incoming entity instance
* *