Just correcting some formatting issues

This commit is contained in:
John Verhaeg 2012-03-02 10:41:17 -06:00
parent 8f010234db
commit 8fcf6a171e
1 changed files with 260 additions and 253 deletions

View File

@ -142,7 +142,7 @@ public class Binder {
private final ObjectNameNormalizer nameNormalizer; private final ObjectNameNormalizer nameNormalizer;
private final HashMap< String, EntitySource > entitySourcesByName = new HashMap< String, EntitySource >(); private final HashMap< String, EntitySource > entitySourcesByName = new HashMap< String, EntitySource >();
private final HashMap< RootEntitySource, EntityHierarchy > entityHierarchiesByRootEntitySource = private final HashMap< RootEntitySource, EntityHierarchy > entityHierarchiesByRootEntitySource =
new HashMap< RootEntitySource, EntityHierarchy >(); new HashMap< RootEntitySource, EntityHierarchy >();
private final HashMap< String, AttributeSource > attributeSourcesByName = new HashMap< String, AttributeSource >(); private final HashMap< String, AttributeSource > attributeSourcesByName = new HashMap< String, AttributeSource >();
private final LinkedList< LocalBindingContext > bindingContexts = new LinkedList< LocalBindingContext >(); private final LinkedList< LocalBindingContext > bindingContexts = new LinkedList< LocalBindingContext >();
private final LinkedList< InheritanceType > inheritanceTypes = new LinkedList< InheritanceType >(); private final LinkedList< InheritanceType > inheritanceTypes = new LinkedList< InheritanceType >();
@ -169,8 +169,8 @@ public class Binder {
} }
private AttributeBinding bindAttribute( private AttributeBinding bindAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final AttributeSource attributeSource ) { final AttributeSource attributeSource ) {
// Return existing binding if available // Return existing binding if available
final String attributeName = attributeSource.getName(); final String attributeName = attributeSource.getName();
final AttributeBinding attributeBinding = attributeBindingContainer.locateAttributeBinding( attributeName ); final AttributeBinding attributeBinding = attributeBindingContainer.locateAttributeBinding( attributeName );
@ -184,74 +184,72 @@ public class Binder {
} }
private void bindAttributes( private void bindAttributes(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final AttributeSourceContainer attributeSourceContainer ) { final AttributeSourceContainer attributeSourceContainer ) {
for ( final AttributeSource attributeSource : attributeSourceContainer.attributeSources() ) { for ( final AttributeSource attributeSource : attributeSourceContainer.attributeSources() ) {
bindAttribute( attributeBindingContainer, attributeSource ); bindAttribute( attributeBindingContainer, attributeSource );
} }
} }
private AbstractPluralAttributeBinding bindBagAttribute( private AbstractPluralAttributeBinding bindBagAttribute(
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() );
} }
return attributeBindingContainer.makeBagAttributeBinding( return attributeBindingContainer.makeBagAttributeBinding(
attribute, attribute,
pluralAttributeElementNature( attributeSource ), pluralAttributeElementNature( attributeSource ),
pluralAttributeKeyBinding( attributeBindingContainer, attributeSource ), pluralAttributeKeyBinding( attributeBindingContainer, attributeSource ),
propertyAccessorName( attributeSource ), propertyAccessorName( attributeSource ),
attributeSource.isIncludedInOptimisticLocking(), attributeSource.isIncludedInOptimisticLocking(),
false, false,
createMetaAttributeContext( attributeBindingContainer, attributeSource ) ); createMetaAttributeContext( attributeBindingContainer, attributeSource ) );
} }
private BasicAttributeBinding bindBasicAttribute( private BasicAttributeBinding bindBasicAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final SingularAttributeSource attributeSource, final SingularAttributeSource attributeSource,
SingularAttribute attribute ) { SingularAttribute attribute ) {
if ( attribute == null ) { if ( attribute == null ) {
attribute = createSingularAttribute( attributeBindingContainer, attributeSource ); attribute = createSingularAttribute( attributeBindingContainer, attributeSource );
} }
final List< RelationalValueBinding > relationalValueBindings = final List< RelationalValueBinding > relationalValueBindings =
bindValues( bindValues(
attributeBindingContainer, attributeBindingContainer,
attributeSource, attributeSource,
attribute, attribute,
attributeBindingContainer.seekEntityBinding().getPrimaryTable() ); attributeBindingContainer.seekEntityBinding().getPrimaryTable() );
final BasicAttributeBinding attributeBinding = final BasicAttributeBinding attributeBinding =
attributeBindingContainer.makeBasicAttributeBinding( attributeBindingContainer.makeBasicAttributeBinding(
attribute, attribute,
relationalValueBindings, relationalValueBindings,
propertyAccessorName( attributeSource ), propertyAccessorName( attributeSource ),
attributeSource.isIncludedInOptimisticLocking(), attributeSource.isIncludedInOptimisticLocking(),
attributeSource.isLazy(), attributeSource.isLazy(),
createMetaAttributeContext( attributeBindingContainer, attributeSource ), createMetaAttributeContext( attributeBindingContainer, attributeSource ),
attributeSource.getGeneration() ); attributeSource.getGeneration() );
bindHibernateTypeDescriptor( bindHibernateTypeDescriptor(
attributeBinding.getHibernateTypeDescriptor(), attributeBinding.getHibernateTypeDescriptor(),
attributeSource.getTypeInformation(), attributeSource.getTypeInformation(),
attributeBinding.getAttribute(), attributeBinding.getAttribute(),
( AbstractValue ) relationalValueBindings.get( 0 ).getValue() ); ( AbstractValue ) relationalValueBindings.get( 0 ).getValue() );
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor(); final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
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.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();
if ( elementBinding.getPluralAttributeElementNature() != PluralAttributeElementNature.BASIC ) { if ( elementBinding.getPluralAttributeElementNature() != PluralAttributeElementNature.BASIC ) {
throw new MappingException( String.format( throw new MappingException( String.format(
"Expected a SetBinding with an element of nature PluralAttributeElementNature.BASIC; instead was %s", "Expected a SetBinding with an element of nature PluralAttributeElementNature.BASIC; instead was %s",
elementBinding.getPluralAttributeElementNature() ), bindingContexts.peek().getOrigin() ); elementBinding.getPluralAttributeElementNature() ), bindingContexts.peek().getOrigin() );
} }
for ( final Column foreignKeyColumn : foreignKey.getSourceColumns() ) { for ( final Column foreignKeyColumn : foreignKey.getSourceColumns() ) {
primaryKey.addColumn( foreignKeyColumn ); primaryKey.addColumn( foreignKeyColumn );
@ -269,23 +267,23 @@ public class Binder {
} }
private void bindBasicPluralElementRelationalValues( private void bindBasicPluralElementRelationalValues(
final RelationalValueSourceContainer relationalValueSourceContainer, final RelationalValueSourceContainer relationalValueSourceContainer,
final BasicPluralAttributeElementBinding elementBinding ) { final BasicPluralAttributeElementBinding elementBinding ) {
elementBinding.setRelationalValueBindings( bindValues( elementBinding.setRelationalValueBindings( bindValues(
elementBinding.getPluralAttributeBinding().getContainer(), elementBinding.getPluralAttributeBinding().getContainer(),
relationalValueSourceContainer, relationalValueSourceContainer,
elementBinding.getPluralAttributeBinding().getAttribute(), elementBinding.getPluralAttributeBinding().getAttribute(),
elementBinding.getPluralAttributeBinding().getCollectionTable() ) ); elementBinding.getPluralAttributeBinding().getCollectionTable() ) );
} }
private void bindCollectionElement( private void bindCollectionElement(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
final PluralAttributeElementSource elementSource = attributeSource.getElementSource(); final PluralAttributeElementSource elementSource = attributeSource.getElementSource();
if ( elementSource.getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.BASIC ) { if ( elementSource.getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.BASIC ) {
final BasicPluralAttributeElementSource basicElementSource = ( BasicPluralAttributeElementSource ) elementSource; final BasicPluralAttributeElementSource basicElementSource = ( BasicPluralAttributeElementSource ) elementSource;
final BasicPluralAttributeElementBinding basicCollectionElement = final BasicPluralAttributeElementBinding basicCollectionElement =
( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding(); ( BasicPluralAttributeElementBinding ) attributeBinding.getPluralAttributeElementBinding();
bindBasicPluralElementRelationalValues( basicElementSource, basicCollectionElement ); bindBasicPluralElementRelationalValues( basicElementSource, basicCollectionElement );
return; return;
} }
@ -294,15 +292,15 @@ public class Binder {
// cascadeable.setCascadeStyles( source.getCascadeStyles() ); // cascadeable.setCascadeStyles( source.getCascadeStyles() );
// todo : implement // todo : implement
throw new NotYetImplementedException( String.format( throw new NotYetImplementedException( String.format(
"Support for collection elements of type %s not yet implemented", "Support for collection elements of type %s not yet implemented",
elementSource.getNature() ) ); elementSource.getNature() ) );
} }
private void bindCollectionIndex( private void bindCollectionIndex(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
if ( attributeSource.getPluralAttributeNature() != PluralAttributeNature.LIST && if ( attributeSource.getPluralAttributeNature() != PluralAttributeNature.LIST &&
attributeSource.getPluralAttributeNature() != PluralAttributeNature.MAP ) { attributeSource.getPluralAttributeNature() != PluralAttributeNature.MAP ) {
return; return;
} }
// todo : implement // todo : implement
@ -310,14 +308,14 @@ public class Binder {
} }
private void bindCollectionKey( private void bindCollectionKey(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
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 =
StringHelper.isEmpty( keySource.getExplicitForeignKeyName() ) StringHelper.isEmpty( keySource.getExplicitForeignKeyName() )
? 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 ); attributeBinding.getPluralAttributeKeyBinding().prepareForeignKey( foreignKeyName, table );
attributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule( keySource.getOnDeleteAction() ); attributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule( keySource.getOnDeleteAction() );
@ -329,17 +327,17 @@ public class Binder {
} }
private void bindCollectionKeyTargetingPrimaryKey( private void bindCollectionKeyTargetingPrimaryKey(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeKeySource keySource ) { final PluralAttributeKeySource keySource ) {
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(), attributeBinding.getCollectionTable(),
( ColumnSource ) valueSource, ( ColumnSource ) valueSource,
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
false, false,
true ); true );
attributeBinding.getPluralAttributeKeyBinding().getForeignKey().addColumn( column ); attributeBinding.getPluralAttributeKeyBinding().getForeignKey().addColumn( column );
} else { } else {
// todo: deal with formulas??? // todo: deal with formulas???
@ -348,44 +346,44 @@ public class Binder {
} }
private void bindCollectionKeyTargetingPropertyRef( private void bindCollectionKeyTargetingPropertyRef(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeKeySource keySource ) { final PluralAttributeKeySource keySource ) {
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() );
final ForeignKey foreignKey = attributeBinding.getPluralAttributeKeyBinding().getForeignKey(); final ForeignKey foreignKey = attributeBinding.getPluralAttributeKeyBinding().getForeignKey();
if ( !referencedAttributeBinding.getAttribute().isSingular() ) { if ( !referencedAttributeBinding.getAttribute().isSingular() ) {
throw new MappingException( String.format( throw new MappingException( String.format(
"Collection (%s) property-ref is a plural attribute (%s); must be singular.", "Collection (%s) property-ref is a plural attribute (%s); must be singular.",
attributeBinding.getAttribute().getRole(), attributeBinding.getAttribute().getRole(),
referencedAttributeBinding ), bindingContexts.peek().getOrigin() ); referencedAttributeBinding ), bindingContexts.peek().getOrigin() );
} }
final Iterator< RelationalValueBinding > targetValueBindings = final Iterator< RelationalValueBinding > targetValueBindings =
( ( SingularAttributeBinding ) referencedAttributeBinding ).getRelationalValueBindings().iterator(); ( ( SingularAttributeBinding ) referencedAttributeBinding ).getRelationalValueBindings().iterator();
for ( final RelationalValueSource valueSource : keySource.getValueSources() ) { for ( final RelationalValueSource valueSource : keySource.getValueSources() ) {
if ( !targetValueBindings.hasNext() ) { if ( !targetValueBindings.hasNext() ) {
throw new MappingException( String.format( throw new MappingException( String.format(
"More collection key source columns than target columns for collection: %s", "More collection key source columns than target columns for collection: %s",
attributeBinding.getAttribute().getRole() ), bindingContexts.peek().getOrigin() ); attributeBinding.getAttribute().getRole() ), bindingContexts.peek().getOrigin() );
} }
final Value targetValue = targetValueBindings.next().getValue(); final Value targetValue = targetValueBindings.next().getValue();
if ( ColumnSource.class.isInstance( valueSource ) ) { if ( ColumnSource.class.isInstance( valueSource ) ) {
final ColumnSource columnSource = ( ColumnSource ) valueSource; final ColumnSource columnSource = ( ColumnSource ) valueSource;
final Column column = final Column column =
createColumn( createColumn(
attributeBinding.getCollectionTable(), attributeBinding.getCollectionTable(),
columnSource, columnSource,
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
false, false,
true ); true );
if ( targetValue != null && !( targetValue instanceof Column ) ) { if ( targetValue != null && !( targetValue instanceof Column ) ) {
throw new MappingException( throw new MappingException(
String.format( String.format(
"Type mismatch between collection key source and target; collection: %s; source column (%s) corresponds with target derived value (%s).", "Type mismatch between collection key source and target; collection: %s; source column (%s) corresponds with target derived value (%s).",
attributeBinding.getAttribute().getRole(), attributeBinding.getAttribute().getRole(),
columnSource.getName(), columnSource.getName(),
( ( DerivedValue ) targetValue ).getExpression() ), ( ( DerivedValue ) targetValue ).getExpression() ),
bindingContexts.peek().getOrigin() ); bindingContexts.peek().getOrigin() );
} }
foreignKey.addColumnMapping( column, ( Column ) targetValue ); foreignKey.addColumnMapping( column, ( Column ) targetValue );
} else { } else {
@ -394,14 +392,14 @@ public class Binder {
} }
if ( targetValueBindings != null && targetValueBindings.hasNext() ) { if ( targetValueBindings != null && targetValueBindings.hasNext() ) {
throw new MappingException( String.format( throw new MappingException( String.format(
"More collection key target columns than source columns for collection: %s", "More collection key target columns than source columns for collection: %s",
attributeBinding.getAttribute().getRole() ), bindingContexts.peek().getOrigin() ); attributeBinding.getAttribute().getRole() ), bindingContexts.peek().getOrigin() );
} }
} }
private void bindCollectionTable( private void bindCollectionTable(
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 ) { if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.ONE_TO_MANY ) {
return; return;
} }
@ -412,20 +410,20 @@ public class Binder {
final AttributeBindingContainer attributeBindingContainer = pluralAttributeBinding.getContainer(); final AttributeBindingContainer attributeBindingContainer = pluralAttributeBinding.getContainer();
final EntityBinding owner = attributeBindingContainer.seekEntityBinding(); final EntityBinding owner = attributeBindingContainer.seekEntityBinding();
final String ownerTableLogicalName = final String ownerTableLogicalName =
Table.class.isInstance( owner.getPrimaryTable() ) Table.class.isInstance( owner.getPrimaryTable() )
? ( ( Table ) owner.getPrimaryTable() ).getTableName().getName() ? ( ( Table ) owner.getPrimaryTable() ).getTableName().getName()
: null; : null;
return bindingContexts.peek().getNamingStrategy().collectionTableName( return bindingContexts.peek().getNamingStrategy().collectionTableName(
owner.getEntity().getName(), owner.getEntity().getName(),
ownerTableLogicalName, ownerTableLogicalName,
null, // todo: here null, // todo: here
null, // todo: and here null, // todo: and here
attributeBindingContainer.getPathBase() + '.' + attributeSource.getName() ); attributeBindingContainer.getPathBase() + '.' + attributeSource.getName() );
} }
}; };
pluralAttributeBinding.setCollectionTable( createTable( pluralAttributeBinding.setCollectionTable( createTable(
attributeSource.getCollectionTableSpecificationSource(), attributeSource.getCollectionTableSpecificationSource(),
defaultNamingStategy ) ); defaultNamingStategy ) );
if ( StringHelper.isNotEmpty( attributeSource.getCollectionTableComment() ) ) { if ( StringHelper.isNotEmpty( attributeSource.getCollectionTableComment() ) ) {
pluralAttributeBinding.getCollectionTable().addComment( attributeSource.getCollectionTableComment() ); pluralAttributeBinding.getCollectionTable().addComment( attributeSource.getCollectionTableComment() );
} }
@ -435,10 +433,10 @@ public class Binder {
} }
private void bindCollectionTablePrimaryKey( private void bindCollectionTablePrimaryKey(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
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 ) {
@ -451,15 +449,21 @@ public class Binder {
} }
private CompositeAttributeBinding bindComponentAttribute( private CompositeAttributeBinding bindComponentAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final ComponentAttributeSource attributeSource, final ComponentAttributeSource attributeSource,
SingularAttribute attribute ) { SingularAttribute attribute ) {
Composite composite; Composite composite;
if ( attribute == null ) { if ( attribute == null ) {
composite = composite =
new Composite( attributeSource.getPath(), attributeSource.getClassName(), attributeSource.getClassReference(), null ); new Composite(
attributeSource.getPath(),
attributeSource.getClassName(),
attributeSource.getClassReference(),
null );
attribute = attribute =
attributeBindingContainer.getAttributeContainer().createCompositeAttribute( attributeSource.getName(), composite ); attributeBindingContainer.getAttributeContainer().createCompositeAttribute(
attributeSource.getName(),
composite );
} else { } else {
composite = ( Composite ) attribute.getSingularAttributeType(); composite = ( Composite ) attribute.getSingularAttributeType();
} }
@ -470,13 +474,13 @@ public class Binder {
referencingAttribute = composite.createSingularAttribute( attributeSource.getParentReferenceAttributeName() ); referencingAttribute = composite.createSingularAttribute( attributeSource.getParentReferenceAttributeName() );
} }
final CompositeAttributeBinding attributeBinding = final CompositeAttributeBinding attributeBinding =
attributeBindingContainer.makeComponentAttributeBinding( attributeBindingContainer.makeComponentAttributeBinding(
attribute, attribute,
referencingAttribute, referencingAttribute,
propertyAccessorName( attributeSource ), propertyAccessorName( attributeSource ),
attributeSource.isIncludedInOptimisticLocking(), attributeSource.isIncludedInOptimisticLocking(),
attributeSource.isLazy(), attributeSource.isLazy(),
createMetaAttributeContext( attributeBindingContainer, attributeSource ) ); createMetaAttributeContext( attributeBindingContainer, attributeSource ) );
bindAttributes( attributeBinding, attributeSource ); bindAttributes( attributeBinding, attributeSource );
return attributeBinding; return attributeBinding;
} }
@ -491,24 +495,24 @@ public class Binder {
AbstractValue value; AbstractValue value;
if ( valueSource instanceof ColumnSource ) { if ( valueSource instanceof ColumnSource ) {
value = value =
createColumn( createColumn(
table, table,
( ColumnSource ) valueSource, ( ColumnSource ) valueSource,
bindingContexts.peek().getMappingDefaults().getDiscriminatorColumnName(), bindingContexts.peek().getMappingDefaults().getDiscriminatorColumnName(),
false, false,
false ); false );
} else { } else {
value = table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() ); value = table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() );
} }
final EntityDiscriminator discriminator = final EntityDiscriminator discriminator =
new EntityDiscriminator( value, discriminatorSource.isInserted(), discriminatorSource.isForced() ); new EntityDiscriminator( value, discriminatorSource.isInserted(), discriminatorSource.isForced() );
rootEntityBinding.getHierarchyDetails().setEntityDiscriminator( discriminator ); rootEntityBinding.getHierarchyDetails().setEntityDiscriminator( discriminator );
rootEntityBinding.setDiscriminatorMatchValue( rootEntitySource.getDiscriminatorMatchValue() ); rootEntityBinding.setDiscriminatorMatchValue( rootEntitySource.getDiscriminatorMatchValue() );
// Configure discriminator hibernate type // Configure discriminator hibernate type
final String typeName = final String typeName =
discriminatorSource.getExplicitHibernateTypeName() != null discriminatorSource.getExplicitHibernateTypeName() != null
? discriminatorSource.getExplicitHibernateTypeName() ? discriminatorSource.getExplicitHibernateTypeName()
: "string"; : "string";
final HibernateTypeDescriptor hibernateTypeDescriptor = discriminator.getExplicitHibernateTypeDescriptor(); final HibernateTypeDescriptor hibernateTypeDescriptor = discriminator.getExplicitHibernateTypeDescriptor();
hibernateTypeDescriptor.setExplicitTypeName( typeName ); hibernateTypeDescriptor.setExplicitTypeName( typeName );
resolveHibernateResolvedType( hibernateTypeDescriptor, typeName, value ); resolveHibernateResolvedType( hibernateTypeDescriptor, typeName, value );
@ -581,16 +585,18 @@ public class Binder {
} }
private void bindHibernateTypeDescriptor( private void bindHibernateTypeDescriptor(
final HibernateTypeDescriptor hibernateTypeDescriptor, final HibernateTypeDescriptor hibernateTypeDescriptor,
final ExplicitHibernateTypeSource typeSource, final ExplicitHibernateTypeSource typeSource,
final Attribute attribute, final Attribute attribute,
final AbstractValue value ) { final AbstractValue value ) {
String typeName = typeSource.getName(); String typeName = typeSource.getName();
// Check if user specified a type // Check if user specified a type
if ( typeName == null ) { if ( typeName == null ) {
// Obtain Java type name from attribute // Obtain Java type name from attribute
final Class< ? > attributeJavaType = final Class< ? > attributeJavaType =
ReflectHelper.reflectedPropertyClass( attribute.getAttributeContainer().getClassReference(), attribute.getName() ); ReflectHelper.reflectedPropertyClass(
attribute.getAttributeContainer().getClassReference(),
attribute.getName() );
typeName = attributeJavaType.getName(); typeName = attributeJavaType.getName();
hibernateTypeDescriptor.setJavaTypeName( typeName ); hibernateTypeDescriptor.setJavaTypeName( typeName );
} else { } else {
@ -630,33 +636,33 @@ public class Binder {
} }
private ManyToOneAttributeBinding bindManyToOneAttribute( private ManyToOneAttributeBinding bindManyToOneAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final ToOneAttributeSource attributeSource, final ToOneAttributeSource attributeSource,
SingularAttribute attribute ) { SingularAttribute attribute ) {
if ( attribute == null ) { if ( attribute == null ) {
attribute = createSingularAttribute( attributeBindingContainer, attributeSource ); attribute = createSingularAttribute( attributeBindingContainer, attributeSource );
} }
final List< RelationalValueBinding > relationalValueBindings = final List< RelationalValueBinding > relationalValueBindings =
bindValues( bindValues(
attributeBindingContainer, attributeBindingContainer,
attributeSource, attributeSource,
attribute, attribute,
attributeBindingContainer.seekEntityBinding().getPrimaryTable() ); attributeBindingContainer.seekEntityBinding().getPrimaryTable() );
final ManyToOneAttributeBinding attributeBinding = final ManyToOneAttributeBinding attributeBinding =
attributeBindingContainer.makeManyToOneAttributeBinding( attributeBindingContainer.makeManyToOneAttributeBinding(
attribute, attribute,
propertyAccessorName( attributeSource ), propertyAccessorName( attributeSource ),
attributeSource.isIncludedInOptimisticLocking(), attributeSource.isIncludedInOptimisticLocking(),
attributeSource.isLazy(), attributeSource.isLazy(),
createMetaAttributeContext( attributeBindingContainer, attributeSource ), createMetaAttributeContext( attributeBindingContainer, attributeSource ),
null, // this isn't passed to the binding constructor null, // this isn't passed to the binding constructor
null, // this isn't passed to the binding constructor null, // this isn't passed to the binding constructor
relationalValueBindings ); relationalValueBindings );
bindHibernateTypeDescriptor( bindHibernateTypeDescriptor(
attributeBinding.getHibernateTypeDescriptor(), attributeBinding.getHibernateTypeDescriptor(),
attributeSource.getTypeInformation(), attributeSource.getTypeInformation(),
attributeBinding.getAttribute(), attributeBinding.getAttribute(),
( AbstractValue ) relationalValueBindings.get( 0 ).getValue() ); ( AbstractValue ) relationalValueBindings.get( 0 ).getValue() );
final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor(); final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor();
attribute.resolveType( bindingContexts.peek().makeJavaType( hibernateTypeDescriptor.getJavaTypeName() ) ); attribute.resolveType( bindingContexts.peek().makeJavaType( hibernateTypeDescriptor.getJavaTypeName() ) );
@ -673,20 +679,20 @@ public class Binder {
final String referencedAttributeName = attributeSource.getReferencedEntityAttributeName(); final String referencedAttributeName = attributeSource.getReferencedEntityAttributeName();
attributeBinding.setReferencedAttributeName( referencedAttributeName ); attributeBinding.setReferencedAttributeName( referencedAttributeName );
final AttributeBinding referencedAttributeBinding = final AttributeBinding referencedAttributeBinding =
referencedAttributeName == null referencedAttributeName == null
? referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() ? referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding()
: referencedEntityBinding.locateAttributeBinding( referencedAttributeName ); : referencedEntityBinding.locateAttributeBinding( referencedAttributeName );
attributeBinding.resolveReference( referencedAttributeBinding ); attributeBinding.resolveReference( referencedAttributeBinding );
referencedAttributeBinding.addEntityReferencingAttributeBinding( attributeBinding ); referencedAttributeBinding.addEntityReferencingAttributeBinding( attributeBinding );
return attributeBinding; return attributeBinding;
} }
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;
if ( nature == PluralAttributeNature.BAG ) { if ( nature == PluralAttributeNature.BAG ) {
attributeBinding = bindBagAttribute( attributeBindingContainer, attributeSource, attribute ); attributeBinding = bindBagAttribute( attributeBindingContainer, attributeSource, attribute );
@ -701,10 +707,10 @@ public class Binder {
attributeBinding.getHibernateTypeDescriptor().setJavaTypeName( nature.reportedJavaType().getName() ); attributeBinding.getHibernateTypeDescriptor().setJavaTypeName( nature.reportedJavaType().getName() );
attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( attributeSource.getTypeInformation().getName() ); attributeBinding.getHibernateTypeDescriptor().setExplicitTypeName( attributeSource.getTypeInformation().getName() );
attributeBinding.getHibernateTypeDescriptor().getTypeParameters().putAll( attributeBinding.getHibernateTypeDescriptor().getTypeParameters().putAll(
attributeSource.getTypeInformation().getParameters() ); attributeSource.getTypeInformation().getParameters() );
if ( StringHelper.isNotEmpty( attributeSource.getCustomPersisterClassName() ) ) { if ( StringHelper.isNotEmpty( attributeSource.getCustomPersisterClassName() ) ) {
attributeBinding.setExplicitPersisterClass( bindingContexts.peek().< CollectionPersister >locateClassByName( attributeBinding.setExplicitPersisterClass( bindingContexts.peek().< CollectionPersister >locateClassByName(
attributeSource.getCustomPersisterClassName() ) ); attributeSource.getCustomPersisterClassName() ) );
} }
attributeBinding.setCustomLoaderName( attributeSource.getCustomLoaderName() ); attributeBinding.setCustomLoaderName( attributeSource.getCustomLoaderName() );
attributeBinding.setCustomSqlInsert( attributeSource.getCustomSqlInsert() ); attributeBinding.setCustomSqlInsert( attributeSource.getCustomSqlInsert() );
@ -771,26 +777,26 @@ public class Binder {
} }
private AbstractPluralAttributeBinding bindSetAttribute( private AbstractPluralAttributeBinding bindSetAttribute(
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() );
} }
return attributeBindingContainer.makeSetAttributeBinding( return attributeBindingContainer.makeSetAttributeBinding(
attribute, attribute,
pluralAttributeElementNature( attributeSource ), pluralAttributeElementNature( attributeSource ),
pluralAttributeKeyBinding( attributeBindingContainer, attributeSource ), pluralAttributeKeyBinding( attributeBindingContainer, attributeSource ),
propertyAccessorName( attributeSource ), propertyAccessorName( attributeSource ),
attributeSource.isIncludedInOptimisticLocking(), attributeSource.isIncludedInOptimisticLocking(),
false, false,
createMetaAttributeContext( attributeBindingContainer, attributeSource ), createMetaAttributeContext( attributeBindingContainer, attributeSource ),
null ); null );
} }
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() );
rootEntityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding ); rootEntityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding );
// Configure ID generator // Configure ID generator
IdGenerator generator = identifierSource.getIdentifierGeneratorDescriptor(); IdGenerator generator = identifierSource.getIdentifierGeneratorDescriptor();
@ -807,11 +813,11 @@ public class Binder {
} }
private SingularAttributeBinding bindSingularAttribute( private SingularAttributeBinding bindSingularAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final SingularAttributeSource attributeSource ) { final SingularAttributeSource attributeSource ) {
final SingularAttributeNature nature = attributeSource.getNature(); final SingularAttributeNature nature = attributeSource.getNature();
final SingularAttribute attribute = final SingularAttribute attribute =
attributeBindingContainer.getAttributeContainer().locateSingularAttribute( attributeSource.getName() ); attributeBindingContainer.getAttributeContainer().locateSingularAttribute( attributeSource.getName() );
if ( nature == SingularAttributeNature.BASIC ) { if ( nature == SingularAttributeNature.BASIC ) {
return bindBasicAttribute( attributeBindingContainer, attributeSource, attribute ); return bindBasicAttribute( attributeBindingContainer, attributeSource, attribute );
} }
@ -825,8 +831,8 @@ public class Binder {
} }
private void bindSortingAndOrdering( private void bindSortingAndOrdering(
final AbstractPluralAttributeBinding attributeBinding, final AbstractPluralAttributeBinding attributeBinding,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
if ( Sortable.class.isInstance( attributeSource ) ) { if ( Sortable.class.isInstance( attributeSource ) ) {
final Sortable sortable = ( Sortable ) attributeSource; final Sortable sortable = ( Sortable ) attributeSource;
if ( sortable.isSorted() ) { if ( sortable.isSorted() ) {
@ -866,14 +872,14 @@ public class Binder {
} }
private List< RelationalValueBinding > bindValues( private List< RelationalValueBinding > bindValues(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final RelationalValueSourceContainer valueSourceContainer, final RelationalValueSourceContainer valueSourceContainer,
final Attribute attribute, final Attribute attribute,
final TableSpecification defaultTable ) { final TableSpecification defaultTable ) {
final List< RelationalValueBinding > valueBindings = new ArrayList< RelationalValueBinding >(); final List< RelationalValueBinding > valueBindings = new ArrayList< RelationalValueBinding >();
if ( valueSourceContainer.relationalValueSources().isEmpty() ) { if ( valueSourceContainer.relationalValueSources().isEmpty() ) {
final String columnName = final String columnName =
quotedIdentifier( bindingContexts.peek().getNamingStrategy().propertyToColumnName( attribute.getName() ) ); quotedIdentifier( bindingContexts.peek().getNamingStrategy().propertyToColumnName( attribute.getName() ) );
final Column column = defaultTable.locateOrCreateColumn( columnName ); final Column column = defaultTable.locateOrCreateColumn( columnName );
column.setNullable( valueSourceContainer.areValuesNullableByDefault() ); column.setNullable( valueSourceContainer.areValuesNullableByDefault() );
valueBindings.add( new RelationalValueBinding( column ) ); valueBindings.add( new RelationalValueBinding( column ) );
@ -881,25 +887,25 @@ public class Binder {
final String name = attribute.getName(); final String name = attribute.getName();
for ( final RelationalValueSource valueSource : valueSourceContainer.relationalValueSources() ) { for ( final RelationalValueSource valueSource : valueSourceContainer.relationalValueSources() ) {
final TableSpecification table = final TableSpecification table =
valueSource.getContainingTableName() == null valueSource.getContainingTableName() == null
? defaultTable ? defaultTable
: attributeBindingContainer.seekEntityBinding().locateTable( valueSource.getContainingTableName() ); : attributeBindingContainer.seekEntityBinding().locateTable( valueSource.getContainingTableName() );
if ( valueSource instanceof ColumnSource ) { if ( valueSource instanceof ColumnSource ) {
final ColumnSource columnSource = ( ColumnSource ) valueSource; final ColumnSource columnSource = ( ColumnSource ) valueSource;
final boolean isIncludedInInsert = final boolean isIncludedInInsert =
toBoolean( columnSource.isIncludedInInsert(), valueSourceContainer.areValuesIncludedInInsertByDefault() ); toBoolean( columnSource.isIncludedInInsert(), valueSourceContainer.areValuesIncludedInInsertByDefault() );
final boolean isIncludedInUpdate = final boolean isIncludedInUpdate =
toBoolean( columnSource.isIncludedInUpdate(), valueSourceContainer.areValuesIncludedInUpdateByDefault() ); toBoolean( columnSource.isIncludedInUpdate(), valueSourceContainer.areValuesIncludedInUpdateByDefault() );
valueBindings.add( new RelationalValueBinding( createColumn( valueBindings.add( new RelationalValueBinding( createColumn(
table, table,
columnSource, columnSource,
name, name,
valueSourceContainer.areValuesNullableByDefault(), valueSourceContainer.areValuesNullableByDefault(),
true ), isIncludedInInsert, isIncludedInUpdate ) ); true ), isIncludedInInsert, isIncludedInUpdate ) );
} else { } else {
final DerivedValue derivedValue = final DerivedValue derivedValue =
table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() ); table.locateOrCreateDerivedValue( ( ( DerivedValueSource ) valueSource ).getExpression() );
valueBindings.add( new RelationalValueBinding( derivedValue ) ); valueBindings.add( new RelationalValueBinding( derivedValue ) );
} }
} }
@ -917,15 +923,15 @@ public class Binder {
} }
private Column createColumn( private Column createColumn(
final TableSpecification table, final TableSpecification table,
final ColumnSource columnSource, final ColumnSource columnSource,
final String defaultName, final String defaultName,
final boolean isNullableByDefault, final boolean isNullableByDefault,
final boolean isDefaultAttributeName ) { final boolean isDefaultAttributeName ) {
if ( columnSource.getName() == null && defaultName == null ) { if ( columnSource.getName() == null && defaultName == null ) {
throw new MappingException( throw new MappingException(
"Cannot resolve name for column because no name was specified and default name is null.", "Cannot resolve name for column because no name was specified and default name is null.",
bindingContexts.peek().getOrigin() ); bindingContexts.peek().getOrigin() );
} }
String name; String name;
if ( columnSource.getName() != null ) { if ( columnSource.getName() != null ) {
@ -958,15 +964,16 @@ public class Binder {
final InheritanceType inheritanceType = inheritanceTypes.peek(); final InheritanceType inheritanceType = inheritanceTypes.peek();
final EntityMode entityMode = entityModes.peek(); final EntityMode entityMode = entityModes.peek();
final EntityBinding entityBinding = final EntityBinding entityBinding =
entitySource instanceof RootEntitySource ? new EntityBinding( inheritanceType, entityMode ) : new EntityBinding( entitySource instanceof RootEntitySource
superEntityBinding ); ? new EntityBinding( inheritanceType, entityMode )
: new EntityBinding( superEntityBinding );
// Create domain entity // Create domain entity
final String entityClassName = entityMode == EntityMode.POJO ? entitySource.getClassName() : null; final String entityClassName = entityMode == EntityMode.POJO ? entitySource.getClassName() : null;
entityBinding.setEntity( new Entity( entityBinding.setEntity( new Entity(
entitySource.getEntityName(), entitySource.getEntityName(),
entityClassName, entityClassName,
bindingContext.makeClassReference( entityClassName ), bindingContext.makeClassReference( entityClassName ),
superEntityBinding == null ? null : superEntityBinding.getEntity() ) ); superEntityBinding == null ? null : superEntityBinding.getEntity() ) );
// Create relational table // Create relational table
if ( superEntityBinding != null && inheritanceType == InheritanceType.SINGLE_TABLE ) { if ( superEntityBinding != null && inheritanceType == InheritanceType.SINGLE_TABLE ) {
entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() ); entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() );
@ -991,9 +998,9 @@ public class Binder {
entityBinding.setCustomEntityPersisterClass( bindingContext.< EntityPersister >locateClassByName( customPersisterClassName ) ); entityBinding.setCustomEntityPersisterClass( bindingContext.< EntityPersister >locateClassByName( customPersisterClassName ) );
} }
entityBinding.setMetaAttributeContext( createMetaAttributeContext( entityBinding.setMetaAttributeContext( createMetaAttributeContext(
entitySource.metaAttributes(), entitySource.metaAttributes(),
true, true,
metadata.getGlobalMetaAttributeContext() ) ); metadata.getGlobalMetaAttributeContext() ) );
entityBinding.setJpaEntityName( entitySource.getJpaEntityName() ); entityBinding.setJpaEntityName( entitySource.getJpaEntityName() );
entityBinding.setDynamicUpdate( entitySource.isDynamicUpdate() ); entityBinding.setDynamicUpdate( entitySource.isDynamicUpdate() );
entityBinding.setDynamicInsert( entitySource.isDynamicInsert() ); entityBinding.setDynamicInsert( entitySource.isDynamicInsert() );
@ -1052,23 +1059,23 @@ public class Binder {
properties.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, nameNormalizer ); properties.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, nameNormalizer );
} }
rootEntityBinding.getHierarchyDetails().getEntityIdentifier().createIdentifierGenerator( rootEntityBinding.getHierarchyDetails().getEntityIdentifier().createIdentifierGenerator(
identifierGeneratorFactory, identifierGeneratorFactory,
properties ); properties );
} }
private MetaAttributeContext createMetaAttributeContext( private MetaAttributeContext createMetaAttributeContext(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final AttributeSource attributeSource ) { final AttributeSource attributeSource ) {
return createMetaAttributeContext( return createMetaAttributeContext(
attributeSource.metaAttributes(), attributeSource.metaAttributes(),
false, false,
attributeBindingContainer.getMetaAttributeContext() ); attributeBindingContainer.getMetaAttributeContext() );
} }
private MetaAttributeContext createMetaAttributeContext( private MetaAttributeContext createMetaAttributeContext(
final Iterable< MetaAttributeSource > metaAttributeSources, final Iterable< MetaAttributeSource > metaAttributeSources,
final boolean onlyInheritable, final boolean onlyInheritable,
final MetaAttributeContext parentContext ) { final MetaAttributeContext parentContext ) {
final MetaAttributeContext subContext = new MetaAttributeContext( parentContext ); final MetaAttributeContext subContext = new MetaAttributeContext( parentContext );
for ( final MetaAttributeSource metaAttributeSource : metaAttributeSources ) { for ( final MetaAttributeSource metaAttributeSource : metaAttributeSources ) {
if ( onlyInheritable && !metaAttributeSource.isInheritable() ) { if ( onlyInheritable && !metaAttributeSource.isInheritable() ) {
@ -1086,22 +1093,22 @@ public class Binder {
} }
private SingularAttribute createSingularAttribute( private SingularAttribute createSingularAttribute(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final SingularAttributeSource attributeSource ) { final SingularAttributeSource attributeSource ) {
return attributeSource.isVirtualAttribute() return attributeSource.isVirtualAttribute()
? attributeBindingContainer.getAttributeContainer().createVirtualSingularAttribute( attributeSource.getName() ) ? attributeBindingContainer.getAttributeContainer().createVirtualSingularAttribute( attributeSource.getName() )
: attributeBindingContainer.getAttributeContainer().createSingularAttribute( attributeSource.getName() ); : attributeBindingContainer.getAttributeContainer().createSingularAttribute( attributeSource.getName() );
} }
private TableSpecification createTable( private TableSpecification createTable(
final TableSpecificationSource tableSpecSource, final TableSpecificationSource tableSpecSource,
final DefaultNamingStrategy defaultNamingStrategy ) { final DefaultNamingStrategy defaultNamingStrategy ) {
final LocalBindingContext bindingContext = bindingContexts.peek(); final LocalBindingContext bindingContext = bindingContexts.peek();
final MappingDefaults mappingDefaults = bindingContext.getMappingDefaults(); final MappingDefaults mappingDefaults = bindingContext.getMappingDefaults();
final Schema.Name schemaName = final Schema.Name schemaName =
new Schema.Name( new Schema.Name(
createIdentifier( tableSpecSource.getExplicitSchemaName(), mappingDefaults.getSchemaName() ), createIdentifier( tableSpecSource.getExplicitSchemaName(), mappingDefaults.getSchemaName() ),
createIdentifier( tableSpecSource.getExplicitCatalogName(), mappingDefaults.getCatalogName() ) ); createIdentifier( tableSpecSource.getExplicitCatalogName(), mappingDefaults.getCatalogName() ) );
final Schema schema = metadata.getDatabase().locateSchema( schemaName ); final Schema schema = metadata.getDatabase().locateSchema( schemaName );
if ( tableSpecSource instanceof TableSource ) { if ( tableSpecSource instanceof TableSource ) {
final TableSource tableSource = ( TableSource ) tableSpecSource; final TableSource tableSource = ( TableSource ) tableSpecSource;
@ -1121,8 +1128,8 @@ public class Binder {
} }
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 ) {
@ -1133,14 +1140,14 @@ public class Binder {
final EntitySource entitySource = entitySourcesByName.get( entityName ); final EntitySource entitySource = entitySourcesByName.get( entityName );
// Get super entity binding (creating it if necessary using recursive call to this method) // Get super entity binding (creating it if necessary using recursive call to this method)
final EntityBinding superEntityBinding = final EntityBinding superEntityBinding =
entitySource instanceof SubclassEntitySource entitySource instanceof SubclassEntitySource
? entityBinding( ( ( SubclassEntitySource ) entitySource ).superclassEntitySource().getEntityName() ) ? entityBinding( ( ( SubclassEntitySource ) entitySource ).superclassEntitySource().getEntityName() )
: null; : null;
// Create entity binding // Create entity binding
entityBinding = entityBinding =
superEntityBinding == null ? bindEntities( entityHierarchiesByRootEntitySource.get( entitySource ) ) : bindEntity( superEntityBinding == null
entitySource, ? bindEntities( entityHierarchiesByRootEntitySource.get( entitySource ) )
superEntityBinding ); : bindEntity( entitySource, superEntityBinding );
} }
return entityBinding; return entityBinding;
} }
@ -1160,29 +1167,29 @@ public class Binder {
} }
private SingularAttributeBinding pluralAttributeKeyBinding( private SingularAttributeBinding pluralAttributeKeyBinding(
final AttributeBindingContainer attributeBindingContainer, final AttributeBindingContainer attributeBindingContainer,
final PluralAttributeSource attributeSource ) { final PluralAttributeSource attributeSource ) {
final EntityBinding entityBinding = attributeBindingContainer.seekEntityBinding(); final EntityBinding entityBinding = attributeBindingContainer.seekEntityBinding();
final String referencedAttributeName = attributeSource.getKeySource().getReferencedEntityAttributeName(); final String referencedAttributeName = attributeSource.getKeySource().getReferencedEntityAttributeName();
final AttributeBinding referencedAttributeBinding = final AttributeBinding referencedAttributeBinding =
referencedAttributeName == null referencedAttributeName == null
? entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() ? entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding()
: entityBinding.locateAttributeBinding( referencedAttributeName ); : entityBinding.locateAttributeBinding( referencedAttributeName );
if ( referencedAttributeBinding == null ) { if ( referencedAttributeBinding == null ) {
throw new MappingException( "Plural atttribute key references an attribute binding that does not exist: " + throw new MappingException( "Plural atttribute key references an attribute binding that does not exist: " +
referencedAttributeBinding, bindingContexts.peek().getOrigin() ); referencedAttributeBinding, bindingContexts.peek().getOrigin() );
} }
if ( !referencedAttributeBinding.getAttribute().isSingular() ) { if ( !referencedAttributeBinding.getAttribute().isSingular() ) {
throw new MappingException( "Plural atttribute key references a plural attribute; it must be plural: " + throw new MappingException( "Plural atttribute key references a plural attribute; it must be plural: " +
referencedAttributeName, bindingContexts.peek().getOrigin() ); referencedAttributeName, bindingContexts.peek().getOrigin() );
} }
return ( SingularAttributeBinding ) referencedAttributeBinding; return ( SingularAttributeBinding ) referencedAttributeBinding;
} }
private String propertyAccessorName( final AttributeSource attributeSource ) { private String propertyAccessorName( final AttributeSource attributeSource ) {
return attributeSource.getPropertyAccessorName() == null return attributeSource.getPropertyAccessorName() == null
? bindingContexts.peek().getMappingDefaults().getPropertyAccessorName() ? bindingContexts.peek().getMappingDefaults().getPropertyAccessorName()
: attributeSource.getPropertyAccessorName(); : attributeSource.getPropertyAccessorName();
} }
private String quotedIdentifier( final String name ) { private String quotedIdentifier( final String name ) {
@ -1190,9 +1197,9 @@ public class Binder {
} }
private void resolveHibernateResolvedType( private void resolveHibernateResolvedType(
final HibernateTypeDescriptor hibernateTypeDescriptor, final HibernateTypeDescriptor hibernateTypeDescriptor,
final String typeName, final String typeName,
final AbstractValue value ) { final AbstractValue value ) {
final Properties typeProperties = new Properties(); final Properties typeProperties = new Properties();
typeProperties.putAll( hibernateTypeDescriptor.getTypeParameters() ); typeProperties.putAll( hibernateTypeDescriptor.getTypeParameters() );
final Type resolvedType = metadata.getTypeResolver().heuristicType( typeName, typeProperties ); final Type resolvedType = metadata.getTypeResolver().heuristicType( typeName, typeProperties );
@ -1203,9 +1210,9 @@ public class Binder {
hibernateTypeDescriptor.setJavaTypeName( resolvedType.getReturnedClass().getName() ); hibernateTypeDescriptor.setJavaTypeName( resolvedType.getReturnedClass().getName() );
} }
value.setJdbcDataType( new JdbcDataType( value.setJdbcDataType( new JdbcDataType(
resolvedType.sqlTypes( metadata )[ 0 ], resolvedType.sqlTypes( metadata )[ 0 ],
resolvedType.getName(), resolvedType.getName(),
resolvedType.getReturnedClass() ) ); resolvedType.getReturnedClass() ) );
} }
} }