HHH-6471 - Redesign how EntityBinding models hierarchy-shared information

This commit is contained in:
Steve Ebersole 2011-07-21 12:15:48 -05:00
parent 8639904969
commit 46102a2be3
23 changed files with 225 additions and 168 deletions

View File

@ -96,8 +96,8 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
Comparator versionComparator = null;
if ( model.isVersioned() ) {
versionComparator = (
( VersionType ) model
.getVersioningValueBinding()
( VersionType ) model.getHierarchyDetails()
.getVersioningAttributeBinding()
.getHibernateTypeDescriptor()
.getResolvedTypeMapping()
).getComparator();

View File

@ -605,7 +605,7 @@ public final class SessionFactoryImpl
if ( entityBinding.isRoot() ) {
identifierGenerators.put(
entityBinding.getEntity().getName(),
entityBinding.getEntityIdentifier().getIdentifierGenerator()
entityBinding.getHierarchyDetails().getEntityIdentifier().getIdentifierGenerator()
);
}
}
@ -632,13 +632,13 @@ public final class SessionFactoryImpl
EntityBinding rootEntityBinding = metadata.getRootEntityBinding( model.getEntity().getName() );
EntityRegionAccessStrategy accessStrategy = null;
if ( settings.isSecondLevelCacheEnabled() &&
rootEntityBinding.getCaching() != null &&
model.getCaching() != null &&
model.getCaching().getAccessType() != null ) {
final String cacheRegionName = cacheRegionPrefix + rootEntityBinding.getCaching().getRegion();
rootEntityBinding.getHierarchyDetails().getCaching() != null &&
model.getHierarchyDetails().getCaching() != null &&
model.getHierarchyDetails().getCaching().getAccessType() != null ) {
final String cacheRegionName = cacheRegionPrefix + rootEntityBinding.getHierarchyDetails().getCaching().getRegion();
accessStrategy = EntityRegionAccessStrategy.class.cast( entityAccessStrategies.get( cacheRegionName ) );
if ( accessStrategy == null ) {
final AccessType accessType = model.getCaching().getAccessType();
final AccessType accessType = model.getHierarchyDetails().getCaching().getAccessType();
LOG.trace("Building cache for entity data [" + model.getEntity().getName() + "]");
EntityRegion entityRegion =
settings.getRegionFactory().buildEntityRegion(

View File

@ -117,7 +117,7 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
}
protected final boolean isPrimaryKey() {
return this == getEntityBinding().getEntityIdentifier().getValueBinding();
return this == getEntityBinding().getHierarchyDetails().getEntityIdentifier().getValueBinding();
}
@Override

View File

@ -29,7 +29,6 @@ import java.util.Map;
import java.util.Set;
import org.hibernate.EntityMode;
import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.domain.Entity;
@ -48,10 +47,12 @@ import org.hibernate.tuple.entity.EntityTuplizer;
* @author Gail Badner
*/
public class EntityBinding {
private final EntityBinding superEntityBinding;
private final HierarchyDetails hierarchyDetails;
private Entity entity;
private TableSpecification baseTable;
private EntityMode entityMode;
private Value<Class<?>> proxyInterfaceType;
private String jpaEntityName;
@ -59,26 +60,33 @@ public class EntityBinding {
private Class<? extends EntityPersister> customEntityPersisterClass;
private Class<? extends EntityTuplizer> customEntityTuplizerClass;
private InheritanceType entityInheritanceType;
private EntityBinding superEntityBinding;
private final EntityIdentifier entityIdentifier = new EntityIdentifier( this );
private EntityDiscriminator entityDiscriminator;
private String discriminatorValue;
private SimpleSingularAttributeBinding versionBinding;
private String discriminatorMatchValue;
private Map<String, AttributeBinding> attributeBindingMap = new HashMap<String, AttributeBinding>();
private Set<FilterDefinition> filterDefinitions = new HashSet<FilterDefinition>();
private Set<SingularAssociationAttributeBinding> entityReferencingAttributeBindings = new HashSet<SingularAssociationAttributeBinding>();
private Caching caching;
/**
* Used to instantiate the EntityBinding for an entity that is the root of an inheritance hierarchy
*
* @param inheritanceType The inheritance type for the hierarchy
* @param entityMode The entity mode used in this hierarchy.
*/
public EntityBinding(InheritanceType inheritanceType, EntityMode entityMode) {
this.superEntityBinding = null;
this.hierarchyDetails = new HierarchyDetails( this, inheritanceType, entityMode );
}
public EntityBinding(EntityBinding superEntityBinding) {
this.superEntityBinding = superEntityBinding;
this.hierarchyDetails = superEntityBinding.getHierarchyDetails();
}
private MetaAttributeContext metaAttributeContext;
private boolean lazy;
private boolean mutable;
private boolean explicitPolymorphism;
private String whereFilter;
private String rowId;
@ -88,7 +96,6 @@ public class EntityBinding {
private int batchSize;
private boolean selectBeforeUpdate;
private boolean hasSubselectLoadableCollections;
private OptimisticLockStyle optimisticLockStyle;
private Boolean isAbstract;
@ -99,6 +106,19 @@ public class EntityBinding {
private Set<String> synchronizedTableNames = new HashSet<String>();
public HierarchyDetails getHierarchyDetails() {
return hierarchyDetails;
}
public EntityBinding getSuperEntityBinding() {
return superEntityBinding;
}
public boolean isRoot() {
return superEntityBinding == null;
}
public Entity getEntity() {
return entity;
}
@ -120,56 +140,12 @@ public class EntityBinding {
return baseTable;
}
public boolean isRoot() {
return superEntityBinding == null;
}
public void setInheritanceType(InheritanceType entityInheritanceType) {
this.entityInheritanceType = entityInheritanceType;
}
public InheritanceType getInheritanceType() {
return entityInheritanceType;
}
public void setSuperEntityBinding(EntityBinding superEntityBinding) {
this.superEntityBinding = superEntityBinding;
}
public EntityBinding getSuperEntityBinding() {
return superEntityBinding;
}
public EntityIdentifier getEntityIdentifier() {
return entityIdentifier;
}
public EntityDiscriminator getEntityDiscriminator() {
return entityDiscriminator;
}
public void setEntityDiscriminator(EntityDiscriminator entityDiscriminator) {
this.entityDiscriminator = entityDiscriminator;
}
public String getDiscriminatorValue() {
return discriminatorValue;
}
public void setDiscriminatorValue(String discriminatorValue) {
this.discriminatorValue = discriminatorValue;
}
public boolean isVersioned() {
return versionBinding != null;
return getHierarchyDetails().getVersioningAttributeBinding() != null;
}
public void setVersionBinding(SimpleSingularAttributeBinding versionBinding) {
this.versionBinding = versionBinding;
}
public SimpleSingularAttributeBinding getVersioningValueBinding() {
return versionBinding;
public String getDiscriminatorMatchValue() {
return discriminatorMatchValue;
}
public Iterable<AttributeBinding> getAttributeBindings() {
@ -254,14 +230,6 @@ public class EntityBinding {
attributeBindingMap.put( name, attributeBinding );
}
public Caching getCaching() {
return caching;
}
public void setCaching(Caching caching) {
this.caching = caching;
}
public MetaAttributeContext getMetaAttributeContext() {
return metaAttributeContext;
}
@ -302,14 +270,6 @@ public class EntityBinding {
this.whereFilter = whereFilter;
}
public boolean isExplicitPolymorphism() {
return explicitPolymorphism;
}
public void setExplicitPolymorphism(boolean explicitPolymorphism) {
this.explicitPolymorphism = explicitPolymorphism;
}
public String getRowId() {
return rowId;
}
@ -359,14 +319,6 @@ public class EntityBinding {
this.hasSubselectLoadableCollections = hasSubselectLoadableCollections;
}
public OptimisticLockStyle getOptimisticLockStyle() {
return optimisticLockStyle;
}
public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) {
this.optimisticLockStyle = optimisticLockStyle;
}
public Class<? extends EntityPersister> getCustomEntityPersisterClass() {
return customEntityPersisterClass;
}
@ -399,14 +351,6 @@ public class EntityBinding {
this.synchronizedTableNames.addAll( synchronizedTableNames );
}
public EntityMode getEntityMode() {
return entityMode;
}
public void setEntityMode(EntityMode entityMode) {
this.entityMode = entityMode;
}
public String getJpaEntityName() {
return jpaEntityName;
}

View File

@ -0,0 +1,110 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.binding;
import org.hibernate.EntityMode;
import org.hibernate.engine.OptimisticLockStyle;
/**
* @author Steve Ebersole
*/
public class HierarchyDetails {
private final EntityBinding rootEntityBinding;
private final InheritanceType inheritanceType;
private final EntityMode entityMode;
private final EntityIdentifier entityIdentifier;
private EntityDiscriminator entityDiscriminator;
private OptimisticLockStyle optimisticLockStyle;
private SimpleSingularAttributeBinding versioningAttributeBinding;
private Caching caching;
private boolean explicitPolymorphism;
public HierarchyDetails(EntityBinding rootEntityBinding, InheritanceType inheritanceType, EntityMode entityMode) {
this.rootEntityBinding = rootEntityBinding;
this.inheritanceType = inheritanceType;
this.entityMode = entityMode;
this.entityIdentifier = new EntityIdentifier( rootEntityBinding );
}
public EntityBinding getRootEntityBinding() {
return rootEntityBinding;
}
public InheritanceType getInheritanceType() {
return inheritanceType;
}
public EntityMode getEntityMode() {
return entityMode;
}
public EntityIdentifier getEntityIdentifier() {
return entityIdentifier;
}
public EntityDiscriminator getEntityDiscriminator() {
return entityDiscriminator;
}
public OptimisticLockStyle getOptimisticLockStyle() {
return optimisticLockStyle;
}
public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) {
this.optimisticLockStyle = optimisticLockStyle;
}
public void setEntityDiscriminator(EntityDiscriminator entityDiscriminator) {
this.entityDiscriminator = entityDiscriminator;
}
public SimpleSingularAttributeBinding getVersioningAttributeBinding() {
return versioningAttributeBinding;
}
public void setVersioningAttributeBinding(SimpleSingularAttributeBinding versioningAttributeBinding) {
this.versioningAttributeBinding = versioningAttributeBinding;
}
public Caching getCaching() {
return caching;
}
public void setCaching(Caching caching) {
this.caching = caching;
}
public boolean isExplicitPolymorphism() {
return explicitPolymorphism;
}
public void setExplicitPolymorphism(boolean explicitPolymorphism) {
this.explicitPolymorphism = explicitPolymorphism;
}
}

View File

@ -171,23 +171,22 @@ public class Binder {
bindVersion( entityBinding, entitySource );
bindDiscriminator( entitySource, entityBinding );
entityBinding.getHierarchyDetails().setCaching( entitySource.getCaching() );
entityBinding.getHierarchyDetails().setExplicitPolymorphism( entitySource.isExplicitPolymorphism() );
entityBinding.getHierarchyDetails().setOptimisticLockStyle( entitySource.getOptimisticLockStyle() );
entityBinding.setMutable( entitySource.isMutable() );
entityBinding.setExplicitPolymorphism( entitySource.isExplicitPolymorphism() );
entityBinding.setWhereFilter( entitySource.getWhere() );
entityBinding.setRowId( entitySource.getRowId() );
entityBinding.setOptimisticLockStyle( entitySource.getOptimisticLockStyle() );
entityBinding.setCaching( entitySource.getCaching() );
return entityBinding;
}
private EntityBinding buildBasicEntityBinding(EntitySource entitySource, EntityBinding superEntityBinding) {
final EntityBinding entityBinding = new EntityBinding();
entityBinding.setSuperEntityBinding( superEntityBinding );
entityBinding.setInheritanceType( currentInheritanceType );
entityBinding.setEntityMode( currentHierarchyEntityMode );
final EntityBinding entityBinding = superEntityBinding == null
? new EntityBinding( currentInheritanceType, currentHierarchyEntityMode )
: new EntityBinding( superEntityBinding );
final String entityName = entitySource.getEntityName();
final String className = currentHierarchyEntityMode == EntityMode.POJO ? entitySource.getClassName() : null;
@ -202,7 +201,7 @@ public class Binder {
entityBinding.setJpaEntityName( entitySource.getJpaEntityName() );
if ( entityBinding.getEntityMode() == EntityMode.POJO ) {
if ( currentHierarchyEntityMode == EntityMode.POJO ) {
final String proxy = entitySource.getProxy();
if ( proxy != null ) {
entityBinding.setProxyInterfaceType(
@ -317,8 +316,8 @@ public class Binder {
identifierSource.getIdentifierAttributeSource(), entityBinding
);
entityBinding.getEntityIdentifier().setValueBinding( idAttributeBinding );
entityBinding.getEntityIdentifier().setIdGenerator( identifierSource.getIdentifierGeneratorDescriptor() );
entityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding );
entityBinding.getHierarchyDetails().getEntityIdentifier().setIdGenerator( identifierSource.getIdentifierGeneratorDescriptor() );
final org.hibernate.metamodel.relational.Value relationalValue = idAttributeBinding.getValue();
@ -347,7 +346,7 @@ public class Binder {
SimpleSingularAttributeBinding attributeBinding = doBasicSingularAttributeBindingCreation(
versioningAttributeSource, entityBinding
);
entityBinding.setVersionBinding( attributeBinding );
entityBinding.getHierarchyDetails().setVersioningAttributeBinding( attributeBinding );
}
private void bindDiscriminator(RootEntitySource entitySource, EntityBinding entityBinding) {

View File

@ -61,7 +61,7 @@ class AssociationResolver {
AttributeBinding referencedAttributeBinding =
attributeBinding.isPropertyReference() ?
entityBinding.getAttributeBinding( attributeBinding.getReferencedAttributeName() ) :
entityBinding.getEntityIdentifier().getValueBinding();
entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding();
if ( referencedAttributeBinding == null ) {
// TODO: does attribute name include path w/ entity name?
throw new MappingException(

View File

@ -67,7 +67,7 @@ public class IdentifierGeneratorResolver {
new ObjectNameNormalizerImpl( metadata )
);
}
entityBinding.getEntityIdentifier().createIdentifierGenerator(
entityBinding.getHierarchyDetails().getEntityIdentifier().createIdentifierGenerator(
metadata.getIdentifierGeneratorFactory(),
properties
);

View File

@ -511,6 +511,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
throw new MappingException( "Entity binding not known: " + entityName );
}
return entityBinding
.getHierarchyDetails()
.getEntityIdentifier()
.getValueBinding()
.getHibernateTypeDescriptor()
@ -523,7 +524,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
if ( entityBinding == null ) {
throw new MappingException( "Entity binding not known: " + entityName );
}
AttributeBinding idBinding = entityBinding.getEntityIdentifier().getValueBinding();
AttributeBinding idBinding = entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding();
return idBinding == null ? null : idBinding.getAttribute().getName();
}

View File

@ -772,9 +772,9 @@ public abstract class AbstractEntityPersister
this.factory = factory;
this.cacheAccessStrategy = cacheAccessStrategy;
this.isLazyPropertiesCacheable =
entityBinding.getCaching() == null ?
entityBinding.getHierarchyDetails().getCaching() == null ?
false :
entityBinding.getCaching().isCacheLazyProperties();
entityBinding.getHierarchyDetails().getCaching().isCacheLazyProperties();
this.cacheEntryStructure =
factory.getSettings().isStructuredCacheEntriesEnabled() ?
new StructuredCacheEntry(this) :
@ -791,7 +791,7 @@ public abstract class AbstractEntityPersister
// IDENTIFIER
identifierColumnSpan = entityBinding.getEntityIdentifier().getValueBinding().getSimpleValueSpan();
identifierColumnSpan = entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding().getSimpleValueSpan();
rootTableKeyColumnNames = new String[identifierColumnSpan];
rootTableKeyColumnReaders = new String[identifierColumnSpan];
rootTableKeyColumnReaderTemplates = new String[identifierColumnSpan];
@ -821,7 +821,7 @@ public abstract class AbstractEntityPersister
// VERSION
if ( entityBinding.isVersioned() ) {
final Value versioningValue = entityBinding.getVersioningValueBinding().getValue();
final Value versioningValue = entityBinding.getHierarchyDetails().getVersioningAttributeBinding().getValue();
if ( ! org.hibernate.metamodel.relational.Column.class.isInstance( versioningValue ) ) {
throw new AssertionFailure( "Bad versioning attribute binding : " + versioningValue );
}
@ -864,7 +864,7 @@ public abstract class AbstractEntityPersister
i = 0;
boolean foundFormula = false;
for ( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure() ) {
if ( attributeBinding == entityBinding.getEntityIdentifier().getValueBinding() ) {
if ( attributeBinding == entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() ) {
// entity identifier is not considered a "normal" property
continue;
}
@ -970,7 +970,7 @@ public abstract class AbstractEntityPersister
// TODO: fix this when EntityBinding.getSubclassAttributeBindingClosure() is working
// for ( AttributeBinding prop : entityBinding.getSubclassAttributeBindingClosure() ) {
for ( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure() ) {
if ( attributeBinding == entityBinding.getEntityIdentifier().getValueBinding() ) {
if ( attributeBinding == entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() ) {
// entity identifier is not considered a "normal" property
continue;
}

View File

@ -548,11 +548,11 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
final Object discriminatorValue;
if ( isPolymorphic ) {
org.hibernate.metamodel.relational.Value discrimValue =
entityBinding.getEntityDiscriminator().getValueBinding().getValue();
entityBinding.getHierarchyDetails().getEntityDiscriminator().getValueBinding().getValue();
if (discrimValue==null) {
throw new MappingException("discriminator mapping required for single table polymorphic persistence");
}
forceDiscriminator = entityBinding.getEntityDiscriminator().isForced();
forceDiscriminator = entityBinding.getHierarchyDetails().getEntityDiscriminator().isForced();
if ( ! SimpleValue.class.isInstance( discrimValue ) ) {
throw new MappingException( "discriminator must be mapped to a single column or formula." );
}
@ -585,6 +585,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
}
discriminatorType =
entityBinding
.getHierarchyDetails()
.getEntityDiscriminator()
.getValueBinding()
.getHibernateTypeDescriptor()
@ -606,7 +607,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
}
else {
discriminatorInsertable =
entityBinding.getEntityDiscriminator().isInserted() &&
entityBinding.getHierarchyDetails().getEntityDiscriminator().isInserted() &&
! DerivedValue.class.isInstance( discrimValue );
try {
DiscriminatorType dtype = ( DiscriminatorType ) discriminatorType;
@ -642,7 +643,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
for( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure() ) {
// TODO: fix when joins are working (HHH-6391)
//propertyTableNumbers[i++] = entityBinding.getJoinNumber( attributeBinding);
if ( attributeBinding == entityBinding.getEntityIdentifier().getValueBinding() ) {
if ( attributeBinding == entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() ) {
continue; // skip identifier binding
}
if ( ! attributeBinding.getAttribute().isSingular() ) {

View File

@ -47,12 +47,10 @@ import org.hibernate.persister.spi.UnknownPersisterException;
public class StandardPersisterClassResolver implements PersisterClassResolver {
public Class<? extends EntityPersister> getEntityPersisterClass(EntityBinding metadata) {
// todo : make sure this is based on an attribute kept on the metamodel in the new code, not the concrete PersistentClass impl found!
if ( metadata.isRoot() ) {
return singleTableEntityPersister(); // EARLY RETURN!
}
switch ( metadata.getInheritanceType() ) {
switch ( metadata.getHierarchyDetails().getInheritanceType() ) {
case JOINED: {
return joinedSubclassEntityPersister();
}

View File

@ -86,7 +86,7 @@ public class PojoInstantiator implements Instantiator, Serializable {
public PojoInstantiator(EntityBinding entityBinding, ReflectionOptimizer.InstantiationOptimizer optimizer) {
this.mappedClass = entityBinding.getEntity().getClassReference();
this.proxyInterface = entityBinding.getProxyInterfaceType().getValue();
this.embeddedIdentifier = entityBinding.getEntityIdentifier().isEmbedded();
this.embeddedIdentifier = entityBinding.getHierarchyDetails().getEntityIdentifier().isEmbedded();
this.optimizer = optimizer;
try {

View File

@ -109,7 +109,7 @@ public class PropertyFactory {
*/
public static IdentifierProperty buildIdentifierProperty(EntityBinding mappedEntity, IdentifierGenerator generator) {
final SimpleSingularAttributeBinding property = mappedEntity.getEntityIdentifier().getValueBinding();
final SimpleSingularAttributeBinding property = mappedEntity.getHierarchyDetails().getEntityIdentifier().getValueBinding();
// TODO: the following will cause an NPE with "virtual" IDs; how should they be set?
// (steve) virtual attributes will still be attributes, they will simply be marked as virtual.
@ -129,8 +129,8 @@ public class PropertyFactory {
// this is a virtual id property...
return new IdentifierProperty(
type,
mappedEntity.getEntityIdentifier().isEmbedded(),
mappedEntity.getEntityIdentifier().isIdentifierMapper(),
mappedEntity.getHierarchyDetails().getEntityIdentifier().isEmbedded(),
mappedEntity.getHierarchyDetails().getEntityIdentifier().isIdentifierMapper(),
unsavedValue,
generator
);
@ -140,7 +140,7 @@ public class PropertyFactory {
property.getAttribute().getName(),
null,
type,
mappedEntity.getEntityIdentifier().isEmbedded(),
mappedEntity.getHierarchyDetails().getEntityIdentifier().isEmbedded(),
unsavedValue,
generator
);

View File

@ -241,8 +241,8 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
this.entityMetamodel = entityMetamodel;
if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
idGetter = buildPropertyGetter( mappingInfo.getEntityIdentifier().getValueBinding() );
idSetter = buildPropertySetter( mappingInfo.getEntityIdentifier().getValueBinding() );
idGetter = buildPropertyGetter( mappingInfo.getHierarchyDetails().getEntityIdentifier().getValueBinding() );
idSetter = buildPropertySetter( mappingInfo.getHierarchyDetails().getEntityIdentifier().getValueBinding() );
}
else {
idGetter = null;
@ -257,7 +257,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
boolean foundCustomAccessor = false;
int i = 0;
for ( AttributeBinding property : mappingInfo.getAttributeBindingClosure() ) {
if ( property == mappingInfo.getEntityIdentifier().getValueBinding() ) {
if ( property == mappingInfo.getHierarchyDetails().getEntityIdentifier().getValueBinding() ) {
continue; // ID binding processed above
}

View File

@ -387,7 +387,7 @@ public class EntityMetamodel implements Serializable {
// TODO: Fix after HHH-6337 is fixed; for now assume entityBinding is the root binding
//SimpleSingularAttributeBinding rootEntityIdentifier = entityBinding.getRootEntityBinding().getEntityIdentifier().getValueBinding();
SimpleSingularAttributeBinding rootEntityIdentifier = entityBinding.getEntityIdentifier().getValueBinding();
SimpleSingularAttributeBinding rootEntityIdentifier = entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding();
// entityBinding.getAttributeClosureSpan() includes the identifier binding;
// "properties" here excludes the ID, so subtract 1 if the identifier binding is non-null
propertySpan = rootEntityIdentifier == null ?
@ -428,9 +428,11 @@ public class EntityMetamodel implements Serializable {
continue;
}
if ( attributeBinding == entityBinding.getVersioningValueBinding() ) {
if ( attributeBinding == entityBinding.getHierarchyDetails().getVersioningAttributeBinding() ) {
tempVersionProperty = i;
properties[i] = PropertyFactory.buildVersionProperty( entityBinding.getVersioningValueBinding(), lazyAvailable );
properties[i] = PropertyFactory.buildVersionProperty(
entityBinding.getHierarchyDetails().getVersioningAttributeBinding(), lazyAvailable
);
}
else {
properties[i] = PropertyFactory.buildStandardProperty( attributeBinding, lazyAvailable );
@ -546,13 +548,13 @@ public class EntityMetamodel implements Serializable {
//polymorphic = ! entityBinding.isRoot() || entityBinding.hasSubclasses();
polymorphic = ! entityBinding.isRoot() || hasSubclasses;
explicitPolymorphism = entityBinding.isExplicitPolymorphism();
explicitPolymorphism = entityBinding.getHierarchyDetails().isExplicitPolymorphism();
inherited = ! entityBinding.isRoot();
superclass = inherited ?
entityBinding.getEntity().getSuperType().getName() :
null;
optimisticLockStyle = entityBinding.getOptimisticLockStyle();
optimisticLockStyle = entityBinding.getHierarchyDetails().getOptimisticLockStyle();
final boolean isAllOrDirty =
optimisticLockStyle == OptimisticLockStyle.ALL
|| optimisticLockStyle == OptimisticLockStyle.DIRTY;

View File

@ -323,13 +323,14 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
proxyInterfaces,
proxyGetIdentifierMethod,
proxySetIdentifierMethod,
entityBinding.getEntityIdentifier().isEmbedded() ?
( CompositeType ) entityBinding
entityBinding.getHierarchyDetails().getEntityIdentifier().isEmbedded()
? ( CompositeType ) entityBinding
.getHierarchyDetails()
.getEntityIdentifier()
.getValueBinding()
.getHibernateTypeDescriptor()
.getResolvedTypeMapping() :
null
.getResolvedTypeMapping()
: null
);
}
catch ( HibernateException he ) {

View File

@ -85,7 +85,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
assertRoot( metadata, entityBinding );
assertIdAndSimpleProperty( entityBinding );
assertNull( entityBinding.getVersioningValueBinding() );
assertNull( entityBinding.getHierarchyDetails().getVersioningAttributeBinding() );
}
@Test
@ -94,8 +94,8 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
EntityBinding entityBinding = metadata.getEntityBinding( SimpleVersionedEntity.class.getName() );
assertIdAndSimpleProperty( entityBinding );
assertNotNull( entityBinding.getVersioningValueBinding() );
assertNotNull( entityBinding.getVersioningValueBinding().getAttribute() );
assertNotNull( entityBinding.getHierarchyDetails().getVersioningAttributeBinding() );
assertNotNull( entityBinding.getHierarchyDetails().getVersioningAttributeBinding().getAttribute() );
}
@Test
@ -130,12 +130,12 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
protected void assertIdAndSimpleProperty(EntityBinding entityBinding) {
assertNotNull( entityBinding );
assertNotNull( entityBinding.getEntityIdentifier() );
assertNotNull( entityBinding.getEntityIdentifier().getValueBinding() );
assertNotNull( entityBinding.getHierarchyDetails().getEntityIdentifier() );
assertNotNull( entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() );
AttributeBinding idAttributeBinding = entityBinding.getAttributeBinding( "id" );
assertNotNull( idAttributeBinding );
assertSame( idAttributeBinding, entityBinding.getEntityIdentifier().getValueBinding() );
assertSame( idAttributeBinding, entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() );
assertSame( LongType.INSTANCE, idAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping() );
assertTrue( idAttributeBinding.getAttribute().isSingular() );

View File

@ -27,6 +27,7 @@ import java.sql.Types;
import org.junit.Test;
import org.hibernate.EntityMode;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.domain.Entity;
import org.hibernate.metamodel.domain.SingularAttribute;
@ -55,7 +56,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
public void testBasicMiddleOutBuilding() {
Table table = new Table( new Schema( null, null ), "the_table" );
Entity entity = new Entity( "TheEntity", "NoSuchClass", makeJavaType( "NoSuchClass" ), null );
EntityBinding entityBinding = new EntityBinding();
EntityBinding entityBinding = new EntityBinding( InheritanceType.NO_INHERITANCE, EntityMode.POJO );
entityBinding.setEntity( entity );
entityBinding.setBaseTable( table );
@ -64,7 +65,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( "long" );
assertSame( idAttribute, attributeBinding.getAttribute() );
entityBinding.getEntityIdentifier().setValueBinding( attributeBinding );
entityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( attributeBinding );
Column idColumn = table.locateOrCreateColumn( "id" );
idColumn.setDatatype( BIGINT );

View File

@ -50,8 +50,8 @@ public class CacheBindingTests extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = HibernateCacheEntity.class, cacheMode = SharedCacheMode.ALL)
public void testHibernateCaching() {
EntityBinding binding = getEntityBinding( HibernateCacheEntity.class );
assertNotNull( "There should be a cache binding", binding.getCaching() );
Caching caching = binding.getCaching();
assertNotNull( "There should be a cache binding", binding.getHierarchyDetails().getCaching() );
Caching caching = binding.getHierarchyDetails().getCaching();
assertEquals( "Wrong region", "foo", caching.getRegion() );
assertEquals( "Wrong strategy", AccessType.READ_WRITE, caching.getAccessType() );
assertEquals( "Wrong lazy properties configuration", false, caching.isCacheLazyProperties() );
@ -61,8 +61,8 @@ public class CacheBindingTests extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = JpaCacheEntity.class, cacheMode = SharedCacheMode.ALL)
public void testJpaCaching() {
EntityBinding binding = getEntityBinding( JpaCacheEntity.class );
assertNotNull( "There should be a cache binding", binding.getCaching() );
Caching caching = binding.getCaching();
assertNotNull( "There should be a cache binding", binding.getHierarchyDetails().getCaching() );
Caching caching = binding.getHierarchyDetails().getCaching();
assertEquals(
"Wrong region",
this.getClass().getName() + "$" + JpaCacheEntity.class.getSimpleName(),
@ -75,7 +75,7 @@ public class CacheBindingTests extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = NoCacheEntity.class, cacheMode = SharedCacheMode.NONE)
public void testNoCaching() {
EntityBinding binding = getEntityBinding( NoCacheEntity.class );
assertNull( "There should be no cache binding", binding.getCaching() );
assertNull( "There should be no cache binding", binding.getHierarchyDetails().getCaching() );
}
@Entity

View File

@ -26,7 +26,7 @@ public class EmbeddedIdTests extends BaseAnnotationBindingTestCase {
// @Resources(annotatedClasses = { User.class, Address.class })
public void testEmbeddable() {
EntityBinding binding = getEntityBinding( User.class );
EntityIdentifier identifier = binding.getEntityIdentifier();
EntityIdentifier identifier = binding.getHierarchyDetails().getEntityIdentifier();
assertTrue( identifier.isEmbedded() );
}

View File

@ -46,7 +46,7 @@ public class InheritanceBindingTest extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = SingleEntity.class)
public void testNoInheritance() {
EntityBinding entityBinding = getEntityBinding( SingleEntity.class );
assertNull( entityBinding.getEntityDiscriminator() );
assertNull( entityBinding.getHierarchyDetails().getEntityDiscriminator() );
}
@Test

View File

@ -56,7 +56,7 @@ public class TableNameTest extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = { A.class, B.class })
public void testSingleInheritanceDefaultTableName() {
EntityBinding binding = getEntityBinding( A.class );
assertEquals( "wrong inheritance type", InheritanceType.SINGLE_TABLE, binding.getInheritanceType() );
assertEquals( "wrong inheritance type", InheritanceType.SINGLE_TABLE, binding.getHierarchyDetails().getInheritanceType() );
assertEquals(
"wrong table name",
"TableNameTest$A",
@ -64,7 +64,7 @@ public class TableNameTest extends BaseAnnotationBindingTestCase {
);
binding = getEntityBinding( B.class );
assertEquals( "wrong inheritance type", InheritanceType.SINGLE_TABLE, binding.getInheritanceType() );
assertEquals( "wrong inheritance type", InheritanceType.SINGLE_TABLE, binding.getHierarchyDetails().getInheritanceType() );
assertEquals(
"wrong table name",
"TableNameTest$A",
@ -89,7 +89,7 @@ public class TableNameTest extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = { JoinedA.class, JoinedB.class })
public void testJoinedSubclassDefaultTableName() {
EntityBinding binding = getEntityBinding( JoinedA.class );
assertEquals( "wrong inheritance type", InheritanceType.JOINED, binding.getInheritanceType() );
assertEquals( "wrong inheritance type", InheritanceType.JOINED, binding.getHierarchyDetails().getInheritanceType() );
assertEquals(
"wrong table name",
"FOO",
@ -97,7 +97,7 @@ public class TableNameTest extends BaseAnnotationBindingTestCase {
);
binding = getEntityBinding( JoinedB.class );
assertEquals( "wrong inheritance type", InheritanceType.JOINED, binding.getInheritanceType() );
assertEquals( "wrong inheritance type", InheritanceType.JOINED, binding.getHierarchyDetails().getInheritanceType() );
assertEquals(
"wrong table name",
"TableNameTest$JoinedB",
@ -122,7 +122,7 @@ public class TableNameTest extends BaseAnnotationBindingTestCase {
@Resources(annotatedClasses = { TablePerClassA.class, TablePerClassB.class })
public void testTablePerClassDefaultTableName() {
EntityBinding binding = getEntityBinding( TablePerClassA.class );
assertEquals( "wrong inheritance type", InheritanceType.TABLE_PER_CLASS, binding.getInheritanceType() );
assertEquals( "wrong inheritance type", InheritanceType.TABLE_PER_CLASS, binding.getHierarchyDetails().getInheritanceType() );
assertEquals(
"wrong table name",
"TableNameTest$TablePerClassA",
@ -130,7 +130,7 @@ public class TableNameTest extends BaseAnnotationBindingTestCase {
);
binding = getEntityBinding( TablePerClassB.class );
assertEquals( "wrong inheritance type", InheritanceType.TABLE_PER_CLASS, binding.getInheritanceType() );
assertEquals( "wrong inheritance type", InheritanceType.TABLE_PER_CLASS, binding.getHierarchyDetails().getInheritanceType() );
assertEquals(
"wrong table name",
"TableNameTest$TablePerClassB",