HHH-6447 - Develop shared binding creation approach
This commit is contained in:
parent
b17e062a37
commit
c5b013d368
|
@ -182,7 +182,17 @@ public class EntityBinder {
|
|||
|
||||
private EntityBinding doRootEntityBindingCreation() {
|
||||
EntityBinding entityBinding = new EntityBinding();
|
||||
entityBinding.setInheritanceType( InheritanceType.NO_INHERITANCE );
|
||||
|
||||
//temporary (for discrim subclass)
|
||||
// entityBinding.setInheritanceType( InheritanceType.NO_INHERITANCE );
|
||||
entityBinding.setInheritanceType( superType == null ? InheritanceType.NO_INHERITANCE : InheritanceType.SINGLE_TABLE );
|
||||
if ( superType != null ) {
|
||||
EntityBinding superBinding = bindingContext.getMetadataImplementor().getEntityBinding( superType.getName() );
|
||||
if ( superBinding == null ) {
|
||||
throw new AssertionFailure( "EntityBinding for super-type [" + superType.getName() + "] not yet bound" );
|
||||
}
|
||||
entityBinding.setSuperEntityBinding( superBinding );
|
||||
}
|
||||
|
||||
doBasicEntityBinding( entityBinding );
|
||||
|
||||
|
@ -315,6 +325,10 @@ public class EntityBinder {
|
|||
EntityBinding entityBinding = new EntityBinding();
|
||||
entityBinding.setInheritanceType( InheritanceType.SINGLE_TABLE );
|
||||
|
||||
entityBinding.setSuperEntityBinding(
|
||||
bindingContext.getMetadataImplementor().getEntityBinding( superType.getName() )
|
||||
);
|
||||
|
||||
doBasicEntityBinding( entityBinding );
|
||||
|
||||
// todo : bind discriminator-based subclassing specifics...
|
||||
|
@ -326,6 +340,10 @@ public class EntityBinder {
|
|||
EntityBinding entityBinding = new EntityBinding();
|
||||
entityBinding.setInheritanceType( InheritanceType.JOINED );
|
||||
|
||||
entityBinding.setSuperEntityBinding(
|
||||
bindingContext.getMetadataImplementor().getEntityBinding( superType.getName() )
|
||||
);
|
||||
|
||||
doBasicEntityBinding( entityBinding );
|
||||
|
||||
// todo : bind join-based subclassing specifics...
|
||||
|
@ -337,6 +355,10 @@ public class EntityBinder {
|
|||
EntityBinding entityBinding = new EntityBinding();
|
||||
entityBinding.setInheritanceType( InheritanceType.TABLE_PER_CLASS );
|
||||
|
||||
entityBinding.setSuperEntityBinding(
|
||||
bindingContext.getMetadataImplementor().getEntityBinding( superType.getName() )
|
||||
);
|
||||
|
||||
doBasicEntityBinding( entityBinding );
|
||||
|
||||
// todo : bind union-based subclassing specifics...
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Map;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.DuplicateMappingException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
@ -102,7 +103,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
* Maps the fully qualified class name of an entity to its entity binding
|
||||
*/
|
||||
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
|
||||
private Map<String, EntityBinding> rootEntityBindingMap = new HashMap<String, EntityBinding>();
|
||||
|
||||
private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
|
||||
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
|
||||
private Map<String, String> imports = new HashMap<String, String>();
|
||||
|
@ -380,24 +381,19 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
|||
|
||||
@Override
|
||||
public EntityBinding getRootEntityBinding(String entityName) {
|
||||
EntityBinding rootEntityBinding = rootEntityBindingMap.get( entityName );
|
||||
if ( rootEntityBinding == null ) {
|
||||
EntityBinding entityBinding = entityBindingMap.get( entityName );
|
||||
if ( entityBinding == null ) {
|
||||
throw new IllegalStateException( "Unknown entity binding: " + entityName );
|
||||
}
|
||||
if ( entityBinding.isRoot() ) {
|
||||
rootEntityBinding = entityBinding;
|
||||
}
|
||||
else {
|
||||
if ( entityBinding.getEntity().getSuperType() == null ) {
|
||||
throw new IllegalStateException( "Entity binding has no root: " + entityName );
|
||||
}
|
||||
rootEntityBinding = getRootEntityBinding( entityBinding.getEntity().getSuperType().getName() );
|
||||
}
|
||||
rootEntityBindingMap.put( entityName, rootEntityBinding );
|
||||
EntityBinding binding = entityBindingMap.get( entityName );
|
||||
if ( binding == null ) {
|
||||
throw new IllegalStateException( "Unknown entity binding: " + entityName );
|
||||
}
|
||||
return rootEntityBinding;
|
||||
|
||||
do {
|
||||
if ( binding.isRoot() ) {
|
||||
return binding;
|
||||
}
|
||||
binding = binding.getSuperEntityBinding();
|
||||
} while ( binding != null );
|
||||
|
||||
throw new AssertionFailure( "Entity binding has no root: " + entityName );
|
||||
}
|
||||
|
||||
public Iterable<EntityBinding> getEntityBindings() {
|
||||
|
|
Loading…
Reference in New Issue