HHH-5916 Use PersisterClassProvider in Binders

This commit is contained in:
Emmanuel Bernard 2011-02-14 13:56:59 +01:00
parent d7c48d779c
commit e18799b036
3 changed files with 60 additions and 2 deletions

View File

@ -87,6 +87,9 @@ import org.hibernate.mapping.UnionSubclass;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.mapping.Value;
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.SingleTableEntityPersister;
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
@ -687,6 +690,9 @@ public final class HbmBinder {
entity.setMetaAttributes( getMetas( node, inheritedMetas ) );
// PERSISTER
//persister node in XML has priority over
//persisterClassProvider
//if all fail, the default Hibernate persisters kick in
Attribute persisterNode = node.attribute( "persister" );
if ( persisterNode != null ) {
try {
@ -698,6 +704,17 @@ public final class HbmBinder {
+ 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
handleCustomSQL( node, entity );
@ -1399,6 +1416,9 @@ public final class HbmBinder {
// PERSISTER
//persister node in XML has priority over
//persisterClassProvider
//if all fail, the default Hibernate persisters kick in
Attribute persisterNode = node.attribute( "persister" );
if ( persisterNode != null ) {
try {
@ -1410,6 +1430,16 @@ public final class HbmBinder {
+ 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" );
if ( typeNode != null ) {

View File

@ -111,6 +111,8 @@ import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Table;
import org.hibernate.persister.PersisterClassProvider;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.util.StringHelper;
/**
@ -399,8 +401,23 @@ public abstract class CollectionBinder {
collection.setMutable( !property.isAnnotationPresent( Immutable.class ) );
OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
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 );
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
if ( orderBy != null ) collection.setOrderBy( orderBy );

View File

@ -83,6 +83,7 @@ import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.TableOwner;
import org.hibernate.mapping.Value;
import org.hibernate.persister.PersisterClassProvider;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
@ -251,6 +252,8 @@ public class EntityBinder {
//set persister if needed
//@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 );
Class persister = null;
if ( persisterAnn != null ) {
@ -266,8 +269,16 @@ public class EntityBinder {
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 );