HHH-7163 : Refactor code for binding PluralAttributeBinding

This commit is contained in:
Gail Badner 2012-03-09 11:47:57 -08:00
parent 6bab3a3141
commit a2e844c381
7 changed files with 336 additions and 343 deletions

View File

@ -30,6 +30,7 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.TruthValue; import org.hibernate.TruthValue;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
@ -45,6 +46,7 @@
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding;
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
import org.hibernate.metamodel.spi.binding.BagBinding;
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding;
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
@ -56,7 +58,9 @@
import org.hibernate.metamodel.spi.binding.InheritanceType; import org.hibernate.metamodel.spi.binding.InheritanceType;
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
import org.hibernate.metamodel.spi.binding.MetaAttribute; import org.hibernate.metamodel.spi.binding.MetaAttribute;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature; import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.SecondaryTable;
import org.hibernate.metamodel.spi.binding.SetBinding; import org.hibernate.metamodel.spi.binding.SetBinding;
@ -100,7 +104,6 @@
import org.hibernate.metamodel.spi.source.MetaAttributeSource; import org.hibernate.metamodel.spi.source.MetaAttributeSource;
import org.hibernate.metamodel.spi.source.MetadataImplementor; import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.spi.source.Orderable; import org.hibernate.metamodel.spi.source.Orderable;
import org.hibernate.metamodel.spi.source.PluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.PluralAttributeKeySource; import org.hibernate.metamodel.spi.source.PluralAttributeKeySource;
import org.hibernate.metamodel.spi.source.PluralAttributeNature; import org.hibernate.metamodel.spi.source.PluralAttributeNature;
import org.hibernate.metamodel.spi.source.PluralAttributeSource; import org.hibernate.metamodel.spi.source.PluralAttributeSource;
@ -123,6 +126,7 @@
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.config.spi.ConfigurationService; import org.hibernate.service.config.spi.ConfigurationService;
import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -193,10 +197,10 @@ private void bindAttributes(
} }
} }
private AbstractPluralAttributeBinding bindBagAttribute( private AbstractPluralAttributeBinding createBagAttributeBinding(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final PluralAttributeSource attributeSource, final PluralAttributeSource attributeSource,
PluralAttribute attribute ) { PluralAttribute attribute) {
if ( attribute == null ) { if ( attribute == null ) {
attribute = attributeBindingContainer.getAttributeContainer().createBag( attributeSource.getName() ); attribute = attributeBindingContainer.getAttributeContainer().createBag( attributeSource.getName() );
} }
@ -210,6 +214,40 @@ private AbstractPluralAttributeBinding bindBagAttribute(
createMetaAttributeContext( attributeBindingContainer, attributeSource ) ); createMetaAttributeContext( attributeBindingContainer, attributeSource ) );
} }
private Type createBagType(BagBinding bagBinding) {
if ( bagBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) {
return resolveCustomCollectionType( bagBinding );
}
else {
return metadata.getTypeResolver()
.getTypeFactory()
.bag(
bagBinding.getAttribute().getRole(),
bagBinding.getReferencedPropertyName(),
bagBinding.getPluralAttributeElementBinding()
.getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
);
}
}
private Type resolveCustomCollectionType( PluralAttributeBinding pluralAttributeBinding) {
final HibernateTypeDescriptor hibernateTypeDescriptor = pluralAttributeBinding.getHibernateTypeDescriptor();
Properties typeParameters = new Properties( );
if ( hibernateTypeDescriptor.getTypeParameters() != null ) {
typeParameters.putAll( hibernateTypeDescriptor.getTypeParameters() );
}
return metadata.getTypeResolver()
.getTypeFactory()
.customCollection(
hibernateTypeDescriptor.getExplicitTypeName(),
typeParameters,
pluralAttributeBinding.getAttribute().getName(),
pluralAttributeBinding.getReferencedPropertyName(),
pluralAttributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() ==
PluralAttributeElementNature.COMPOSITE
);
}
private BasicAttributeBinding bindBasicAttribute( private BasicAttributeBinding bindBasicAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final SingularAttributeSource attributeSource, final SingularAttributeSource attributeSource,
@ -234,22 +272,19 @@ private BasicAttributeBinding bindBasicAttribute(
attributeSource.getGeneration() ); attributeSource.getGeneration() );
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor(); final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
bindHibernateTypeDescriptor( bindHibernateTypeDescriptor(
hibernateTypeDescriptor, attributeBinding,
attributeSource.getTypeInformation(), attributeSource.getTypeInformation()
attributeBinding.getAttribute()
);
resolveHibernateResolvedType(
attributeBinding.getHibernateTypeDescriptor(),
getHeuristicType( hibernateTypeDescriptor ),
( AbstractValue ) relationalValueBindings.get( 0 ).getValue()
); );
Type resolvedType = getHeuristicType( hibernateTypeDescriptor );
resolveHibernateResolvedType( attributeBinding.getHibernateTypeDescriptor(), resolvedType );
resolveJdbcDataType( resolvedType,( AbstractValue ) relationalValueBindings.get( 0 ).getValue() );
attributeBinding.getAttribute().resolveType( attributeBinding.getAttribute().resolveType(
bindingContexts.peek().makeJavaType( hibernateTypeDescriptor.getJavaTypeName() ) ); bindingContexts.peek().makeJavaType( hibernateTypeDescriptor.getJavaTypeName() ) );
return attributeBinding; return attributeBinding;
} }
private void bindBasicElementSetTablePrimaryKey( final SetBinding attributeBinding ) { private void bindBasicElementSetTablePrimaryKey( final SetBinding attributeBinding ) {
final PrimaryKey primaryKey = attributeBinding.getCollectionTable().getPrimaryKey(); final PrimaryKey primaryKey = attributeBinding.getPluralAttributeKeyBinding().getCollectionTable().getPrimaryKey();
final ForeignKey foreignKey = attributeBinding.getPluralAttributeKeyBinding().getForeignKey(); final ForeignKey foreignKey = attributeBinding.getPluralAttributeKeyBinding().getForeignKey();
final BasicPluralAttributeElementBinding elementBinding = final BasicPluralAttributeElementBinding elementBinding =
( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding(); ( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding();
@ -276,36 +311,38 @@ private void bindBasicElementSetTablePrimaryKey( final SetBinding attributeBindi
private void bindBasicPluralElementRelationalValues( private void bindBasicPluralElementRelationalValues(
final RelationalValueSourceContainer relationalValueSourceContainer, final RelationalValueSourceContainer relationalValueSourceContainer,
final BasicPluralAttributeElementBinding elementBinding ) { final BasicPluralAttributeElementBinding elementBinding ) {
elementBinding.setRelationalValueBindings( bindValues( elementBinding.setRelationalValueBindings(
elementBinding.getPluralAttributeBinding().getContainer(), bindValues(
relationalValueSourceContainer, elementBinding.getPluralAttributeBinding().getContainer(),
elementBinding.getPluralAttributeBinding().getAttribute(), relationalValueSourceContainer,
elementBinding.getPluralAttributeBinding().getCollectionTable() ) ); elementBinding.getPluralAttributeBinding().getAttribute(),
elementBinding.getPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable()
)
);
} }
private void bindCollectionElement( private void bindBasicCollectionElement(
final AbstractPluralAttributeBinding attributeBinding, final BasicPluralAttributeElementBinding elementBinding,
final PluralAttributeSource attributeSource ) { final BasicPluralAttributeElementSource elementSource,
final PluralAttributeElementSource elementSource = attributeSource.getElementSource(); final String defaultElementJavaTypeName) {
if ( elementSource.getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.BASIC ) { bindBasicPluralElementRelationalValues( elementSource, elementBinding );
final BasicPluralAttributeElementSource basicElementSource = ( BasicPluralAttributeElementSource ) elementSource; bindHibernateTypeDescriptor(
final BasicPluralAttributeElementBinding basicCollectionElement = elementBinding.getHibernateTypeDescriptor(),
( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding(); elementSource.getExplicitHibernateTypeSource(),
bindBasicPluralElementRelationalValues( basicElementSource, basicCollectionElement ); defaultElementJavaTypeName
return; );
} Type resolvedElementType = getHeuristicType( elementBinding.getHibernateTypeDescriptor() );
// todo : handle cascades resolveHibernateResolvedType( elementBinding.getHibernateTypeDescriptor(), resolvedElementType );
// final Cascadeable cascadeable = (Cascadeable) binding.getPluralAttributeElementBinding(); resolveJdbcDataType(
// cascadeable.setCascadeStyles( source.getCascadeStyles() ); resolvedElementType,
// todo : implement ( AbstractValue ) elementBinding.getRelationalValueBindings().get( 0 ).getValue()
throw new NotYetImplementedException( String.format( );
"Support for collection elements of type %s not yet implemented",
elementSource.getNature() ) );
} }
private void bindCollectionIndex( private void bindCollectionIndex(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource,
final String defaultElementJavaTypeNam) {
if ( attributeSource.getPluralAttributeNature() != PluralAttributeNature.LIST && if ( attributeSource.getPluralAttributeNature() != PluralAttributeNature.LIST &&
attributeSource.getPluralAttributeNature() != PluralAttributeNature.MAP ) { attributeSource.getPluralAttributeNature() != PluralAttributeNature.MAP ) {
return; return;
@ -317,6 +354,22 @@ private void bindCollectionIndex(
private void bindCollectionKey( private void bindCollectionKey(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
TableSpecification collectionTable;
if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.ONE_TO_MANY ) {
// TODO: Need to look up the table to be able to create the foreign key
throw new NotYetImplementedException( "one-to-many is not supported yet." );
}
else {
collectionTable = createCollectionTable( attributeBinding, attributeSource );
if ( StringHelper.isNotEmpty( attributeSource.getCollectionTableComment() ) ) {
collectionTable.addComment( attributeSource.getCollectionTableComment() );
}
if ( StringHelper.isNotEmpty( attributeSource.getCollectionTableCheck() ) ) {
collectionTable.addCheckConstraint( attributeSource.getCollectionTableCheck() );
}
}
final PluralAttributeKeyBinding keyBinding = attributeBinding.getPluralAttributeKeyBinding();
final PluralAttributeKeySource keySource = attributeSource.getKeySource(); final PluralAttributeKeySource keySource = attributeSource.getKeySource();
// todo: is null FK name allowed (is there a default?) // todo: is null FK name allowed (is there a default?)
final String foreignKeyName = final String foreignKeyName =
@ -324,23 +377,46 @@ private void bindCollectionKey(
? null ? null
: quotedIdentifier( keySource.getExplicitForeignKeyName() ); : quotedIdentifier( keySource.getExplicitForeignKeyName() );
final TableSpecification table = attributeBinding.getContainer().seekEntityBinding().getPrimaryTable(); final TableSpecification table = attributeBinding.getContainer().seekEntityBinding().getPrimaryTable();
attributeBinding.getPluralAttributeKeyBinding().prepareForeignKey( foreignKeyName, table ); keyBinding.prepareForeignKey( foreignKeyName, collectionTable, table );
attributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule( keySource.getOnDeleteAction() ); keyBinding.getForeignKey().setDeleteRule( keySource.getOnDeleteAction() );
if ( keySource.getReferencedEntityAttributeName() == null ) { if ( keySource.getReferencedEntityAttributeName() == null ) {
bindCollectionKeyTargetingPrimaryKey( attributeBinding, attributeSource.getKeySource() ); bindCollectionKeyTargetingPrimaryKey( attributeBinding, attributeSource.getKeySource(), collectionTable );
} else { } else {
bindCollectionKeyTargetingPropertyRef( attributeBinding, attributeSource.getKeySource() ); bindCollectionKeyTargetingPropertyRef( attributeBinding, attributeSource.getKeySource(), collectionTable );
}
final HibernateTypeDescriptor pluralAttributeKeyTypeDescriptor = keyBinding.getHibernateTypeDescriptor();
final HibernateTypeDescriptor referencedTypeDescriptor =
keyBinding.getReferencedAttributeBinding().getHibernateTypeDescriptor();
pluralAttributeKeyTypeDescriptor.setExplicitTypeName( referencedTypeDescriptor.getExplicitTypeName() );
pluralAttributeKeyTypeDescriptor.setJavaTypeName( referencedTypeDescriptor.getJavaTypeName() );
// TODO: not sure about the following...
pluralAttributeKeyTypeDescriptor.setToOne( referencedTypeDescriptor.isToOne() );
pluralAttributeKeyTypeDescriptor.getTypeParameters().putAll( referencedTypeDescriptor.getTypeParameters() );
final Type resolvedKeyType = referencedTypeDescriptor.getResolvedTypeMapping();
pluralAttributeKeyTypeDescriptor.setResolvedTypeMapping( resolvedKeyType );
Iterator<Column> fkColumnIterator = keyBinding.getForeignKey().getSourceColumns().iterator();
if ( resolvedKeyType.isComponentType() ) {
ComponentType componentType = ( ComponentType ) resolvedKeyType;
for ( Type subType : componentType.getSubtypes() ) {
resolveJdbcDataType( subType, fkColumnIterator.next() );
}
}
else {
resolveJdbcDataType( resolvedKeyType, fkColumnIterator.next() );
} }
} }
private void bindCollectionKeyTargetingPrimaryKey( private void bindCollectionKeyTargetingPrimaryKey(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeKeySource keySource ) { final PluralAttributeKeySource keySource,
final TableSpecification collectionTable) {
for ( final RelationalValueSource valueSource : keySource.getValueSources() ) { for ( final RelationalValueSource valueSource : keySource.getValueSources() ) {
if ( valueSource instanceof ColumnSource ) { if ( valueSource instanceof ColumnSource ) {
final Column column = final Column column =
createColumn( createColumn(
attributeBinding.getCollectionTable(), collectionTable,
( ColumnSource ) valueSource, ( ColumnSource ) valueSource,
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
false, false,
@ -354,7 +430,8 @@ private void bindCollectionKeyTargetingPrimaryKey(
private void bindCollectionKeyTargetingPropertyRef( private void bindCollectionKeyTargetingPropertyRef(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeKeySource keySource ) { final PluralAttributeKeySource keySource,
final TableSpecification collectionTable ) {
final EntityBinding ownerEntityBinding = attributeBinding.getContainer().seekEntityBinding(); final EntityBinding ownerEntityBinding = attributeBinding.getContainer().seekEntityBinding();
final AttributeBinding referencedAttributeBinding = final AttributeBinding referencedAttributeBinding =
ownerEntityBinding.locateAttributeBinding( keySource.getReferencedEntityAttributeName() ); ownerEntityBinding.locateAttributeBinding( keySource.getReferencedEntityAttributeName() );
@ -378,7 +455,7 @@ private void bindCollectionKeyTargetingPropertyRef(
final ColumnSource columnSource = ( ColumnSource ) valueSource; final ColumnSource columnSource = ( ColumnSource ) valueSource;
final Column column = final Column column =
createColumn( createColumn(
attributeBinding.getCollectionTable(), collectionTable,
columnSource, columnSource,
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
false, false,
@ -404,12 +481,9 @@ private void bindCollectionKeyTargetingPropertyRef(
} }
} }
private void bindCollectionTable( private TableSpecification createCollectionTable(
final AbstractPluralAttributeBinding pluralAttributeBinding, final AbstractPluralAttributeBinding pluralAttributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource) {
if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.ONE_TO_MANY ) {
return;
}
final DefaultNamingStrategy defaultNamingStategy = new DefaultNamingStrategy() { final DefaultNamingStrategy defaultNamingStategy = new DefaultNamingStrategy() {
@Override @Override
@ -428,25 +502,27 @@ public String defaultName() {
attributeBindingContainer.getPathBase() + '.' + attributeSource.getName() ); attributeBindingContainer.getPathBase() + '.' + attributeSource.getName() );
} }
}; };
pluralAttributeBinding.setCollectionTable( createTable( return createTable(
attributeSource.getCollectionTableSpecificationSource(), attributeSource.getCollectionTableSpecificationSource(),
defaultNamingStategy ) ); defaultNamingStategy );
if ( StringHelper.isNotEmpty( attributeSource.getCollectionTableComment() ) ) {
pluralAttributeBinding.getCollectionTable().addComment( attributeSource.getCollectionTableComment() );
}
if ( StringHelper.isNotEmpty( attributeSource.getCollectionTableCheck() ) ) {
pluralAttributeBinding.getCollectionTable().addCheckConstraint( attributeSource.getCollectionTableCheck() );
}
} }
private void bindCollectionTablePrimaryKey( private void bindCollectionTablePrimaryKey(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource,
final HibernateTypeHelper.ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) {
if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.ONE_TO_MANY || if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.ONE_TO_MANY ||
attributeSource.getPluralAttributeNature() == PluralAttributeNature.BAG ) { attributeSource.getPluralAttributeNature() == PluralAttributeNature.BAG ) {
return; return;
} }
if ( attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.BASIC ) { if ( attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.BASIC ) {
bindHibernateTypeDescriptor(
attributeBinding.getPluralAttributeElementBinding().getHibernateTypeDescriptor(),
( (BasicPluralAttributeElementSource) attributeSource.getElementSource() ).getExplicitHibernateTypeSource(),
reflectedCollectionJavaTypes != null && reflectedCollectionJavaTypes.getCollectionElementType() != null ?
reflectedCollectionJavaTypes.getCollectionElementType().getName() :
null
);
if ( attributeSource.getPluralAttributeNature() == PluralAttributeNature.SET ) { if ( attributeSource.getPluralAttributeNature() == PluralAttributeNature.SET ) {
bindBasicElementSetTablePrimaryKey( ( SetBinding ) attributeBinding ); bindBasicElementSetTablePrimaryKey( ( SetBinding ) attributeBinding );
} else { } else {
@ -522,10 +598,9 @@ private void bindDiscriminator( final EntityBinding rootEntityBinding, final Roo
: "string"; : "string";
final HibernateTypeDescriptor hibernateTypeDescriptor = discriminator.getExplicitHibernateTypeDescriptor(); final HibernateTypeDescriptor hibernateTypeDescriptor = discriminator.getExplicitHibernateTypeDescriptor();
hibernateTypeDescriptor.setExplicitTypeName( typeName ); hibernateTypeDescriptor.setExplicitTypeName( typeName );
resolveHibernateResolvedType( Type resolvedType = getHeuristicType( hibernateTypeDescriptor );
hibernateTypeDescriptor, resolveHibernateResolvedType( hibernateTypeDescriptor, resolvedType );
getHeuristicType( hibernateTypeDescriptor ), resolveJdbcDataType( resolvedType, value );
value );
} }
private EntityBinding bindEntities( final EntityHierarchy entityHierarchy ) { private EntityBinding bindEntities( final EntityHierarchy entityHierarchy ) {
@ -595,28 +670,29 @@ private EntityBinding bindEntity( final EntitySource entitySource, final EntityB
} }
private void bindHibernateTypeDescriptor( private void bindHibernateTypeDescriptor(
final SingularAttributeBinding singularAttributeBinding,
final ExplicitHibernateTypeSource typeSource) {
bindHibernateTypeDescriptor(
singularAttributeBinding.getHibernateTypeDescriptor(),
typeSource,
determineJavaType( singularAttributeBinding.getAttribute() ).getName()
);
}
private void bindExplicitHibernateTypeDescriptor(
final HibernateTypeDescriptor hibernateTypeDescriptor, final HibernateTypeDescriptor hibernateTypeDescriptor,
final ExplicitHibernateTypeSource typeSource, final String typeName,
final Attribute attribute) { final Map<String, String> typeParameters) {
String typeName = typeSource.getName(); // Check if user-specified name is of a User-Defined Type (UDT)
// Check if user specified a type final TypeDefinition typeDef = metadata.getTypeDefinition( typeName );
if ( typeName == null ) { if ( typeDef == null ) {
// Obtain Java type name from attribute hibernateTypeDescriptor.setExplicitTypeName( typeName );
typeName = determineJavaType( attribute ).getName();
hibernateTypeDescriptor.setJavaTypeName( typeName );
} else { } else {
// Check if user-specified name is of a User-Defined Type (UDT) hibernateTypeDescriptor.setExplicitTypeName( typeDef.getTypeImplementorClass().getName() );
final TypeDefinition typeDef = metadata.getTypeDefinition( typeName ); hibernateTypeDescriptor.setTypeParameters( typeDef.getParameters() );
if ( typeDef == null ) { }
hibernateTypeDescriptor.setExplicitTypeName( typeName ); if ( typeParameters != null ) {
} else { hibernateTypeDescriptor.getTypeParameters().putAll( typeParameters );
hibernateTypeDescriptor.setExplicitTypeName( typeDef.getTypeImplementorClass().getName() );
hibernateTypeDescriptor.setTypeParameters( typeDef.getParameters() );
}
final Map< String, String > typeParameters = typeSource.getParameters();
if ( typeParameters != null ) {
hibernateTypeDescriptor.getTypeParameters().putAll( typeParameters );
}
} }
} }
@ -627,6 +703,22 @@ private Class<?> determineJavaType(Attribute attribute) {
); );
} }
private void bindHibernateTypeDescriptor(
final HibernateTypeDescriptor hibernateTypeDescriptor,
final ExplicitHibernateTypeSource explicitTypeSource,
final String defaultJavaTypeName) {
if ( explicitTypeSource.getName() == null ) {
if ( hibernateTypeDescriptor.getJavaTypeName() == null ) {
hibernateTypeDescriptor.setJavaTypeName( defaultJavaTypeName );
}
}
else {
bindExplicitHibernateTypeDescriptor(
hibernateTypeDescriptor, explicitTypeSource.getName(), explicitTypeSource.getParameters()
);
}
}
private void bindIdentifier( final EntityBinding rootEntityBinding, final IdentifierSource identifierSource ) { private void bindIdentifier( final EntityBinding rootEntityBinding, final IdentifierSource identifierSource ) {
final Nature nature = identifierSource.getNature(); final Nature nature = identifierSource.getNature();
if ( nature == Nature.SIMPLE ) { if ( nature == Nature.SIMPLE ) {
@ -694,15 +786,11 @@ private ManyToOneAttributeBinding bindManyToOneAttribute(
); );
// TODO: need to be able to deal with composite IDs // TODO: need to be able to deal with composite IDs
bindHibernateTypeDescriptor( bindHibernateTypeDescriptor(
attributeBinding.getHibernateTypeDescriptor(), attributeBinding,
attributeSource.getTypeInformation(), attributeSource.getTypeInformation()
attributeBinding.getAttribute()
);
resolveHibernateResolvedType(
attributeBinding.getHibernateTypeDescriptor(),
resolvedType,
(AbstractValue) relationalValueBindings.get( 0 ).getValue()
); );
resolveHibernateResolvedType( attributeBinding.getHibernateTypeDescriptor(), resolvedType );
resolveJdbcDataType( resolvedType, (AbstractValue) relationalValueBindings.get( 0 ).getValue() );
attributeBinding.setCascadeStyles( attributeSource.getCascadeStyles() ); attributeBinding.setCascadeStyles( attributeSource.getCascadeStyles() );
attributeBinding.setFetchTiming( attributeSource.getFetchTiming() ); attributeBinding.setFetchTiming( attributeSource.getFetchTiming() );
attributeBinding.setFetchStyle( attributeSource.getFetchStyle() ); attributeBinding.setFetchStyle( attributeSource.getFetchStyle() );
@ -712,28 +800,50 @@ private ManyToOneAttributeBinding bindManyToOneAttribute(
private AbstractPluralAttributeBinding bindPluralAttribute( private AbstractPluralAttributeBinding bindPluralAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource) {
final PluralAttributeNature nature = attributeSource.getPluralAttributeNature(); final PluralAttributeNature nature = attributeSource.getPluralAttributeNature();
final PluralAttribute attribute = final PluralAttribute attribute =
attributeBindingContainer.getAttributeContainer().locatePluralAttribute( attributeSource.getName() ); attributeBindingContainer.getAttributeContainer().locatePluralAttribute( attributeSource.getName() );
AbstractPluralAttributeBinding attributeBinding; AbstractPluralAttributeBinding attributeBinding;
HibernateTypeHelper.ReflectedCollectionJavaTypes reflectedCollectionJavaTypes;
if ( nature == PluralAttributeNature.BAG ) { if ( nature == PluralAttributeNature.BAG ) {
attributeBinding = bindBagAttribute( attributeBindingContainer, attributeSource, attribute ); attributeBinding = createBagAttributeBinding( attributeBindingContainer, attributeSource, attribute );
reflectedCollectionJavaTypes = typeHelper.getReflectedCollectionJavaTypes( attributeBinding );
bindHibernateTypeDescriptor(
attributeBinding.getHibernateTypeDescriptor(),
attributeSource.getTypeInformation(),
getDefaultCollectionJavaTypeName( reflectedCollectionJavaTypes, attributeSource)
);
resolveHibernateResolvedType(
attributeBinding.getHibernateTypeDescriptor(),
createBagType( (BagBinding) attributeBinding )
);
// collection types do not have a relational model
} else if ( nature == PluralAttributeNature.SET ) { } else if ( nature == PluralAttributeNature.SET ) {
attributeBinding = bindSetAttribute( attributeBindingContainer, attributeSource, attribute ); attributeBinding = createSetAttributeBinding( attributeBindingContainer, attributeSource, attribute );
reflectedCollectionJavaTypes = typeHelper.getReflectedCollectionJavaTypes( attributeBinding );
bindHibernateTypeDescriptor(
attributeBinding.getHibernateTypeDescriptor(),
attributeSource.getTypeInformation(),
getDefaultCollectionJavaTypeName( reflectedCollectionJavaTypes, attributeSource)
);
resolveHibernateResolvedType(
attributeBinding.getHibernateTypeDescriptor(),
createSetType( (SetBinding) attributeBinding )
);
// collection types do not have a relational model
} else { } else {
throw new NotYetImplementedException( nature.toString() ); throw new NotYetImplementedException( nature.toString() );
} }
attributeBinding.setFetchTiming( attributeSource.getFetchTiming() ); attributeBinding.setFetchTiming( attributeSource.getFetchTiming() );
attributeBinding.setFetchStyle( attributeSource.getFetchStyle() ); attributeBinding.setFetchStyle( attributeSource.getFetchStyle() );
attributeBinding.setCaching( attributeSource.getCaching() ); attributeBinding.setCaching( attributeSource.getCaching() );
attributeBinding.getHibernateTypeDescriptor().setJavaTypeName( nature.reportedJavaType().getName() );
attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( attributeSource.getTypeInformation().getName() );
attributeBinding.getHibernateTypeDescriptor().getTypeParameters().putAll(
attributeSource.getTypeInformation().getParameters() );
if ( StringHelper.isNotEmpty( attributeSource.getCustomPersisterClassName() ) ) { if ( StringHelper.isNotEmpty( attributeSource.getCustomPersisterClassName() ) ) {
attributeBinding.setExplicitPersisterClass( bindingContexts.peek().< CollectionPersister >locateClassByName( attributeBinding.setExplicitPersisterClass(
attributeSource.getCustomPersisterClassName() ) ); bindingContexts.peek().<CollectionPersister>locateClassByName(
attributeSource.getCustomPersisterClassName()
)
);
} }
attributeBinding.setCustomLoaderName( attributeSource.getCustomLoaderName() ); attributeBinding.setCustomLoaderName( attributeSource.getCustomLoaderName() );
attributeBinding.setCustomSqlInsert( attributeSource.getCustomSqlInsert() ); attributeBinding.setCustomSqlInsert( attributeSource.getCustomSqlInsert() );
@ -741,17 +851,57 @@ private AbstractPluralAttributeBinding bindPluralAttribute(
attributeBinding.setCustomSqlDelete( attributeSource.getCustomSqlDelete() ); attributeBinding.setCustomSqlDelete( attributeSource.getCustomSqlDelete() );
attributeBinding.setCustomSqlDeleteAll( attributeSource.getCustomSqlDeleteAll() ); attributeBinding.setCustomSqlDeleteAll( attributeSource.getCustomSqlDeleteAll() );
attributeBinding.setWhere( attributeSource.getWhere() ); attributeBinding.setWhere( attributeSource.getWhere() );
bindCollectionTable( attributeBinding, attributeSource );
bindSortingAndOrdering( attributeBinding, attributeSource ); bindSortingAndOrdering( attributeBinding, attributeSource );
bindCollectionKey( attributeBinding, attributeSource ); bindCollectionKey( attributeBinding, attributeSource );
bindCollectionElement( attributeBinding, attributeSource );
bindCollectionIndex( attributeBinding, attributeSource ); if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.BASIC ) {
bindCollectionTablePrimaryKey( attributeBinding, attributeSource ); bindBasicCollectionElement(
typeHelper.bindPluralAttributeTypeInformation( attributeSource, attributeBinding ); (BasicPluralAttributeElementBinding) attributeBinding.getPluralAttributeElementBinding(),
(BasicPluralAttributeElementSource) attributeSource.getElementSource(),
getDefaultCollectionElementJavaTypeName( reflectedCollectionJavaTypes )
);
}
else {
throw new NotYetImplementedException( String.format(
"Support for collection elements of type %s not yet implemented",
attributeSource.getElementSource().getNature() ) );
}
bindCollectionIndex(
attributeBinding,
attributeSource,
getDefaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes )
);
bindCollectionTablePrimaryKey( attributeBinding, attributeSource, reflectedCollectionJavaTypes );
metadata.addCollection( attributeBinding ); metadata.addCollection( attributeBinding );
return attributeBinding; return attributeBinding;
} }
private String getDefaultCollectionJavaTypeName(
HibernateTypeHelper.ReflectedCollectionJavaTypes reflectedCollectionJavaTypes,
PluralAttributeSource attributeSource) {
return reflectedCollectionJavaTypes != null && reflectedCollectionJavaTypes.getCollectionType() != null ?
reflectedCollectionJavaTypes.getCollectionType().getName() :
attributeSource.getPluralAttributeNature().reportedJavaType().getName();
}
private String getDefaultCollectionElementJavaTypeName(
HibernateTypeHelper.ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) {
return reflectedCollectionJavaTypes != null && reflectedCollectionJavaTypes.getCollectionElementType() != null ?
reflectedCollectionJavaTypes.getCollectionElementType().getName() :
null;
}
private String getDefaultCollectionIndexJavaTypeName(
HibernateTypeHelper.ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) {
return reflectedCollectionJavaTypes != null && reflectedCollectionJavaTypes.getCollectionIndexType() != null ?
reflectedCollectionJavaTypes.getCollectionIndexType().getName() :
null;
}
private void bindPrimaryTable( final EntityBinding entityBinding, final EntitySource entitySource ) { private void bindPrimaryTable( final EntityBinding entityBinding, final EntitySource entitySource ) {
entityBinding.setPrimaryTable( createTable( entitySource.getPrimaryTable(), new DefaultNamingStrategy() { entityBinding.setPrimaryTable( createTable( entitySource.getPrimaryTable(), new DefaultNamingStrategy() {
@ -799,10 +949,10 @@ private void bindSecondaryTables( final EntityBinding entityBinding, final Entit
} }
} }
private AbstractPluralAttributeBinding bindSetAttribute( private AbstractPluralAttributeBinding createSetAttributeBinding(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final PluralAttributeSource attributeSource, final PluralAttributeSource attributeSource,
PluralAttribute attribute ) { PluralAttribute attribute) {
if ( attribute == null ) { if ( attribute == null ) {
attribute = attributeBindingContainer.getAttributeContainer().createSet( attributeSource.getName() ); attribute = attributeBindingContainer.getAttributeContainer().createSet( attributeSource.getName() );
} }
@ -817,6 +967,22 @@ private AbstractPluralAttributeBinding bindSetAttribute(
null ); null );
} }
private Type createSetType(SetBinding bagBinding) {
if ( bagBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) {
return resolveCustomCollectionType( bagBinding );
}
else {
return metadata.getTypeResolver()
.getTypeFactory()
.set(
bagBinding.getAttribute().getRole(),
bagBinding.getReferencedPropertyName(),
bagBinding.getPluralAttributeElementBinding()
.getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
);
}
}
private void bindSimpleIdentifier( final EntityBinding rootEntityBinding, final SimpleIdentifierSource identifierSource ) { private void bindSimpleIdentifier( final EntityBinding rootEntityBinding, final SimpleIdentifierSource identifierSource ) {
final BasicAttributeBinding idAttributeBinding = final BasicAttributeBinding idAttributeBinding =
( BasicAttributeBinding ) bindAttribute( rootEntityBinding, identifierSource.getIdentifierAttributeSource() ); ( BasicAttributeBinding ) bindAttribute( rootEntityBinding, identifierSource.getIdentifierAttributeSource() );
@ -1152,7 +1318,8 @@ private TableSpecification createTable(
final InLineViewSource inLineViewSource = ( InLineViewSource ) tableSpecSource; final InLineViewSource inLineViewSource = ( InLineViewSource ) tableSpecSource;
return schema.createInLineView( return schema.createInLineView(
Identifier.toIdentifier( inLineViewSource.getLogicalName() ), Identifier.toIdentifier( inLineViewSource.getLogicalName() ),
inLineViewSource.getSelectStatement() ); inLineViewSource.getSelectStatement()
);
} }
private EntityBinding entityBinding( final String entityName ) { private EntityBinding entityBinding( final String entityName ) {
@ -1221,23 +1388,24 @@ private String quotedIdentifier( final String name ) {
private void resolveHibernateResolvedType( private void resolveHibernateResolvedType(
final HibernateTypeDescriptor hibernateTypeDescriptor, final HibernateTypeDescriptor hibernateTypeDescriptor,
final Type resolvedType, final Type resolvedType) {
final AbstractValue value ) {
// Configure relational value JDBC type from Hibernate type descriptor now that its configured // Configure relational value JDBC type from Hibernate type descriptor now that its configured
if ( resolvedType != null ) { if ( resolvedType != null ) {
hibernateTypeDescriptor.setResolvedTypeMapping( resolvedType ); hibernateTypeDescriptor.setResolvedTypeMapping( resolvedType );
if ( hibernateTypeDescriptor.getJavaTypeName() == null ) { if ( hibernateTypeDescriptor.getJavaTypeName() == null ) {
hibernateTypeDescriptor.setJavaTypeName( resolvedType.getReturnedClass().getName() ); hibernateTypeDescriptor.setJavaTypeName( resolvedType.getReturnedClass().getName() );
} }
Type resolvedRelationalType; hibernateTypeDescriptor.setToOne( resolvedType.isEntityType() );
if ( resolvedType.isEntityType() ) { }
resolvedRelationalType = EntityType.class.cast( resolvedType ).getIdentifierOrUniqueKeyType( metadata ); }
hibernateTypeDescriptor.setToOne( true );
} private void resolveJdbcDataType(
else { final Type resolvedType,
resolvedRelationalType = resolvedType; final AbstractValue value) {
hibernateTypeDescriptor.setToOne( false ); if ( resolvedType != null && value != null ) {
} final Type resolvedRelationalType = resolvedType.isEntityType() ?
EntityType.class.cast( resolvedType ).getIdentifierOrUniqueKeyType( metadata ) :
resolvedType;
value.setJdbcDataType( new JdbcDataType( value.setJdbcDataType( new JdbcDataType(
resolvedRelationalType.sqlTypes( metadata )[ 0 ], resolvedRelationalType.sqlTypes( metadata )[ 0 ],
resolvedRelationalType.getName(), resolvedRelationalType.getName(),

View File

@ -34,42 +34,30 @@
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.engine.FetchTiming;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.beans.BeanInfoHelper; import org.hibernate.internal.util.beans.BeanInfoHelper;
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding;
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding;
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.binding.TypeDefinition; import org.hibernate.metamodel.spi.binding.TypeDefinition;
import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.domain.PluralAttribute;
import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.domain.SingularAttribute;
import org.hibernate.metamodel.spi.relational.AbstractValue; import org.hibernate.metamodel.spi.relational.AbstractValue;
import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.JdbcDataType; import org.hibernate.metamodel.spi.relational.JdbcDataType;
import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.metamodel.spi.source.AttributeSource; import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.ComponentAttributeSource; import org.hibernate.metamodel.spi.source.ComponentAttributeSource;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.MetadataImplementor; import org.hibernate.metamodel.spi.source.MetadataImplementor;
import org.hibernate.metamodel.spi.source.PluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
import org.hibernate.metamodel.spi.source.SingularAttributeSource; import org.hibernate.metamodel.spi.source.SingularAttributeSource;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeFactory;
/** /**
* Delegate for handling:<ol> * Delegate for handling:<ol>
@ -88,7 +76,6 @@
* <p/> * <p/>
* Methods intended as entry points are:<ul> * Methods intended as entry points are:<ul>
* <li>{@link #bindSingularAttributeTypeInformation}</li> * <li>{@link #bindSingularAttributeTypeInformation}</li>
* <li>{@link #bindPluralAttributeTypeInformation}</li>
* </ul> * </ul>
* <p/> * <p/>
* Currently the following methods are also required to be non-private because of handling discriminators which * Currently the following methods are also required to be non-private because of handling discriminators which
@ -129,13 +116,12 @@ public void bindSingularAttributeTypeInformation(
} }
} }
bindHibernateTypeInformation( attributeSource.getTypeInformation(), false, hibernateTypeDescriptor ); bindHibernateTypeInformation( attributeSource.getTypeInformation(), hibernateTypeDescriptor );
processSingularAttributeTypeInformation( attributeSource, attributeBinding ); processSingularAttributeTypeInformation( attributeSource, attributeBinding );
} }
public void bindPluralAttributeTypeInformation( public ReflectedCollectionJavaTypes getReflectedCollectionJavaTypes(
PluralAttributeSource attributeSource,
PluralAttributeBinding attributeBinding) { PluralAttributeBinding attributeBinding) {
final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes = determineJavaType( attributeBinding.getAttribute() ); final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes = determineJavaType( attributeBinding.getAttribute() );
@ -165,57 +151,7 @@ public void bindPluralAttributeTypeInformation(
} }
} }
} }
return reflectedCollectionJavaTypes;
bindHibernateTypeInformation(
attributeSource.getTypeInformation(),
false,
attributeBinding.getHibernateTypeDescriptor()
);
processPluralAttributeTypeInformation( attributeSource, attributeBinding );
}
private void processPluralAttributeKeyTypeInformation(PluralAttributeKeyBinding keyBinding) {
final HibernateTypeDescriptor pluralAttributeKeyTypeDescriptor = keyBinding.getHibernateTypeDescriptor();
final HibernateTypeDescriptor referencedTypeDescriptor =
keyBinding.getReferencedAttributeBinding().getHibernateTypeDescriptor();
pluralAttributeKeyTypeDescriptor.setExplicitTypeName( referencedTypeDescriptor.getExplicitTypeName() );
pluralAttributeKeyTypeDescriptor.setJavaTypeName( referencedTypeDescriptor.getJavaTypeName() );
// TODO: not sure about the following...
pluralAttributeKeyTypeDescriptor.setToOne( referencedTypeDescriptor.isToOne() );
pluralAttributeKeyTypeDescriptor.getTypeParameters().putAll( referencedTypeDescriptor.getTypeParameters() );
processPluralAttributeKeyInformation( keyBinding );
}
private void processPluralAttributeKeyInformation(PluralAttributeKeyBinding keyBinding) {
if ( keyBinding.getHibernateTypeDescriptor().getResolvedTypeMapping() != null ) {
return;
}
// we can determine the Hibernate Type if either:
// 1) the user explicitly named a Type in a HibernateTypeDescriptor
// 2) we know the java type of the attribute
Type resolvedType = determineHibernateTypeFromDescriptor( keyBinding.getHibernateTypeDescriptor() );
if ( resolvedType == null ) {
resolvedType = determineHibernateTypeFromAttributeJavaType(
keyBinding.getReferencedAttributeBinding().getAttribute()
);
}
if ( resolvedType != null ) {
Iterator<Column> fkColumnIterator = keyBinding.getForeignKey().getSourceColumns().iterator();
if ( resolvedType.isComponentType() ) {
ComponentType componentType = ( ComponentType ) resolvedType;
for ( Type subType : componentType.getSubtypes() ) {
pushHibernateTypeInformationDown( subType, fkColumnIterator.next() );
}
}
else {
pushHibernateTypeInformationDown( resolvedType, fkColumnIterator.next() );
}
}
} }
private Class<?> determineJavaType(final SingularAttribute attribute) { private Class<?> determineJavaType(final SingularAttribute attribute) {
@ -257,12 +193,10 @@ private ReflectedCollectionJavaTypes determineJavaType(PluralAttribute attribute
* Takes explicit source type information and applies it to the binding model. * Takes explicit source type information and applies it to the binding model.
* *
* @param typeSource The source (user supplied) hibernate type information * @param typeSource The source (user supplied) hibernate type information
* @param isToOne Indicates if this for a to-one association
* @param hibernateTypeDescriptor The binding model hibernate type information * @param hibernateTypeDescriptor The binding model hibernate type information
*/ */
private void bindHibernateTypeInformation( private void bindHibernateTypeInformation(
ExplicitHibernateTypeSource typeSource, ExplicitHibernateTypeSource typeSource,
boolean isToOne,
HibernateTypeDescriptor hibernateTypeDescriptor) { HibernateTypeDescriptor hibernateTypeDescriptor) {
final String explicitTypeName = typeSource.getName(); final String explicitTypeName = typeSource.getName();
if ( explicitTypeName != null ) { if ( explicitTypeName != null ) {
@ -279,7 +213,6 @@ private void bindHibernateTypeInformation(
hibernateTypeDescriptor.getTypeParameters().putAll( parameters ); hibernateTypeDescriptor.getTypeParameters().putAll( parameters );
} }
} }
hibernateTypeDescriptor.setToOne( isToOne );
} }
/** /**
@ -414,12 +347,6 @@ private void pushHibernateTypeInformationDown(
SingularAttributeBinding.class.cast( subAttributeBinding ) SingularAttributeBinding.class.cast( subAttributeBinding )
); );
} }
else if ( AbstractPluralAttributeBinding.class.isInstance( subAttributeBinding ) ) {
processPluralAttributeTypeInformation(
( PluralAttributeSource ) subAttributeSource,
AbstractPluralAttributeBinding.class.cast( subAttributeBinding )
);
}
else { else {
throw new AssertionFailure( "Unknown type of AttributeBinding: " + attributeBinding.getClass().getName() ); throw new AssertionFailure( "Unknown type of AttributeBinding: " + attributeBinding.getClass().getName() );
} }
@ -473,116 +400,8 @@ public void pushHibernateTypeInformationDown(Type resolvedHibernateType, Value v
} }
} }
private void processPluralAttributeTypeInformation( /* package-protected */
PluralAttributeSource attributeSource, static class ReflectedCollectionJavaTypes {
PluralAttributeBinding attributeBinding) {
processCollectionTypeInformation( attributeBinding );
processPluralAttributeElementTypeInformation( attributeSource.getElementSource(), attributeBinding.getPluralAttributeElementBinding() );
processPluralAttributeKeyTypeInformation( attributeBinding.getPluralAttributeKeyBinding() );
}
private void processCollectionTypeInformation(PluralAttributeBinding attributeBinding) {
if ( attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping() != null ) {
return;
}
Type resolvedType;
// do NOT look at java type...
//String typeName = determineTypeName( attributeBinding.getHibernateTypeDescriptor() );
String typeName = attributeBinding.getHibernateTypeDescriptor().getExplicitTypeName();
if ( typeName != null ) {
resolvedType =
metadata.getTypeResolver()
.getTypeFactory()
.customCollection(
typeName,
getTypeParameters( attributeBinding.getHibernateTypeDescriptor() ),
attributeBinding.getAttribute().getName(),
attributeBinding.getReferencedPropertyName(),
attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() ==
PluralAttributeElementNature.COMPOSITE
);
}
else {
resolvedType = determineHibernateTypeFromCollectionType( attributeBinding );
}
if ( resolvedType != null ) {
attributeBinding.getHibernateTypeDescriptor().setResolvedTypeMapping( resolvedType );
}
}
private Type determineHibernateTypeFromCollectionType(PluralAttributeBinding attributeBinding) {
final TypeFactory typeFactory = metadata.getTypeResolver().getTypeFactory();
switch ( attributeBinding.getAttribute().getNature() ) {
case SET: {
return typeFactory.set(
attributeBinding.getAttribute().getRole(),
attributeBinding.getReferencedPropertyName(),
attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
);
}
case BAG: {
return typeFactory.bag(
attributeBinding.getAttribute().getRole(),
attributeBinding.getReferencedPropertyName(),
attributeBinding.getPluralAttributeElementBinding()
.getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
);
}
default: {
throw new UnsupportedOperationException(
"Collection type not supported yet:" + attributeBinding.getAttribute().getNature()
);
}
}
}
private void processPluralAttributeElementTypeInformation(
PluralAttributeElementSource elementSource,
PluralAttributeElementBinding pluralAttributeElementBinding
) {
switch ( pluralAttributeElementBinding.getPluralAttributeElementNature() ) {
case BASIC: {
processBasicCollectionElementTypeInformation(
BasicPluralAttributeElementSource.class.cast( elementSource ),
BasicPluralAttributeElementBinding.class.cast( pluralAttributeElementBinding )
);
break;
}
case COMPOSITE:
case ONE_TO_MANY:
case MANY_TO_MANY:
case MANY_TO_ANY: {
throw new UnsupportedOperationException( "Collection element nature not supported yet: " + pluralAttributeElementBinding
.getPluralAttributeElementNature() );
}
default: {
throw new AssertionFailure( "Unknown collection element nature : " + pluralAttributeElementBinding.getPluralAttributeElementNature() );
}
}
}
private void processBasicCollectionElementTypeInformation(
BasicPluralAttributeElementSource elementSource,
BasicPluralAttributeElementBinding basicCollectionElementBinding) {
Type resolvedType = basicCollectionElementBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
if ( resolvedType == null ) {
bindHibernateTypeInformation(
elementSource.getExplicitHibernateTypeSource(),
false,
basicCollectionElementBinding.getHibernateTypeDescriptor() );
resolvedType = determineHibernateTypeFromDescriptor( basicCollectionElementBinding.getHibernateTypeDescriptor() );
}
if ( resolvedType != null ) {
pushHibernateTypeInformationDown(
basicCollectionElementBinding.getHibernateTypeDescriptor(),
basicCollectionElementBinding.getRelationalValueBindings(),
resolvedType
);
}
}
private static class ReflectedCollectionJavaTypes {
private final Class<?> collectionType; private final Class<?> collectionType;
private final Class<?> collectionElementType; private final Class<?> collectionElementType;
private final Class<?> collectionIndexType; private final Class<?> collectionIndexType;
@ -595,6 +414,16 @@ private ReflectedCollectionJavaTypes(
this.collectionElementType = collectionElementType; this.collectionElementType = collectionElementType;
this.collectionIndexType = collectionIndexType; this.collectionIndexType = collectionIndexType;
} }
public Class<?> getCollectionType() {
return collectionType;
}
public Class<?> getCollectionElementType() {
return collectionElementType;
}
public Class<?> getCollectionIndexType() {
return collectionIndexType;
}
} }
/** /**

View File

@ -45,8 +45,6 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
private final PluralAttributeKeyBinding pluralAttributeKeyBinding; private final PluralAttributeKeyBinding pluralAttributeKeyBinding;
private final AbstractPluralAttributeElementBinding pluralAttributeElementBinding; private final AbstractPluralAttributeElementBinding pluralAttributeElementBinding;
private TableSpecification collectionTable;
private FetchTiming fetchTiming; private FetchTiming fetchTiming;
private FetchStyle fetchStyle; private FetchStyle fetchStyle;
@ -162,15 +160,6 @@ public boolean isAssociation() {
return pluralAttributeElementBinding.getPluralAttributeElementNature().isAssociation(); return pluralAttributeElementBinding.getPluralAttributeElementNature().isAssociation();
} }
@Override
public TableSpecification getCollectionTable() {
return collectionTable;
}
public void setCollectionTable(TableSpecification collectionTable) {
this.collectionTable = collectionTable;
}
@Override @Override
public PluralAttributeKeyBinding getPluralAttributeKeyBinding() { public PluralAttributeKeyBinding getPluralAttributeKeyBinding() {
return pluralAttributeKeyBinding; return pluralAttributeKeyBinding;

View File

@ -57,8 +57,6 @@ public interface PluralAttributeBinding extends AttributeBinding, Fetchable {
*/ */
public PluralAttributeElementBinding getPluralAttributeElementBinding(); public PluralAttributeElementBinding getPluralAttributeElementBinding();
public TableSpecification getCollectionTable();
public boolean isMutable(); public boolean isMutable();
public Caching getCaching(); public Caching getCaching();

View File

@ -75,6 +75,10 @@ public ForeignKey getForeignKey() {
return foreignKey; return foreignKey;
} }
public TableSpecification getCollectionTable() {
return foreignKey.getSourceTable();
}
/** /**
* Is the plural attribute considered inverse? * Is the plural attribute considered inverse?
* <p/> * <p/>
@ -94,13 +98,15 @@ public HibernateTypeDescriptor getHibernateTypeDescriptor() {
return hibernateTypeDescriptor; return hibernateTypeDescriptor;
} }
public void prepareForeignKey(String foreignKeyName, TableSpecification targetTable) { public void prepareForeignKey(
String foreignKeyName,
TableSpecification collectionTable,
TableSpecification targetTable) {
if ( foreignKey != null ) { if ( foreignKey != null ) {
throw new AssertionFailure( "Foreign key already initialized" ); throw new AssertionFailure( "Foreign key already initialized" );
} }
final TableSpecification collectionTable = pluralAttributeBinding.getCollectionTable();
if ( collectionTable == null ) { if ( collectionTable == null ) {
throw new AssertionFailure( "Collection table not yet bound" ); throw new AssertionFailure( "Collection table cannot be null" );
} }
if ( foreignKeyName != null ) { if ( foreignKeyName != null ) {

View File

@ -654,7 +654,7 @@ public AbstractCollectionPersister(
nodeName = null; nodeName = null;
isMutable = collection.isMutable(); isMutable = collection.isMutable();
TableSpecification table = collection.getCollectionTable(); TableSpecification table = collection.getPluralAttributeKeyBinding().getCollectionTable();
fetchMode = collection.getFetchMode(); fetchMode = collection.getFetchMode();
elementType = collection.getPluralAttributeElementBinding().getHibernateTypeDescriptor().getResolvedTypeMapping(); elementType = collection.getPluralAttributeElementBinding().getHibernateTypeDescriptor().getResolvedTypeMapping();
// isSet = collection.isSet(); // isSet = collection.isSet();

View File

@ -24,7 +24,6 @@
package org.hibernate.metamodel.spi.binding; package org.hibernate.metamodel.spi.binding;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -38,6 +37,7 @@
import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.ForeignKey; import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.metamodel.spi.relational.Identifier;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.StandardServiceRegistryImpl; import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -93,8 +93,9 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
PluralAttributeBinding bagBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theBag" ); PluralAttributeBinding bagBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theBag" );
assertNotNull( bagBinding ); assertNotNull( bagBinding );
assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) ); assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) );
assertNotNull( bagBinding.getCollectionTable() ); TableSpecification bagCollectionTable = bagBinding.getPluralAttributeKeyBinding().getCollectionTable();
assertEquals( Identifier.toIdentifier( "`EntityWithBasicCollections_theBag`" ), bagBinding.getCollectionTable().getLogicalName() ); assertNotNull( bagCollectionTable );
assertEquals( Identifier.toIdentifier( "`EntityWithBasicCollections_theBag`" ), bagCollectionTable.getLogicalName() );
PluralAttributeKeyBinding bagKeyBinding = bagBinding.getPluralAttributeKeyBinding(); PluralAttributeKeyBinding bagKeyBinding = bagBinding.getPluralAttributeKeyBinding();
assertSame( bagBinding, bagKeyBinding.getPluralAttributeBinding() ); assertSame( bagBinding, bagKeyBinding.getPluralAttributeBinding() );
HibernateTypeDescriptor bagHibernateTypeDescriptor = bagBinding.getHibernateTypeDescriptor(); HibernateTypeDescriptor bagHibernateTypeDescriptor = bagBinding.getHibernateTypeDescriptor();
@ -107,7 +108,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
ForeignKey fkBag = bagKeyBinding.getForeignKey(); ForeignKey fkBag = bagKeyBinding.getForeignKey();
assertNotNull( fkBag ); assertNotNull( fkBag );
assertSame( bagBinding.getCollectionTable(), fkBag.getSourceTable() ); assertSame( bagCollectionTable, fkBag.getSourceTable() );
assertEquals( 1, fkBag.getColumnSpan() ); assertEquals( 1, fkBag.getColumnSpan() );
Iterator<Column> fkBagColumnIterator = fkBag.getColumns().iterator(); Iterator<Column> fkBagColumnIterator = fkBag.getColumns().iterator();
Iterator<Column> fkBagSourceColumnIterator = fkBag.getSourceColumns().iterator(); Iterator<Column> fkBagSourceColumnIterator = fkBag.getSourceColumns().iterator();
@ -129,7 +130,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
entityIdentifier.getValueBinding().getHibernateTypeDescriptor(), entityIdentifier.getValueBinding().getHibernateTypeDescriptor(),
bagKeyBinding.getHibernateTypeDescriptor() bagKeyBinding.getHibernateTypeDescriptor()
); );
assertEquals( 0, bagBinding.getCollectionTable().getPrimaryKey().getColumnSpan() ); assertEquals( 0, bagCollectionTable.getPrimaryKey().getColumnSpan() );
assertEquals( assertEquals(
entityBinding.getPrimaryTable().getPrimaryKey().getColumns().iterator().next().getJdbcDataType(), entityBinding.getPrimaryTable().getPrimaryKey().getColumns().iterator().next().getJdbcDataType(),
bagKeyBinding.getForeignKey().getColumns().iterator().next().getJdbcDataType() bagKeyBinding.getForeignKey().getColumns().iterator().next().getJdbcDataType()
@ -141,8 +142,9 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
PluralAttributeBinding setBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" ); PluralAttributeBinding setBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" );
assertNotNull( setBinding ); assertNotNull( setBinding );
assertSame( setBinding, entityBinding.locateAttributeBinding( "theSet" ) ); assertSame( setBinding, entityBinding.locateAttributeBinding( "theSet" ) );
assertNotNull( setBinding.getCollectionTable() ); TableSpecification setCollectionTable = setBinding.getPluralAttributeKeyBinding().getCollectionTable();
assertEquals( Identifier.toIdentifier( "`EntityWithBasicCollections_theSet`" ), setBinding.getCollectionTable().getLogicalName() ); assertNotNull( setCollectionTable );
assertEquals( Identifier.toIdentifier( "`EntityWithBasicCollections_theSet`" ), setCollectionTable.getLogicalName() );
PluralAttributeKeyBinding setKeyBinding = setBinding.getPluralAttributeKeyBinding(); PluralAttributeKeyBinding setKeyBinding = setBinding.getPluralAttributeKeyBinding();
assertSame( setBinding, setKeyBinding.getPluralAttributeBinding() ); assertSame( setBinding, setKeyBinding.getPluralAttributeBinding() );
HibernateTypeDescriptor setHibernateTypeDescriptor = setBinding.getHibernateTypeDescriptor(); HibernateTypeDescriptor setHibernateTypeDescriptor = setBinding.getHibernateTypeDescriptor();
@ -155,7 +157,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
ForeignKey fkSet = setKeyBinding.getForeignKey(); ForeignKey fkSet = setKeyBinding.getForeignKey();
assertNotNull( fkSet ); assertNotNull( fkSet );
assertSame( setBinding.getCollectionTable(), fkSet.getSourceTable() ); assertSame( setCollectionTable, fkSet.getSourceTable() );
assertEquals( 1, fkSet.getColumnSpan() ); assertEquals( 1, fkSet.getColumnSpan() );
Iterator<Column> fkSetColumnIterator = fkSet.getColumns().iterator(); Iterator<Column> fkSetColumnIterator = fkSet.getColumns().iterator();
Iterator<Column> fkSetSourceColumnIterator = fkSet.getSourceColumns().iterator(); Iterator<Column> fkSetSourceColumnIterator = fkSet.getSourceColumns().iterator();
@ -178,19 +180,19 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
setKeyBinding.getHibernateTypeDescriptor() setKeyBinding.getHibernateTypeDescriptor()
); );
assertFalse( setKeyBinding.isInverse() ); assertFalse( setKeyBinding.isInverse() );
assertEquals( 2, setBinding.getCollectionTable().getPrimaryKey().getColumnSpan() ); assertEquals( 2, setCollectionTable.getPrimaryKey().getColumnSpan() );
Iterator<Column> setPrimaryKeyIterator = setBinding.getCollectionTable().getPrimaryKey().getColumns().iterator(); Iterator<Column> setPrimaryKeyIterator = setCollectionTable.getPrimaryKey().getColumns().iterator();
assertEquals( assertEquals(
entityBinding.getPrimaryTable().getPrimaryKey().getColumns().iterator().next().getJdbcDataType(), entityBinding.getPrimaryTable().getPrimaryKey().getColumns().iterator().next().getJdbcDataType(),
setPrimaryKeyIterator.next().getJdbcDataType() setPrimaryKeyIterator.next().getJdbcDataType()
); );
assertEquals( assertEquals(
setBinding.getCollectionTable().locateColumn( "`set_stuff`" ).getJdbcDataType(), setCollectionTable.locateColumn( "`set_stuff`" ).getJdbcDataType(),
setPrimaryKeyIterator.next().getJdbcDataType() setPrimaryKeyIterator.next().getJdbcDataType()
); );
assertFalse( setPrimaryKeyIterator.hasNext() ); assertFalse( setPrimaryKeyIterator.hasNext() );
assertSame( assertSame(
setBinding.getCollectionTable().getPrimaryKey().getColumns().iterator().next(), setCollectionTable.getPrimaryKey().getColumns().iterator().next(),
setKeyBinding.getForeignKey().getColumns().iterator().next() setKeyBinding.getForeignKey().getColumns().iterator().next()
); );
assertEquals( PluralAttributeElementNature.BASIC, setBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() ); assertEquals( PluralAttributeElementNature.BASIC, setBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() );
@ -199,8 +201,9 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
PluralAttributeBinding propertyRefSetBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".thePropertyRefSet" ); PluralAttributeBinding propertyRefSetBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".thePropertyRefSet" );
assertNotNull( propertyRefSetBinding ); assertNotNull( propertyRefSetBinding );
assertSame( propertyRefSetBinding, entityBinding.locateAttributeBinding( "thePropertyRefSet" ) ); assertSame( propertyRefSetBinding, entityBinding.locateAttributeBinding( "thePropertyRefSet" ) );
assertNotNull( propertyRefSetBinding.getCollectionTable() ); TableSpecification propertyRefSetCollectionTable = propertyRefSetBinding.getPluralAttributeKeyBinding().getCollectionTable();
assertEquals( Identifier.toIdentifier( "`EntityWithBasicCollections_thePropertyRefSet`" ), propertyRefSetBinding.getCollectionTable().getLogicalName() ); assertNotNull( propertyRefSetCollectionTable );
assertEquals( Identifier.toIdentifier( "`EntityWithBasicCollections_thePropertyRefSet`" ), propertyRefSetCollectionTable.getLogicalName() );
PluralAttributeKeyBinding propertyRefSetKeyBinding = propertyRefSetBinding.getPluralAttributeKeyBinding(); PluralAttributeKeyBinding propertyRefSetKeyBinding = propertyRefSetBinding.getPluralAttributeKeyBinding();
assertSame( propertyRefSetBinding, propertyRefSetKeyBinding.getPluralAttributeBinding() ); assertSame( propertyRefSetBinding, propertyRefSetKeyBinding.getPluralAttributeBinding() );
HibernateTypeDescriptor propertyRefSetHibernateTypeDescriptor = propertyRefSetBinding.getHibernateTypeDescriptor(); HibernateTypeDescriptor propertyRefSetHibernateTypeDescriptor = propertyRefSetBinding.getHibernateTypeDescriptor();
@ -216,7 +219,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
ForeignKey fkPropertyRefSet = propertyRefSetKeyBinding.getForeignKey(); ForeignKey fkPropertyRefSet = propertyRefSetKeyBinding.getForeignKey();
assertNotNull( fkPropertyRefSet ); assertNotNull( fkPropertyRefSet );
assertSame( propertyRefSetBinding.getCollectionTable(), fkPropertyRefSet.getSourceTable() ); assertSame( propertyRefSetCollectionTable, fkPropertyRefSet.getSourceTable() );
assertEquals( 1, fkPropertyRefSet.getColumnSpan() ); assertEquals( 1, fkPropertyRefSet.getColumnSpan() );
Iterator<Column> fkPropertyRefSetColumnIterator = fkPropertyRefSet.getColumns().iterator(); Iterator<Column> fkPropertyRefSetColumnIterator = fkPropertyRefSet.getColumns().iterator();
Iterator<Column> fkPropertyRefSetSourceColumnIterator = fkPropertyRefSet.getSourceColumns().iterator(); Iterator<Column> fkPropertyRefSetSourceColumnIterator = fkPropertyRefSet.getSourceColumns().iterator();
@ -239,19 +242,19 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
propertyRefSetKeyBinding.getHibernateTypeDescriptor() propertyRefSetKeyBinding.getHibernateTypeDescriptor()
); );
assertFalse( propertyRefSetKeyBinding.isInverse() ); assertFalse( propertyRefSetKeyBinding.isInverse() );
assertEquals( 2, propertyRefSetBinding.getCollectionTable().getPrimaryKey().getColumnSpan() ); assertEquals( 2, propertyRefSetCollectionTable.getPrimaryKey().getColumnSpan() );
Iterator<Column> propertyRefSetPrimaryKeyIterator = propertyRefSetBinding.getCollectionTable().getPrimaryKey().getColumns().iterator(); Iterator<Column> propertyRefSetPrimaryKeyIterator = propertyRefSetCollectionTable.getPrimaryKey().getColumns().iterator();
assertEquals( assertEquals(
entityBinding.getPrimaryTable().locateColumn( "`name`" ).getJdbcDataType(), entityBinding.getPrimaryTable().locateColumn( "`name`" ).getJdbcDataType(),
propertyRefSetPrimaryKeyIterator.next().getJdbcDataType() propertyRefSetPrimaryKeyIterator.next().getJdbcDataType()
); );
assertEquals( assertEquals(
propertyRefSetBinding.getCollectionTable().locateColumn( "`property_ref_set_stuff`" ).getJdbcDataType(), propertyRefSetCollectionTable.locateColumn( "`property_ref_set_stuff`" ).getJdbcDataType(),
propertyRefSetPrimaryKeyIterator.next().getJdbcDataType() propertyRefSetPrimaryKeyIterator.next().getJdbcDataType()
); );
assertFalse( propertyRefSetPrimaryKeyIterator.hasNext() ); assertFalse( propertyRefSetPrimaryKeyIterator.hasNext() );
assertSame( assertSame(
propertyRefSetBinding.getCollectionTable().getPrimaryKey().getColumns().iterator().next(), propertyRefSetCollectionTable.getPrimaryKey().getColumns().iterator().next(),
propertyRefSetKeyBinding.getForeignKey().getColumns().iterator().next() propertyRefSetKeyBinding.getForeignKey().getColumns().iterator().next()
); );
assertEquals( PluralAttributeElementNature.BASIC, propertyRefSetBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() ); assertEquals( PluralAttributeElementNature.BASIC, propertyRefSetBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() );