HHH-6232 : Add discriminator value to DiscriminatorBindingState
This commit is contained in:
parent
792c85a053
commit
5df5883e31
|
@ -52,6 +52,7 @@ import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class EntityBinding {
|
||||
private final EntityIdentifier entityIdentifier = new EntityIdentifier( this );
|
||||
|
@ -76,7 +77,6 @@ public class EntityBinding {
|
|||
private String whereFilter;
|
||||
private String rowId;
|
||||
|
||||
private String discriminatorValue;
|
||||
private boolean dynamicUpdate;
|
||||
private boolean dynamicInsert;
|
||||
|
||||
|
@ -102,7 +102,6 @@ public class EntityBinding {
|
|||
// go ahead and set the lazy here, since pojo.proxy can override it.
|
||||
lazy = MappingHelper.getBooleanValue( entityClazz.isLazy(), defaults.isDefaultLazy() );
|
||||
proxyInterfaceName = entityClazz.getProxy();
|
||||
discriminatorValue = MappingHelper.getStringValue( entityClazz.getDiscriminatorValue(), entity.getName() );
|
||||
dynamicUpdate = entityClazz.isDynamicUpdate();
|
||||
dynamicInsert = entityClazz.isDynamicInsert();
|
||||
batchSize = MappingHelper.getIntValue( entityClazz.getBatchSize(), 0 );
|
||||
|
@ -353,11 +352,7 @@ public class EntityBinding {
|
|||
}
|
||||
|
||||
public String getDiscriminatorValue() {
|
||||
return discriminatorValue;
|
||||
}
|
||||
|
||||
public void setDiscriminatorValue(String discriminatorValue) {
|
||||
this.discriminatorValue = discriminatorValue;
|
||||
return entityDiscriminator == null ? null : entityDiscriminator.getDiscriminatorValue();
|
||||
}
|
||||
|
||||
public boolean isDynamicUpdate() {
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
|||
*/
|
||||
public class EntityDiscriminator {
|
||||
private SimpleAttributeBinding valueBinding;
|
||||
private String discriminatorValue;
|
||||
private boolean forced;
|
||||
private boolean inserted = true;
|
||||
|
||||
|
@ -53,8 +54,9 @@ public class EntityDiscriminator {
|
|||
throw new IllegalStateException( "Cannot bind state because the value binding has not been initialized." );
|
||||
}
|
||||
this.valueBinding.initialize( state );
|
||||
this.discriminatorValue = state.getDiscriminatorValue();
|
||||
this.forced = state.isForced();
|
||||
this.inserted = state.isInsertable();
|
||||
this.inserted = state.isInserted();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,10 @@ public class EntityDiscriminator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public String getDiscriminatorValue() {
|
||||
return discriminatorValue;
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return forced;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ package org.hibernate.metamodel.binding.state;
|
|||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface DiscriminatorBindingState extends SimpleAttributeBindingState {
|
||||
public interface DiscriminatorBindingState extends AttributeBindingState {
|
||||
String getDiscriminatorValue();
|
||||
boolean isForced();
|
||||
boolean isInserted();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.hibernate.cache.spi.RegionFactory;
|
|||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityDiscriminator;
|
||||
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
|
||||
|
@ -135,10 +136,6 @@ public class EntityBinder {
|
|||
if ( !( discriminatorAttribute.getColumnValues() instanceof DiscriminatorColumnValues ) ) {
|
||||
throw new AssertionFailure( "Expected discriminator column values" );
|
||||
}
|
||||
|
||||
// TODO: move this into DiscriminatorBindingState
|
||||
DiscriminatorColumnValues discriminatorColumnvalues = (DiscriminatorColumnValues) discriminatorAttribute.getColumnValues();
|
||||
entityBinding.setDiscriminatorValue( discriminatorColumnvalues.getDiscriminatorValue() );
|
||||
}
|
||||
|
||||
private void bindWhereFilter(EntityBinding entityBinding) {
|
||||
|
@ -391,21 +388,20 @@ public class EntityBinder {
|
|||
String attributeName = simpleAttribute.getName();
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName );
|
||||
SimpleAttributeBinding attributeBinding;
|
||||
SimpleAttributeBindingState bindingState;
|
||||
|
||||
if ( simpleAttribute.isDiscriminator() ) {
|
||||
attributeBinding = entityBinding.makeEntityDiscriminator( attributeName ).getValueBinding();
|
||||
bindingState = new DiscriminatorBindingStateImpl( simpleAttribute );
|
||||
EntityDiscriminator entityDiscriminator = entityBinding.makeEntityDiscriminator( attributeName );
|
||||
entityDiscriminator.initialize( new DiscriminatorBindingStateImpl( simpleAttribute ) );
|
||||
attributeBinding = entityDiscriminator.getValueBinding();
|
||||
}
|
||||
else if ( simpleAttribute.isVersioned() ) {
|
||||
attributeBinding = entityBinding.makeVersionBinding( attributeName );
|
||||
bindingState = new AttributeBindingStateImpl( simpleAttribute );
|
||||
attributeBinding.initialize( new AttributeBindingStateImpl( simpleAttribute ) );
|
||||
}
|
||||
else {
|
||||
attributeBinding = entityBinding.makeSimpleAttributeBinding( attributeName );
|
||||
bindingState = new AttributeBindingStateImpl( simpleAttribute );
|
||||
attributeBinding.initialize( new AttributeBindingStateImpl( simpleAttribute ) );
|
||||
}
|
||||
attributeBinding.initialize( bindingState );
|
||||
|
||||
if ( configuredClass.hasOwnTable() ) {
|
||||
ColumnRelationalStateImpl columnRelationsState = new ColumnRelationalStateImpl(
|
||||
|
|
|
@ -33,23 +33,30 @@ import org.hibernate.metamodel.source.annotations.entity.SimpleAttribute;
|
|||
*/
|
||||
public class DiscriminatorBindingStateImpl
|
||||
extends AttributeBindingStateImpl implements org.hibernate.metamodel.binding.state.DiscriminatorBindingState {
|
||||
private final String discriminatorValue;
|
||||
private final boolean isForced;
|
||||
private final boolean isInserted;
|
||||
|
||||
public DiscriminatorBindingStateImpl(SimpleAttribute mappedAttribute) {
|
||||
super( mappedAttribute );
|
||||
DiscriminatorColumnValues columnValues = DiscriminatorColumnValues.class.cast( mappedAttribute.getColumnValues() );
|
||||
discriminatorValue = columnValues.getDiscriminatorValue();
|
||||
isForced = columnValues.isForced();
|
||||
isInserted = columnValues.isIncludedInSql();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDiscriminatorValue() {
|
||||
return discriminatorValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForced() {
|
||||
return isForced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
public boolean isInserted() {
|
||||
return isInserted;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ 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.state.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.relational.Identifier;
|
||||
import org.hibernate.metamodel.relational.InLineView;
|
||||
|
@ -42,6 +41,7 @@ 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;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
||||
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
|
@ -245,9 +245,10 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
}
|
||||
|
||||
DiscriminatorBindingState bindingState = new HbmDiscriminatorBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
xmlEntityClazz.getDiscriminator()
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
entityBinding.getEntity().getName(),
|
||||
getHibernateMappingBinder(),
|
||||
xmlEntityClazz
|
||||
);
|
||||
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.util.Set;
|
|||
import org.hibernate.metamodel.binding.CascadeType;
|
||||
import org.hibernate.metamodel.source.hbm.MappingDefaults;
|
||||
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
|
||||
|
||||
/**
|
||||
|
@ -36,17 +38,28 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLCla
|
|||
public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingState
|
||||
implements DiscriminatorBindingState {
|
||||
private final XMLDiscriminator discriminator;
|
||||
private final String discriminatorValue;
|
||||
private final boolean isForced;
|
||||
private final boolean isInserted;
|
||||
private final String typeName;
|
||||
|
||||
public HbmDiscriminatorBindingState(
|
||||
String entityName,
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
XMLDiscriminator discriminator) {
|
||||
XMLHibernateMapping.XMLClass xmlEntityClazz) {
|
||||
// Discriminator.getName() is not defined, so the attribute will always be
|
||||
// defaults.getDefaultDescriminatorColumnName()
|
||||
super(
|
||||
ownerClassName, defaults.getDefaultDiscriminatorColumnName(), defaults, null, null, null, true
|
||||
);
|
||||
this.discriminator = discriminator;
|
||||
this.discriminatorValue = MappingHelper.getStringValue(
|
||||
xmlEntityClazz.getDiscriminatorValue(), entityName
|
||||
);
|
||||
this.discriminator = xmlEntityClazz.getDiscriminator();
|
||||
this.isForced = xmlEntityClazz.getDiscriminator().isForce();
|
||||
this.isInserted = discriminator.isInsert();
|
||||
this.typeName = discriminator.getType() == null ? "string" : discriminator.getType();
|
||||
}
|
||||
|
||||
public Set<CascadeType> getCascadeTypes() {
|
||||
|
@ -58,9 +71,10 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
|
|||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return discriminator.getType() == null ? "string" : discriminator.getType();
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLazy() {
|
||||
return false;
|
||||
}
|
||||
|
@ -69,11 +83,18 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
|
|||
return discriminator.isInsert();
|
||||
}
|
||||
|
||||
public boolean isUpdatable() {
|
||||
return false;
|
||||
@Override
|
||||
public boolean isInserted() {
|
||||
return isInserted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDiscriminatorValue() {
|
||||
return discriminatorValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForced() {
|
||||
return discriminator.isForce();
|
||||
return isForced;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue