From 6d52bcff6b544e6685f97dcb9859bb39a986601a Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 8 Jun 2011 02:20:43 -0700 Subject: [PATCH] HHH-6217 : Create EntityBindingState and implement for HBM XML --- .../metamodel/binding/EntityBinding.java | 126 ++------ .../binding/state/EntityBindingState.java | 78 +++++ .../annotations/entity/EntityBinder.java | 3 +- .../source/hbm/AbstractEntityBinder.java | 38 +-- .../source/hbm/RootEntityBinder.java | 41 +-- .../state/binding/HbmEntityBindingState.java | 301 ++++++++++++++++++ .../binding/SimpleValueBindingTests.java | 3 +- 7 files changed, 436 insertions(+), 154 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/EntityBindingState.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java index 9cf6599423..c004f5aebf 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java @@ -32,19 +32,10 @@ import java.util.Set; import org.hibernate.AssertionFailure; import org.hibernate.MappingException; -import org.hibernate.engine.internal.Versioning; -import org.hibernate.internal.util.ReflectHelper; +import org.hibernate.metamodel.binding.state.EntityBindingState; import org.hibernate.metamodel.domain.Entity; import org.hibernate.metamodel.relational.Column; import org.hibernate.metamodel.relational.TableSpecification; -import org.hibernate.metamodel.source.hbm.HbmBindingContext; -import org.hibernate.metamodel.source.hbm.HbmHelper; -import org.hibernate.metamodel.source.hbm.util.MappingHelper; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement; import org.hibernate.metamodel.source.spi.MetaAttributeContext; /** @@ -56,7 +47,8 @@ import org.hibernate.metamodel.source.spi.MetaAttributeContext; */ public class EntityBinding { private final EntityIdentifier entityIdentifier = new EntityIdentifier( this ); - private final boolean isRoot; + + private boolean isRoot; private InheritanceType entityInheritanceType; private EntityDiscriminator entityDiscriminator; @@ -96,97 +88,43 @@ public class EntityBinding { private List synchronizedTableNames; - public EntityBinding(boolean isRoot) { - this.isRoot = isRoot; - } - - // TODO: change to intialize from Doimain - public void fromHbmXml(HbmBindingContext bindingContext, XMLClass entityClazz, Entity entity) { - this.entity = entity; - metaAttributeContext = HbmHelper.extractMetaAttributeContext( entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext() ); - - // go ahead and set the lazy here, since pojo.proxy can override it. - lazy = MappingHelper.getBooleanValue( - entityClazz.isLazy(), bindingContext.getMappingDefaults().isDefaultLazy() - ); - proxyInterfaceName = entityClazz.getProxy(); - dynamicUpdate = entityClazz.isDynamicUpdate(); - dynamicInsert = entityClazz.isDynamicInsert(); - batchSize = MappingHelper.getIntValue( entityClazz.getBatchSize(), 0 ); - selectBeforeUpdate = entityClazz.isSelectBeforeUpdate(); - - // OPTIMISTIC LOCK MODE - String optimisticLockModeString = MappingHelper.getStringValue( entityClazz.getOptimisticLock(), "version" ); - if ( "version".equals( optimisticLockModeString ) ) { - optimisticLockMode = Versioning.OPTIMISTIC_LOCK_VERSION; - } - else if ( "dirty".equals( optimisticLockModeString ) ) { - optimisticLockMode = Versioning.OPTIMISTIC_LOCK_DIRTY; - } - else if ( "all".equals( optimisticLockModeString ) ) { - optimisticLockMode = Versioning.OPTIMISTIC_LOCK_ALL; - } - else if ( "none".equals( optimisticLockModeString ) ) { - optimisticLockMode = Versioning.OPTIMISTIC_LOCK_NONE; - } - else { - throw new MappingException( "Unsupported optimistic-lock style: " + optimisticLockModeString ); - } - - // PERSISTER - if ( entityClazz.getPersister() != null ) { - try { - entityPersisterClass = ReflectHelper.classForName( entityClazz.getPersister() ); - } - catch ( ClassNotFoundException cnfe ) { - throw new MappingException( - "Could not find persister class: " - + entityClazz.getPersister() - ); + public EntityBinding initialize(EntityBindingState state) { + this.isRoot = state.isRoot(); + this.entityInheritanceType = state.getEntityInheritanceType(); + this.caching = state.getCaching(); + this.metaAttributeContext = state.getMetaAttributeContext(); + this.proxyInterfaceName = state.getProxyInterfaceName(); + this.lazy = state.isLazy(); + this.mutable = state.isMutable(); + this.explicitPolymorphism = state.isExplicitPolymorphism(); + this.whereFilter = state.getWhereFilter(); + this.rowId = state.getRowId(); + this.dynamicInsert = state.isDynamicUpdate(); + this.dynamicInsert = state.isDynamicInsert(); + this.batchSize = state.getBatchSize(); + this.selectBeforeUpdate = state.isSelectBeforeUpdate(); + this.optimisticLockMode = state.getOptimisticLockMode(); + this.entityPersisterClass = state.getEntityPersisterClass(); + this.isAbstract = state.isAbstract(); + this.customInsert = state.getCustomInsert(); + this.customUpdate = state.getCustomUpdate(); + this.customDelete = state.getCustomDelete(); + if ( state.getSynchronizedTableNames() != null ) { + for ( String synchronizedTableName : state.getSynchronizedTableNames() ) { + addSynchronizedTable( synchronizedTableName ); } } - - // CUSTOM SQL - XMLSqlInsertElement sqlInsert = entityClazz.getSqlInsert(); - if ( sqlInsert != null ) { - customInsert = HbmHelper.getCustomSql( - sqlInsert.getValue(), - sqlInsert.isCallable(), - sqlInsert.getCheck().value() - ); - } - - XMLSqlDeleteElement sqlDelete = entityClazz.getSqlDelete(); - if ( sqlDelete != null ) { - customDelete = HbmHelper.getCustomSql( - sqlDelete.getValue(), - sqlDelete.isCallable(), - sqlDelete.getCheck().value() - ); - } - - XMLSqlUpdateElement sqlUpdate = entityClazz.getSqlUpdate(); - if ( sqlUpdate != null ) { - customUpdate = HbmHelper.getCustomSql( - sqlUpdate.getValue(), - sqlUpdate.isCallable(), - sqlUpdate.getCheck().value() - ); - } - - if ( entityClazz.getSynchronize() != null ) { - for ( XMLSynchronizeElement synchronize : entityClazz.getSynchronize() ) { - addSynchronizedTable( synchronize.getTable() ); - } - } - - isAbstract = entityClazz.isAbstract(); + return this; } public boolean isRoot() { return isRoot; } + public void setRoot(boolean isRoot) { + this.isRoot = isRoot; + } + public Entity getEntity() { return entity; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/EntityBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/EntityBindingState.java new file mode 100644 index 0000000000..0d5eb36893 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/state/EntityBindingState.java @@ -0,0 +1,78 @@ +/* + * 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.state; + +import java.util.List; + +import org.hibernate.metamodel.binding.Caching; +import org.hibernate.metamodel.binding.CustomSQL; +import org.hibernate.metamodel.binding.InheritanceType; +import org.hibernate.metamodel.source.spi.MetaAttributeContext; + +/** + * @author Gail Badner + */ +public interface EntityBindingState { + boolean isRoot(); + + InheritanceType getEntityInheritanceType(); + + Caching getCaching(); + + MetaAttributeContext getMetaAttributeContext(); + + String getProxyInterfaceName(); + + boolean isLazy(); + + boolean isMutable(); + + boolean isExplicitPolymorphism(); + + String getWhereFilter(); + + String getRowId(); + + boolean isDynamicUpdate(); + + boolean isDynamicInsert(); + + int getBatchSize(); + + boolean isSelectBeforeUpdate(); + + int getOptimisticLockMode(); + + Class getEntityPersisterClass(); + + Boolean isAbstract(); + + CustomSQL getCustomInsert(); + + CustomSQL getCustomUpdate(); + + CustomSQL getCustomDelete(); + + List getSynchronizedTableNames(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java index 2bbc4833f2..5f64c10f6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java @@ -85,7 +85,7 @@ public class EntityBinder { } public void bind() { - EntityBinding entityBinding = new EntityBinding( configuredClass.isRoot() ); + EntityBinding entityBinding = new EntityBinding(); bindJpaEntityAnnotation( entityBinding ); bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity @@ -300,6 +300,7 @@ public class EntityBinder { } private void bindId(EntityBinding entityBinding) { + entityBinding.setRoot( true ); switch ( configuredClass.getIdType() ) { case SIMPLE: { bindSingleIdAnnotation( entityBinding ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java index dcae799058..b20b4b4d09 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java @@ -35,6 +35,7 @@ import org.hibernate.metamodel.binding.AttributeBinding; import org.hibernate.metamodel.binding.BagBinding; import org.hibernate.metamodel.binding.CollectionElementType; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.InheritanceType; import org.hibernate.metamodel.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.binding.SimpleAttributeBinding; import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState; @@ -45,6 +46,7 @@ import org.hibernate.metamodel.relational.Table; import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.relational.UniqueKey; import org.hibernate.metamodel.relational.state.ManyToOneRelationalState; +import org.hibernate.metamodel.source.hbm.state.binding.HbmEntityBindingState; import org.hibernate.metamodel.source.hbm.state.binding.HbmManyToOneAttributeBindingState; import org.hibernate.metamodel.source.hbm.state.binding.HbmPluralAttributeBindingState; import org.hibernate.metamodel.source.hbm.state.binding.HbmSimpleAttributeBindingState; @@ -100,6 +102,12 @@ abstract class AbstractEntityBinder { ); } + public boolean isRoot() { + return false; + } + + public abstract InheritanceType getInheritanceType(); + public HbmBindingContext getBindingContext() { return bindingContext; } @@ -120,11 +128,9 @@ abstract class AbstractEntityBinder { XMLHibernateMapping.XMLClass entityClazz, EntityBinding entityBinding, Hierarchical superType) { - entityBinding.fromHbmXml( - bindingContext, - entityClazz, - new Entity( bindingContext.extractEntityName( entityClazz ), superType ) - ); + entityBinding.setEntity( new Entity( bindingContext.extractEntityName( entityClazz ), superType ) ); + entityBinding.initialize( new HbmEntityBindingState( isRoot(), getInheritanceType(), bindingContext, entityClazz ) ); + // TODO: move this stuff out // transfer an explicitly defined lazy attribute bindPojoRepresentation( entityClazz, entityBinding ); @@ -210,28 +216,6 @@ abstract class AbstractEntityBinder { return null; } - int getOptimisticLockMode(Attribute olAtt) throws MappingException { - if ( olAtt == null ) { - return Versioning.OPTIMISTIC_LOCK_VERSION; - } - String olMode = olAtt.getValue(); - if ( olMode == null || "version".equals( olMode ) ) { - return Versioning.OPTIMISTIC_LOCK_VERSION; - } - else if ( "dirty".equals( olMode ) ) { - return Versioning.OPTIMISTIC_LOCK_DIRTY; - } - else if ( "all".equals( olMode ) ) { - return Versioning.OPTIMISTIC_LOCK_ALL; - } - else if ( "none".equals( olMode ) ) { - return Versioning.OPTIMISTIC_LOCK_NONE; - } - else { - throw new MappingException( "Unsupported optimistic-lock style: " + olMode ); - } - } - protected String getClassTableName( XMLHibernateMapping.XMLClass entityClazz, EntityBinding entityBinding, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java index 46759597d3..c61710da96 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/RootEntityBinder.java @@ -25,9 +25,8 @@ package org.hibernate.metamodel.source.hbm; import org.hibernate.InvalidMappingException; import org.hibernate.MappingException; -import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.metamodel.binding.Caching; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.InheritanceType; import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState; import org.hibernate.metamodel.relational.Identifier; import org.hibernate.metamodel.relational.InLineView; @@ -36,7 +35,6 @@ import org.hibernate.metamodel.relational.state.ValueRelationalState; import org.hibernate.metamodel.source.hbm.state.binding.HbmDiscriminatorBindingState; import org.hibernate.metamodel.source.hbm.state.binding.HbmSimpleAttributeBindingState; import org.hibernate.metamodel.source.hbm.state.relational.HbmSimpleValueRelationalStateContainer; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLCacheElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLCompositeId; @@ -54,34 +52,27 @@ class RootEntityBinder extends AbstractEntityBinder { super( bindingContext, xmlClazz ); } + public boolean isRoot() { + return true; + } + + public InheritanceType getInheritanceType() { + return InheritanceType.SINGLE_TABLE; + } + public void process(XMLClass xmlClazz) { String entityName = getBindingContext().extractEntityName( xmlClazz ); if ( entityName == null ) { throw new MappingException( "Unable to determine entity name" ); } - EntityBinding entityBinding = new EntityBinding( true ); + EntityBinding entityBinding = new EntityBinding(); basicEntityBinding( xmlClazz, entityBinding, null ); basicTableBinding( xmlClazz, entityBinding ); - entityBinding.setMutable( xmlClazz.isMutable() ); - - if ( xmlClazz.getWhere() != null ) { - entityBinding.setWhereFilter( xmlClazz.getWhere() ); - } - - if ( xmlClazz.getPolymorphism() != null ) { - entityBinding.setExplicitPolymorphism( "explicit".equals( xmlClazz.getPolymorphism() ) ); - } - - if ( xmlClazz.getRowid() != null ) { - entityBinding.setRowId( xmlClazz.getRowid() ); - } - bindIdentifier( xmlClazz, entityBinding ); bindDiscriminator( xmlClazz, entityBinding ); bindVersionOrTimestamp( xmlClazz, entityBinding ); - bindCaching( xmlClazz, entityBinding ); // called createClassProperties in HBMBinder... buildAttributeBindings( xmlClazz, entityBinding ); @@ -335,16 +326,4 @@ class RootEntityBinder extends AbstractEntityBinder { .initialize( bindingState ) .initialize( relationalState ); } - - private void bindCaching(XMLClass xmlClazz, - EntityBinding entityBinding) { - XMLCacheElement cache = xmlClazz.getCache(); - if ( cache == null ) { - return; - } - final String region = cache.getRegion() != null ? cache.getRegion() : entityBinding.getEntity().getName(); - final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() ); - final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() ); - entityBinding.setCaching( new Caching( region, accessType, cacheLazyProps ) ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java new file mode 100644 index 0000000000..cac132dd6a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmEntityBindingState.java @@ -0,0 +1,301 @@ +/* + * 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.source.hbm.state.binding; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.MappingException; +import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.engine.internal.Versioning; +import org.hibernate.metamodel.binding.Caching; +import org.hibernate.metamodel.binding.CustomSQL; +import org.hibernate.metamodel.binding.InheritanceType; +import org.hibernate.metamodel.binding.state.EntityBindingState; +import org.hibernate.metamodel.source.hbm.HbmBindingContext; +import org.hibernate.metamodel.source.hbm.HbmHelper; +import org.hibernate.metamodel.source.hbm.util.MappingHelper; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLCacheElement; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement; +import org.hibernate.metamodel.source.spi.MetaAttributeContext; + +/** + * @author Gail Badner + */ +public class HbmEntityBindingState implements EntityBindingState { + private final boolean isRoot; + private final InheritanceType entityInheritanceType; + private final Caching caching; + private final MetaAttributeContext metaAttributeContext; + private final String proxyInterfaceName; + + private final boolean lazy; + private final boolean mutable; + private final boolean explicitPolymorphism; + private final String whereFilter; + private final String rowId; + + private final boolean dynamicUpdate; + private final boolean dynamicInsert; + + private final int batchSize; + private final boolean selectBeforeUpdate; + private final int optimisticLockMode; + + private final Class entityPersisterClass; + private final Boolean isAbstract; + + private final CustomSQL customInsert; + private final CustomSQL customUpdate; + private final CustomSQL customDelete; + + private final List synchronizedTableNames; + + public HbmEntityBindingState( + boolean isRoot, + InheritanceType inheritanceType, + HbmBindingContext bindingContext, + XMLHibernateMapping.XMLClass entityClazz) { + this.isRoot = isRoot; + this.entityInheritanceType = inheritanceType; + + this.caching = createCaching( entityClazz, bindingContext.extractEntityName( entityClazz ) ); + + metaAttributeContext = HbmHelper.extractMetaAttributeContext( + entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext() + ); + + // go ahead and set the lazy here, since pojo.proxy can override it. + lazy = MappingHelper.getBooleanValue( + entityClazz.isLazy(), bindingContext.getMappingDefaults().isDefaultLazy() + ); + mutable = entityClazz.isMutable(); + + explicitPolymorphism = "explicit".equals( entityClazz.getPolymorphism() ); + whereFilter = entityClazz.getWhere(); + rowId = entityClazz.getRowid(); + proxyInterfaceName = entityClazz.getProxy(); + dynamicUpdate = entityClazz.isDynamicUpdate(); + dynamicInsert = entityClazz.isDynamicInsert(); + batchSize = MappingHelper.getIntValue( entityClazz.getBatchSize(), 0 ); + selectBeforeUpdate = entityClazz.isSelectBeforeUpdate(); + optimisticLockMode = getOptimisticLockMode(); + + // PERSISTER + entityPersisterClass = + entityClazz.getPersister() == null ? + null : + MappingHelper.classForName( entityClazz.getPersister(), bindingContext.getServiceRegistry() ); + + // CUSTOM SQL + XMLSqlInsertElement sqlInsert = entityClazz.getSqlInsert(); + if ( sqlInsert != null ) { + customInsert = HbmHelper.getCustomSql( + sqlInsert.getValue(), + sqlInsert.isCallable(), + sqlInsert.getCheck().value() + ); + } + else { + customInsert = null; + } + + XMLSqlDeleteElement sqlDelete = entityClazz.getSqlDelete(); + if ( sqlDelete != null ) { + customDelete = HbmHelper.getCustomSql( + sqlDelete.getValue(), + sqlDelete.isCallable(), + sqlDelete.getCheck().value() + ); + } + else { + customDelete = null; + } + + XMLSqlUpdateElement sqlUpdate = entityClazz.getSqlUpdate(); + if ( sqlUpdate != null ) { + customUpdate = HbmHelper.getCustomSql( + sqlUpdate.getValue(), + sqlUpdate.isCallable(), + sqlUpdate.getCheck().value() + ); + } + else { + customUpdate = null; + } + + if ( entityClazz.getSynchronize() != null ) { + synchronizedTableNames = new ArrayList( entityClazz.getSynchronize().size() ); + for ( XMLSynchronizeElement synchronize : entityClazz.getSynchronize() ) { + synchronizedTableNames.add( synchronize.getTable() ); + } + } + else { + synchronizedTableNames = null; + } + isAbstract = entityClazz.isAbstract(); + } + + private static Caching createCaching(XMLHibernateMapping.XMLClass entityClazz, String entityName) { + XMLCacheElement cache = entityClazz.getCache(); + if ( cache == null ) { + return null; + } + final String region = cache.getRegion() != null ? cache.getRegion() : entityName; + final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() ); + final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() ); + return new Caching( region, accessType, cacheLazyProps ); + } + + private static int createOptimisticLockMode(XMLHibernateMapping.XMLClass entityClazz) { + String optimisticLockModeString = MappingHelper.getStringValue( entityClazz.getOptimisticLock(), "version" ); + int optimisticLockMode; + if ( "version".equals( optimisticLockModeString ) ) { + optimisticLockMode = Versioning.OPTIMISTIC_LOCK_VERSION; + } + else if ( "dirty".equals( optimisticLockModeString ) ) { + optimisticLockMode = Versioning.OPTIMISTIC_LOCK_DIRTY; + } + else if ( "all".equals( optimisticLockModeString ) ) { + optimisticLockMode = Versioning.OPTIMISTIC_LOCK_ALL; + } + else if ( "none".equals( optimisticLockModeString ) ) { + optimisticLockMode = Versioning.OPTIMISTIC_LOCK_NONE; + } + else { + throw new MappingException( "Unsupported optimistic-lock style: " + optimisticLockModeString ); + } + return optimisticLockMode; + } + + @Override + public boolean isRoot() { + return isRoot; + + } + + @Override + public InheritanceType getEntityInheritanceType() { + return entityInheritanceType; + } + + @Override + public Caching getCaching() { + return caching; + } + + @Override + public MetaAttributeContext getMetaAttributeContext() { + return metaAttributeContext; + } + + @Override + public String getProxyInterfaceName() { + return proxyInterfaceName; + } + + @Override + public boolean isLazy() { + return lazy; + } + + @Override + public boolean isMutable() { + return mutable; + } + + @Override + public boolean isExplicitPolymorphism() { + return explicitPolymorphism; + } + + @Override + public String getWhereFilter() { + return whereFilter; + } + + @Override + public String getRowId() { + return rowId; + } + + @Override + public boolean isDynamicUpdate() { + return dynamicUpdate; + } + + @Override + public boolean isDynamicInsert() { + return dynamicInsert; + } + + @Override + public int getBatchSize() { + return batchSize; + } + + @Override + public boolean isSelectBeforeUpdate() { + return selectBeforeUpdate; + } + + @Override + public int getOptimisticLockMode() { + return optimisticLockMode; + } + + @Override + public Class getEntityPersisterClass() { + return entityPersisterClass; + } + + @Override + public Boolean isAbstract() { + return isAbstract; + } + + @Override + public CustomSQL getCustomInsert() { + return customInsert; + } + + @Override + public CustomSQL getCustomUpdate() { + return customUpdate; + } + + @Override + public CustomSQL getCustomDelete() { + return customDelete; + } + + @Override + public List getSynchronizedTableNames() { + return synchronizedTableNames; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java index 2160653407..e16f66ab75 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java @@ -52,7 +52,8 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { public void testBasicMiddleOutBuilding() { Table table = new Table( new Schema( null, null ), "the_table" ); Entity entity = new Entity( "TheEntity", null ); - EntityBinding entityBinding = new EntityBinding( true ); + EntityBinding entityBinding = new EntityBinding(); + entityBinding.setRoot( true ); entityBinding.setEntity( entity ); entityBinding.setBaseTable( table );