HHH-6217 : Create EntityBindingState and implement for HBM XML
This commit is contained in:
parent
c93ce70f9d
commit
6d52bcff6b
|
@ -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<String> 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;
|
||||
}
|
||||
|
|
|
@ -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<String> getSynchronizedTableNames();
|
||||
}
|
|
@ -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 );
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> 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<String>( 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<String> getSynchronizedTableNames() {
|
||||
return synchronizedTableNames;
|
||||
}
|
||||
}
|
|
@ -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 );
|
||||
|
||||
|
|
Loading…
Reference in New Issue