HHH-6447 Implementing EntityDiscriminator and discriminator value binding
This commit is contained in:
parent
e358ab7b5a
commit
8639904969
|
@ -64,11 +64,12 @@ public class EntityBinding {
|
|||
|
||||
private final EntityIdentifier entityIdentifier = new EntityIdentifier( this );
|
||||
private EntityDiscriminator entityDiscriminator;
|
||||
private String discriminatorValue;
|
||||
private SimpleSingularAttributeBinding versionBinding;
|
||||
|
||||
private Map<String, AttributeBinding> attributeBindingMap = new HashMap<String, AttributeBinding>();
|
||||
|
||||
private Set<FilterDefinition> filterDefinitions = new HashSet<FilterDefinition>( );
|
||||
private Set<FilterDefinition> filterDefinitions = new HashSet<FilterDefinition>();
|
||||
private Set<SingularAssociationAttributeBinding> entityReferencingAttributeBindings = new HashSet<SingularAssociationAttributeBinding>();
|
||||
|
||||
private Caching caching;
|
||||
|
@ -147,6 +148,18 @@ public class EntityBinding {
|
|||
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;
|
||||
}
|
||||
|
@ -205,32 +218,17 @@ public class EntityBinding {
|
|||
return entityReferencingAttributeBindings;
|
||||
}
|
||||
|
||||
public SimpleSingularAttributeBinding makeSimpleIdAttributeBinding(SingularAttribute attribute) {
|
||||
final SimpleSingularAttributeBinding binding = makeSimpleAttributeBinding( attribute, true, true );
|
||||
getEntityIdentifier().setValueBinding( binding );
|
||||
return binding;
|
||||
}
|
||||
//
|
||||
// public EntityDiscriminator makeEntityDiscriminator(Attribute attribute) {
|
||||
// if ( entityDiscriminator != null ) {
|
||||
// throw new AssertionFailure( "Creation of entity discriminator was called more than once" );
|
||||
// }
|
||||
// entityDiscriminator = new EntityDiscriminator();
|
||||
// entityDiscriminator.setValueBinding( makeSimpleAttributeBinding( attribute, true, false ) );
|
||||
// return entityDiscriminator;
|
||||
// }
|
||||
|
||||
public SimpleSingularAttributeBinding makeVersionBinding(SingularAttribute attribute) {
|
||||
versionBinding = makeSimpleAttributeBinding( attribute, true, false );
|
||||
return versionBinding;
|
||||
}
|
||||
|
||||
public SimpleSingularAttributeBinding makeSimpleAttributeBinding(SingularAttribute attribute) {
|
||||
return makeSimpleAttributeBinding( attribute, false, false );
|
||||
}
|
||||
|
||||
private SimpleSingularAttributeBinding makeSimpleAttributeBinding(SingularAttribute attribute, boolean forceNonNullable, boolean forceUnique) {
|
||||
final SimpleSingularAttributeBinding binding = new SimpleSingularAttributeBinding( this, attribute, forceNonNullable, forceUnique );
|
||||
final SimpleSingularAttributeBinding binding = new SimpleSingularAttributeBinding(
|
||||
this,
|
||||
attribute,
|
||||
forceNonNullable,
|
||||
forceUnique
|
||||
);
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
@ -320,10 +318,6 @@ public class EntityBinding {
|
|||
this.rowId = rowId;
|
||||
}
|
||||
|
||||
public String getDiscriminatorValue() {
|
||||
return entityDiscriminator == null ? null : entityDiscriminator.getDiscriminatorValue();
|
||||
}
|
||||
|
||||
public boolean isDynamicUpdate() {
|
||||
return dynamicUpdate;
|
||||
}
|
||||
|
@ -401,10 +395,6 @@ public class EntityBinding {
|
|||
return synchronizedTableNames;
|
||||
}
|
||||
|
||||
public void addSynchronizedTable(String tableName) {
|
||||
synchronizedTableNames.add( tableName );
|
||||
}
|
||||
|
||||
public void addSynchronizedTableNames(java.util.Collection<String> synchronizedTableNames) {
|
||||
this.synchronizedTableNames.addAll( synchronizedTableNames );
|
||||
}
|
||||
|
@ -456,4 +446,13 @@ public class EntityBinding {
|
|||
public void setCustomDelete(CustomSQL customDelete) {
|
||||
this.customDelete = customDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "EntityBinding" );
|
||||
sb.append( "{entity=" ).append( entity != null ? entity.getName() : "not set" );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,17 +23,14 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
||||
|
||||
/**
|
||||
* Binding of the discriminator in a entity hierarchy
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class EntityDiscriminator {
|
||||
private SimpleSingularAttributeBinding valueBinding;
|
||||
private String discriminatorValue;
|
||||
private boolean forced;
|
||||
private boolean inserted = true;
|
||||
|
||||
|
@ -44,30 +41,10 @@ public class EntityDiscriminator {
|
|||
return valueBinding;
|
||||
}
|
||||
|
||||
/* package-protected */
|
||||
void setValueBinding(SimpleSingularAttributeBinding valueBinding) {
|
||||
public void setValueBinding(SimpleSingularAttributeBinding valueBinding) {
|
||||
this.valueBinding = valueBinding;
|
||||
}
|
||||
|
||||
public EntityDiscriminator initialize(DiscriminatorBindingState state) {
|
||||
if ( valueBinding == null ) {
|
||||
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.isInserted();
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDiscriminatorValue() {
|
||||
return discriminatorValue;
|
||||
}
|
||||
|
||||
public void setDiscriminatorValue(String discriminatorValue) {
|
||||
this.discriminatorValue = discriminatorValue;
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return forced;
|
||||
}
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* 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.Comparator;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.metamodel.binding.CustomSQL;
|
||||
|
||||
/**
|
||||
* @author gbadner
|
||||
*/
|
||||
public interface PluralAttributeBindingState extends AttributeBindingState {
|
||||
FetchMode getFetchMode();
|
||||
|
||||
boolean isExtraLazy();
|
||||
|
||||
String getElementTypeName();
|
||||
|
||||
String getElementNodeName();
|
||||
|
||||
boolean isInverse();
|
||||
|
||||
boolean isMutable();
|
||||
|
||||
boolean isSubselectLoadable();
|
||||
|
||||
String getCacheConcurrencyStrategy();
|
||||
|
||||
String getCacheRegionName();
|
||||
|
||||
String getOrderBy();
|
||||
|
||||
String getWhere();
|
||||
|
||||
String getReferencedPropertyName();
|
||||
|
||||
boolean isSorted();
|
||||
|
||||
Comparator getComparator();
|
||||
|
||||
String getComparatorClassName();
|
||||
|
||||
boolean isOrphanDelete();
|
||||
|
||||
int getBatchSize();
|
||||
|
||||
boolean isEmbedded();
|
||||
|
||||
boolean isOptimisticLocked();
|
||||
|
||||
Class getCollectionPersisterClass();
|
||||
|
||||
java.util.Map getFilters();
|
||||
|
||||
java.util.Set getSynchronizedTables();
|
||||
|
||||
CustomSQL getCustomSQLInsert();
|
||||
|
||||
CustomSQL getCustomSQLUpdate();
|
||||
|
||||
CustomSQL getCustomSQLDelete();
|
||||
|
||||
CustomSQL getCustomSQLDeleteAll();
|
||||
|
||||
String getLoaderName();
|
||||
}
|
|
@ -374,6 +374,11 @@ public class EntityHierarchyBuilder {
|
|||
}
|
||||
|
||||
private static InheritanceType determineInheritanceType(ClassInfo rootClassInfo, List<ClassInfo> classes) {
|
||||
if(classes.size() == 1) {
|
||||
return InheritanceType.NO_INHERITANCE;
|
||||
}
|
||||
|
||||
// if we have more than one entity class the default is SINGLE_TABLE
|
||||
InheritanceType inheritanceType = InheritanceType.SINGLE_TABLE;
|
||||
AnnotationInstance inheritanceAnnotation = JandexHelper.getSingleAnnotation(
|
||||
rootClassInfo, JPADotNames.INHERITANCE
|
||||
|
|
|
@ -21,13 +21,30 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.binding.state;
|
||||
package org.hibernate.metamodel.source.annotations.attribute;
|
||||
|
||||
import org.hibernate.metamodel.source.binder.DiscriminatorSource;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public interface DiscriminatorBindingState extends AttributeBindingState {
|
||||
String getDiscriminatorValue();
|
||||
boolean isForced();
|
||||
boolean isInserted();
|
||||
public class DiscriminatorSourceImpl extends SingularAttributeSourceImpl implements DiscriminatorSource {
|
||||
private final DiscriminatorColumnValues discriminatorColumnValues;
|
||||
|
||||
public DiscriminatorSourceImpl(SimpleAttribute attribute) {
|
||||
super( attribute );
|
||||
discriminatorColumnValues = (DiscriminatorColumnValues)attribute.getColumnValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForced() {
|
||||
return discriminatorColumnValues.isForced();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInserted() {
|
||||
return discriminatorColumnValues.isIncludedInSql();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,11 +116,6 @@ public class ConfiguredClass {
|
|||
*/
|
||||
private SimpleAttribute versionAttribute;
|
||||
|
||||
/**
|
||||
* The discriminator attribute or {@code null} in case none exists.
|
||||
*/
|
||||
private SimpleAttribute discriminatorAttribute;
|
||||
|
||||
/**
|
||||
* The embedded classes for this entity
|
||||
*/
|
||||
|
@ -192,10 +187,6 @@ public class ConfiguredClass {
|
|||
return versionAttribute;
|
||||
}
|
||||
|
||||
public SimpleAttribute getDiscriminatorAttribute() {
|
||||
return discriminatorAttribute;
|
||||
}
|
||||
|
||||
public Iterable<AssociationAttribute> getAssociationAttributes() {
|
||||
return associationAttributeMap.values();
|
||||
}
|
||||
|
@ -458,11 +449,7 @@ public class ConfiguredClass {
|
|||
} else if (attribute.isVersioned()) {
|
||||
// todo - error handling in case there are multiple version attributes
|
||||
versionAttribute = attribute;
|
||||
} else if (attribute.isDiscriminator()) {
|
||||
// todo - error handling in case there are multiple discriminator attributes
|
||||
versionAttribute = attribute;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
simpleAttributeMap.put( attributeName, attribute );
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
|
|||
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JPADotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.SimpleAttribute;
|
||||
import org.hibernate.metamodel.source.binder.TableSource;
|
||||
|
||||
/**
|
||||
|
@ -87,6 +88,11 @@ public class EntityClass extends ConfiguredClass {
|
|||
private boolean isLazy;
|
||||
private String proxy;
|
||||
|
||||
/**
|
||||
* The discriminator attribute or {@code null} in case none exists.
|
||||
*/
|
||||
private SimpleAttribute discriminatorAttribute;
|
||||
|
||||
public EntityClass(
|
||||
ClassInfo classInfo,
|
||||
EntityClass parent,
|
||||
|
@ -107,14 +113,14 @@ public class EntityClass extends ConfiguredClass {
|
|||
processHibernateEntitySpecificAnnotations();
|
||||
processCustomSqlAnnotations();
|
||||
processProxyGeneration();
|
||||
|
||||
if ( InheritanceType.SINGLE_TABLE.equals( inheritanceType ) ) {
|
||||
discriminatorAttribute = SimpleAttribute.createDiscriminatorAttribute( classInfo.annotations() );
|
||||
}
|
||||
}
|
||||
|
||||
private String determineExplicitEntityName() {
|
||||
final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation(
|
||||
getClassInfo(), JPADotNames.ENTITY
|
||||
);
|
||||
|
||||
return JandexHelper.getValue( jpaEntityAnnotation, "name", String.class );
|
||||
public SimpleAttribute getDiscriminatorAttribute() {
|
||||
return discriminatorAttribute;
|
||||
}
|
||||
|
||||
public IdType getIdType() {
|
||||
|
@ -218,6 +224,15 @@ public class EntityClass extends ConfiguredClass {
|
|||
return getParent() == null;
|
||||
}
|
||||
|
||||
private String determineExplicitEntityName() {
|
||||
final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation(
|
||||
getClassInfo(), JPADotNames.ENTITY
|
||||
);
|
||||
|
||||
return JandexHelper.getValue( jpaEntityAnnotation, "name", String.class );
|
||||
}
|
||||
|
||||
|
||||
private boolean definesItsOwnTable() {
|
||||
return !InheritanceType.SINGLE_TABLE.equals( inheritanceType ) || isEntityRoot();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.hibernate.metamodel.source.Origin;
|
|||
import org.hibernate.metamodel.source.SourceType;
|
||||
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.AssociationAttribute;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.DiscriminatorColumnValues;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.SimpleAttribute;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.SingularAttributeSourceImpl;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.ToOneAttributeSourceImpl;
|
||||
|
@ -196,6 +197,12 @@ public class EntitySourceImpl implements EntitySource {
|
|||
return subclassEntitySources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDiscriminatorValue() {
|
||||
return ( (DiscriminatorColumnValues) entityClass.getDiscriminatorAttribute()
|
||||
.getColumnValues() ).getDiscriminatorValue();
|
||||
}
|
||||
|
||||
class LocalBindingContextImpl implements LocalBindingContext {
|
||||
private final AnnotationBindingContext contextDelegate;
|
||||
|
||||
|
|
|
@ -27,9 +27,11 @@ import org.hibernate.AssertionFailure;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.engine.OptimisticLockStyle;
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.DiscriminatorSourceImpl;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.SimpleAttribute;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.SimpleIdentifierSourceImpl;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.SingularAttributeSourceImpl;
|
||||
import org.hibernate.metamodel.source.binder.DiscriminatorSource;
|
||||
import org.hibernate.metamodel.source.binder.IdentifierSource;
|
||||
import org.hibernate.metamodel.source.binder.RootEntitySource;
|
||||
import org.hibernate.metamodel.source.binder.SingularAttributeSource;
|
||||
|
@ -74,10 +76,10 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public SingularAttributeSource getDiscriminatorAttributeSource() {
|
||||
SingularAttributeSource attributeSource = null;
|
||||
public DiscriminatorSource getDiscriminatorSource() {
|
||||
DiscriminatorSource attributeSource = null;
|
||||
if ( getEntityClass().getDiscriminatorAttribute() != null ) {
|
||||
attributeSource = new SingularAttributeSourceImpl( getEntityClass().getVersionAttribute() );
|
||||
attributeSource = new DiscriminatorSourceImpl( getEntityClass().getDiscriminatorAttribute() );
|
||||
}
|
||||
return attributeSource;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
|
|||
import org.hibernate.metamodel.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.binding.CollectionElementNature;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityDiscriminator;
|
||||
import org.hibernate.metamodel.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.MetaAttribute;
|
||||
|
@ -223,12 +224,20 @@ public class Binder {
|
|||
|
||||
final String customTuplizerClassName = entitySource.getCustomTuplizerClassName();
|
||||
if ( customTuplizerClassName != null ) {
|
||||
entityBinding.setCustomEntityTuplizerClass( currentBindingContext.<EntityTuplizer>locateClassByName( customTuplizerClassName ) );
|
||||
entityBinding.setCustomEntityTuplizerClass(
|
||||
currentBindingContext.<EntityTuplizer>locateClassByName(
|
||||
customTuplizerClassName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
final String customPersisterClassName = entitySource.getCustomPersisterClassName();
|
||||
if ( customPersisterClassName != null ) {
|
||||
entityBinding.setCustomEntityPersisterClass( currentBindingContext.<EntityPersister>locateClassByName( customPersisterClassName ) );
|
||||
entityBinding.setCustomEntityPersisterClass(
|
||||
currentBindingContext.<EntityPersister>locateClassByName(
|
||||
customPersisterClassName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
entityBinding.setMetaAttributeContext( buildMetaAttributeContext( entitySource ) );
|
||||
|
@ -342,11 +351,27 @@ public class Binder {
|
|||
}
|
||||
|
||||
private void bindDiscriminator(RootEntitySource entitySource, EntityBinding entityBinding) {
|
||||
// todo : implement
|
||||
final DiscriminatorSource discriminatorSource = entitySource.getDiscriminatorSource();
|
||||
if ( discriminatorSource == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleSingularAttributeBinding attributeBinding = doBasicSingularAttributeBindingCreation(
|
||||
discriminatorSource, entityBinding
|
||||
);
|
||||
EntityDiscriminator discriminator = new EntityDiscriminator();
|
||||
discriminator.setValueBinding( attributeBinding );
|
||||
discriminator.setInserted( discriminatorSource.isInserted() );
|
||||
discriminator.setForced( discriminatorSource.isForced() );
|
||||
entityBinding.setEntityDiscriminator( discriminator );
|
||||
}
|
||||
|
||||
private void bindDiscriminatorValue(SubclassEntitySource entitySource, EntityBinding entityBinding) {
|
||||
// todo : implement
|
||||
final String discriminatorValue = entitySource.getDiscriminatorValue();
|
||||
if ( discriminatorValue == null ) {
|
||||
return;
|
||||
}
|
||||
entityBinding.setDiscriminatorValue( discriminatorValue );
|
||||
}
|
||||
|
||||
private void bindAttributes(AttributeSourceContainer attributeSourceContainer, EntityBinding entityBinding) {
|
||||
|
@ -373,8 +398,12 @@ public class Binder {
|
|||
private void bindPersistentCollection(PluralAttributeSource attributeSource, EntityBinding entityBinding) {
|
||||
final AbstractPluralAttributeBinding pluralAttributeBinding;
|
||||
if ( attributeSource.getPluralAttributeNature() == PluralAttributeNature.BAG ) {
|
||||
final PluralAttribute pluralAttribute = entityBinding.getEntity().locateOrCreateBag( attributeSource.getName() );
|
||||
pluralAttributeBinding = entityBinding.makeBagAttributeBinding( pluralAttribute, convert( attributeSource.getPluralAttributeElementNature() ) );
|
||||
final PluralAttribute pluralAttribute = entityBinding.getEntity()
|
||||
.locateOrCreateBag( attributeSource.getName() );
|
||||
pluralAttributeBinding = entityBinding.makeBagAttributeBinding(
|
||||
pluralAttribute,
|
||||
convert( attributeSource.getPluralAttributeElementNature() )
|
||||
);
|
||||
}
|
||||
else {
|
||||
// todo : implement other collection types
|
||||
|
@ -408,7 +437,10 @@ public class Binder {
|
|||
else if ( attributeSource.getNature() == SingularAttributeNature.MANY_TO_ONE ) {
|
||||
attributeBinding = entityBinding.makeManyToOneAttributeBinding( attribute );
|
||||
resolveTypeInformation( attributeSource.getTypeInformation(), attributeBinding );
|
||||
resolveToOneInformation( (ToOneAttributeSource) attributeSource, (ManyToOneAttributeBinding) attributeBinding );
|
||||
resolveToOneInformation(
|
||||
(ToOneAttributeSource) attributeSource,
|
||||
(ManyToOneAttributeBinding) attributeBinding
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw new NotYetImplementedException();
|
||||
|
@ -439,12 +471,14 @@ public class Binder {
|
|||
final Class<?> attributeJavaType = determineJavaType( attributeBinding.getAttribute() );
|
||||
if ( attributeJavaType != null ) {
|
||||
attributeBinding.getHibernateTypeDescriptor().setJavaTypeName( attributeJavaType.getName() );
|
||||
attributeBinding.getAttribute().resolveType( currentBindingContext.makeJavaType( attributeJavaType.getName() ) );
|
||||
attributeBinding.getAttribute()
|
||||
.resolveType( currentBindingContext.makeJavaType( attributeJavaType.getName() ) );
|
||||
}
|
||||
|
||||
final String explicitTypeName = typeSource.getName();
|
||||
if ( explicitTypeName != null ) {
|
||||
final TypeDef typeDef = currentBindingContext.getMetadataImplementor().getTypeDefinition( explicitTypeName );
|
||||
final TypeDef typeDef = currentBindingContext.getMetadataImplementor()
|
||||
.getTypeDefinition( explicitTypeName );
|
||||
if ( typeDef != null ) {
|
||||
attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( typeDef.getTypeClass() );
|
||||
attributeBinding.getHibernateTypeDescriptor().getTypeParameters().putAll( typeDef.getParameters() );
|
||||
|
@ -452,7 +486,7 @@ public class Binder {
|
|||
else {
|
||||
attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( explicitTypeName );
|
||||
}
|
||||
final Map<String,String> parameters = typeSource.getParameters();
|
||||
final Map<String, String> parameters = typeSource.getParameters();
|
||||
if ( parameters != null ) {
|
||||
attributeBinding.getHibernateTypeDescriptor().getTypeParameters().putAll( parameters );
|
||||
}
|
||||
|
@ -555,13 +589,13 @@ public class Binder {
|
|||
final String schemaName = StringHelper.isEmpty( tableSource.getExplicitSchemaName() )
|
||||
? currentBindingContext.getMappingDefaults().getSchemaName()
|
||||
: currentBindingContext.getMetadataImplementor().getOptions().isGloballyQuotedIdentifiers()
|
||||
? StringHelper.quote( tableSource.getExplicitSchemaName() )
|
||||
: tableSource.getExplicitSchemaName();
|
||||
? StringHelper.quote( tableSource.getExplicitSchemaName() )
|
||||
: tableSource.getExplicitSchemaName();
|
||||
final String catalogName = StringHelper.isEmpty( tableSource.getExplicitCatalogName() )
|
||||
? currentBindingContext.getMappingDefaults().getCatalogName()
|
||||
: currentBindingContext.getMetadataImplementor().getOptions().isGloballyQuotedIdentifiers()
|
||||
? StringHelper.quote( tableSource.getExplicitCatalogName() )
|
||||
: tableSource.getExplicitCatalogName();
|
||||
? StringHelper.quote( tableSource.getExplicitCatalogName() )
|
||||
: tableSource.getExplicitCatalogName();
|
||||
|
||||
String tableName = tableSource.getExplicitTableName();
|
||||
if ( StringHelper.isEmpty( tableName ) ) {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.binder;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public interface DiscriminatorSource extends SingularAttributeSource {
|
||||
/**
|
||||
* "Forces" Hibernate to specify the allowed discriminator values, even when retrieving all instances of the root class.
|
||||
*
|
||||
* @return {@code true} in case the discriminator value should be forces, {@code false} otherwise. Default is {@code false}.
|
||||
*/
|
||||
boolean isForced();
|
||||
|
||||
/**
|
||||
* Set this to {@code false}, if your discriminator column is also part of a mapped composite identifier.
|
||||
* It tells Hibernate not to include the column in SQL INSERTs.
|
||||
*
|
||||
* @return {@code true} in case the discriminator value should be included in inserts, {@code false} otherwise.
|
||||
* Default is {@code true}.
|
||||
*/
|
||||
boolean isInserted();
|
||||
}
|
|
@ -183,4 +183,12 @@ public interface EntitySource extends SubclassEntityContainer, AttributeSourceCo
|
|||
* @return The meta-attribute sources.
|
||||
*/
|
||||
public Iterable<MetaAttributeSource> metaAttributes();
|
||||
|
||||
/**
|
||||
* Get the actual discriminator value in case of a single table inheritance
|
||||
*
|
||||
* @return the actual discriminator value in case of a single table inheritance or {@code null} in case there is no
|
||||
* explicit value or a different inheritance scheme
|
||||
*/
|
||||
public String getDiscriminatorValue();
|
||||
}
|
||||
|
|
|
@ -47,8 +47,12 @@ public interface RootEntitySource extends EntitySource {
|
|||
*/
|
||||
public SingularAttributeSource getVersioningAttributeSource();
|
||||
|
||||
// todo : I think this needs to go away
|
||||
public SingularAttributeSource getDiscriminatorAttributeSource();
|
||||
/**
|
||||
* Obtain the source information about the discriminator attribute for single table inheritance
|
||||
*
|
||||
* @return the source information about the discriminator attribute for single table inheritance
|
||||
*/
|
||||
public DiscriminatorSource getDiscriminatorSource();
|
||||
|
||||
/**
|
||||
* Obtain the entity mode for this entity.
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.source.binder;
|
||||
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +35,7 @@ public interface SingularAttributeSource extends AttributeSource, RelationalValu
|
|||
* Determine whether this is a virtual attribute or whether it physically exists on the users domain model.
|
||||
*
|
||||
* @return {@code true} indicates the attribute is virtual, meaning it does NOT exist on the domain model;
|
||||
* {@code false} indicates the attribute physically exists.
|
||||
* {@code false} indicates the attribute physically exists.
|
||||
*/
|
||||
public boolean isVirtualAttribute();
|
||||
|
||||
|
@ -58,6 +57,7 @@ public interface SingularAttributeSource extends AttributeSource, RelationalValu
|
|||
* Obtain the name of the property accessor style used to access this attribute.
|
||||
*
|
||||
* @return The property accessor style for this attribute.
|
||||
*
|
||||
* @see org.hibernate.property.PropertyAccessor
|
||||
*/
|
||||
public String getPropertyAccessorName();
|
||||
|
@ -66,7 +66,7 @@ public interface SingularAttributeSource extends AttributeSource, RelationalValu
|
|||
* Determine whether this attribute is insertable.
|
||||
*
|
||||
* @return {@code true} indicates the attribute value should be used in the {@code SQL INSERT}; {@code false}
|
||||
* indicates it should not.
|
||||
* indicates it should not.
|
||||
*/
|
||||
public boolean isInsertable();
|
||||
|
||||
|
@ -74,7 +74,7 @@ public interface SingularAttributeSource extends AttributeSource, RelationalValu
|
|||
* Determine whether this attribute is updateable.
|
||||
*
|
||||
* @return {@code true} indicates the attribute value should be used in the {@code SQL UPDATE}; {@code false}
|
||||
* indicates it should not.
|
||||
* indicates it should not.
|
||||
*/
|
||||
public boolean isUpdatable();
|
||||
|
||||
|
|
|
@ -242,4 +242,9 @@ public abstract class AbstractEntitySourceImpl implements EntitySource {
|
|||
public Iterable<SubclassEntitySource> subclassEntitySources() {
|
||||
return subclassEntitySources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDiscriminatorValue() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.engine.OptimisticLockStyle;
|
|||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.source.MappingException;
|
||||
import org.hibernate.metamodel.source.binder.DiscriminatorSource;
|
||||
import org.hibernate.metamodel.source.binder.IdentifierSource;
|
||||
import org.hibernate.metamodel.source.binder.RootEntitySource;
|
||||
import org.hibernate.metamodel.source.binder.SimpleIdentifierSource;
|
||||
|
@ -56,7 +57,10 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
|
|||
return new SimpleIdentifierSource() {
|
||||
@Override
|
||||
public SingularAttributeSource getIdentifierAttributeSource() {
|
||||
return new SingularIdentifierAttributeSourceImpl( entityElement().getId(), sourceMappingDocument().getMappingLocalBindingContext() );
|
||||
return new SingularIdentifierAttributeSourceImpl(
|
||||
entityElement().getId(),
|
||||
sourceMappingDocument().getMappingLocalBindingContext()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,20 +94,20 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
|
|||
@Override
|
||||
public SingularAttributeSource getVersioningAttributeSource() {
|
||||
if ( entityElement().getVersion() != null ) {
|
||||
return new VersionAttributeSourceImpl( entityElement().getVersion(), sourceMappingDocument().getMappingLocalBindingContext() );
|
||||
return new VersionAttributeSourceImpl(
|
||||
entityElement().getVersion(),
|
||||
sourceMappingDocument().getMappingLocalBindingContext()
|
||||
);
|
||||
}
|
||||
else if ( entityElement().getTimestamp() != null ) {
|
||||
return new TimestampAttributeSourceImpl( entityElement().getTimestamp(), sourceMappingDocument().getMappingLocalBindingContext() );
|
||||
return new TimestampAttributeSourceImpl(
|
||||
entityElement().getTimestamp(),
|
||||
sourceMappingDocument().getMappingLocalBindingContext()
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttributeSource getDiscriminatorAttributeSource() {
|
||||
// todo : implement
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityMode getEntityMode() {
|
||||
return determineEntityMode();
|
||||
|
@ -136,7 +140,7 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
|
|||
try {
|
||||
return OptimisticLockStyle.valueOf( optimisticLockModeString.toUpperCase() );
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch ( Exception e ) {
|
||||
throw new MappingException(
|
||||
"Unknown optimistic-lock value : " + optimisticLockModeString,
|
||||
sourceMappingDocument().getOrigin()
|
||||
|
@ -181,4 +185,10 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorSource getDiscriminatorSource() {
|
||||
// todo : implement
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,16 +50,14 @@ public class InheritanceBindingTest extends BaseAnnotationBindingTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
// @Resources(annotatedClasses = { RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class })
|
||||
@FailureExpected(jiraKey = "HHH-6447", message = "Work in progress")
|
||||
@Resources(annotatedClasses = { RootOfSingleTableInheritance.class, SubclassOfSingleTableInheritance.class })
|
||||
public void testDiscriminatorValue() {
|
||||
EntityBinding entityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class );
|
||||
assertEquals( "Wrong discriminator value", "foo", entityBinding.getDiscriminatorValue() );
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Resources(annotatedClasses = { SubclassOfSingleTableInheritance.class, SingleEntity.class, RootOfSingleTableInheritance.class })
|
||||
@FailureExpected(jiraKey = "HHH-6447", message = "Work in progress")
|
||||
@Resources(annotatedClasses = { SubclassOfSingleTableInheritance.class, SingleEntity.class, RootOfSingleTableInheritance.class })
|
||||
public void testRootEntityBinding() {
|
||||
EntityBinding noInheritanceEntityBinding = getEntityBinding( SingleEntity.class );
|
||||
assertTrue( "SingleEntity should be a root entity", noInheritanceEntityBinding.isRoot() );
|
||||
|
|
Loading…
Reference in New Issue