HHH-5916 Use PersisterClassProvider in Binders
This commit is contained in:
parent
d7c48d779c
commit
e18799b036
|
@ -87,6 +87,9 @@ import org.hibernate.mapping.UnionSubclass;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
import org.hibernate.mapping.Value;
|
import org.hibernate.mapping.Value;
|
||||||
import org.hibernate.mapping.FetchProfile;
|
import org.hibernate.mapping.FetchProfile;
|
||||||
|
import org.hibernate.persister.PersisterClassProvider;
|
||||||
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
|
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
|
||||||
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
||||||
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
|
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
|
||||||
|
@ -687,6 +690,9 @@ public final class HbmBinder {
|
||||||
entity.setMetaAttributes( getMetas( node, inheritedMetas ) );
|
entity.setMetaAttributes( getMetas( node, inheritedMetas ) );
|
||||||
|
|
||||||
// PERSISTER
|
// PERSISTER
|
||||||
|
//persister node in XML has priority over
|
||||||
|
//persisterClassProvider
|
||||||
|
//if all fail, the default Hibernate persisters kick in
|
||||||
Attribute persisterNode = node.attribute( "persister" );
|
Attribute persisterNode = node.attribute( "persister" );
|
||||||
if ( persisterNode != null ) {
|
if ( persisterNode != null ) {
|
||||||
try {
|
try {
|
||||||
|
@ -698,6 +704,17 @@ public final class HbmBinder {
|
||||||
+ persisterNode.getValue() );
|
+ persisterNode.getValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||||
|
if ( persisterClassProvider != null ) {
|
||||||
|
final Class<? extends EntityPersister> persister = persisterClassProvider.getEntityPersisterClass(
|
||||||
|
entity.getEntityName()
|
||||||
|
);
|
||||||
|
if ( persister != null ) {
|
||||||
|
entity.setEntityPersisterClass( persister );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CUSTOM SQL
|
// CUSTOM SQL
|
||||||
handleCustomSQL( node, entity );
|
handleCustomSQL( node, entity );
|
||||||
|
@ -1399,6 +1416,9 @@ public final class HbmBinder {
|
||||||
|
|
||||||
|
|
||||||
// PERSISTER
|
// PERSISTER
|
||||||
|
//persister node in XML has priority over
|
||||||
|
//persisterClassProvider
|
||||||
|
//if all fail, the default Hibernate persisters kick in
|
||||||
Attribute persisterNode = node.attribute( "persister" );
|
Attribute persisterNode = node.attribute( "persister" );
|
||||||
if ( persisterNode != null ) {
|
if ( persisterNode != null ) {
|
||||||
try {
|
try {
|
||||||
|
@ -1410,6 +1430,16 @@ public final class HbmBinder {
|
||||||
+ persisterNode.getValue() );
|
+ persisterNode.getValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||||
|
if ( persisterClassProvider != null ) {
|
||||||
|
final Class<? extends CollectionPersister> persister =
|
||||||
|
persisterClassProvider.getCollectionPersisterClass( collection.getRole() );
|
||||||
|
if ( persister != null ) {
|
||||||
|
collection.setCollectionPersisterClass( persister );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Attribute typeNode = node.attribute( "collection-type" );
|
Attribute typeNode = node.attribute( "collection-type" );
|
||||||
if ( typeNode != null ) {
|
if ( typeNode != null ) {
|
||||||
|
|
|
@ -111,6 +111,8 @@ import org.hibernate.mapping.Selectable;
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.mapping.SingleTableSubclass;
|
import org.hibernate.mapping.SingleTableSubclass;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
|
import org.hibernate.persister.PersisterClassProvider;
|
||||||
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.util.StringHelper;
|
import org.hibernate.util.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -399,8 +401,23 @@ public abstract class CollectionBinder {
|
||||||
collection.setMutable( !property.isAnnotationPresent( Immutable.class ) );
|
collection.setMutable( !property.isAnnotationPresent( Immutable.class ) );
|
||||||
OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
|
OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
|
||||||
if ( lockAnn != null ) collection.setOptimisticLocked( !lockAnn.excluded() );
|
if ( lockAnn != null ) collection.setOptimisticLocked( !lockAnn.excluded() );
|
||||||
|
|
||||||
|
//@Persister has priority over PersisterClassProvider
|
||||||
|
//if all fail, left null and Hibernate defaults kick in
|
||||||
Persister persisterAnn = property.getAnnotation( Persister.class );
|
Persister persisterAnn = property.getAnnotation( Persister.class );
|
||||||
if ( persisterAnn != null ) collection.setCollectionPersisterClass( persisterAnn.impl() );
|
if ( persisterAnn != null ) {
|
||||||
|
collection.setCollectionPersisterClass( persisterAnn.impl() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||||
|
if (persisterClassProvider != null) {
|
||||||
|
final Class<? extends CollectionPersister> persister =
|
||||||
|
persisterClassProvider.getCollectionPersisterClass( collection.getRole() );
|
||||||
|
if (persister != null) {
|
||||||
|
collection.setCollectionPersisterClass( persister );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set ordering
|
// set ordering
|
||||||
if ( orderBy != null ) collection.setOrderBy( orderBy );
|
if ( orderBy != null ) collection.setOrderBy( orderBy );
|
||||||
|
|
|
@ -83,6 +83,7 @@ import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
import org.hibernate.mapping.TableOwner;
|
import org.hibernate.mapping.TableOwner;
|
||||||
import org.hibernate.mapping.Value;
|
import org.hibernate.mapping.Value;
|
||||||
|
import org.hibernate.persister.PersisterClassProvider;
|
||||||
import org.hibernate.util.ReflectHelper;
|
import org.hibernate.util.ReflectHelper;
|
||||||
import org.hibernate.util.StringHelper;
|
import org.hibernate.util.StringHelper;
|
||||||
|
|
||||||
|
@ -251,6 +252,8 @@ public class EntityBinder {
|
||||||
|
|
||||||
//set persister if needed
|
//set persister if needed
|
||||||
//@Persister has precedence over @Entity.persister
|
//@Persister has precedence over @Entity.persister
|
||||||
|
//in both fail we look for the PersisterClassProvider
|
||||||
|
//if all fail, the persister is left null and the Hibernate defaults kick in
|
||||||
Persister persisterAnn = annotatedClass.getAnnotation( Persister.class );
|
Persister persisterAnn = annotatedClass.getAnnotation( Persister.class );
|
||||||
Class persister = null;
|
Class persister = null;
|
||||||
if ( persisterAnn != null ) {
|
if ( persisterAnn != null ) {
|
||||||
|
@ -266,8 +269,16 @@ public class EntityBinder {
|
||||||
throw new AnnotationException( "Could not find persister class: " + persister );
|
throw new AnnotationException( "Could not find persister class: " + persister );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||||
|
if ( persisterClassProvider != null ) {
|
||||||
|
persister = persisterClassProvider.getEntityPersisterClass( persistentClass.getEntityName() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( persister != null ) {
|
||||||
|
persistentClass.setEntityPersisterClass( persister );
|
||||||
}
|
}
|
||||||
if ( persister != null ) persistentClass.setEntityPersisterClass( persister );
|
|
||||||
|
|
||||||
persistentClass.setBatchSize( batchSize );
|
persistentClass.setBatchSize( batchSize );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue