Iterator itr = node.elementIterator();
int count = 0;
while ( itr.hasNext() ) {
Element columnElement = (Element) itr.next();
if ( columnElement.getName().equals( "column" ) ) {
Column column = new Column();
column.setValue( simpleValue );
column.setTypeIndex( count++ );
bindColumn( columnElement, column, isNullable );
final String columnName = columnElement.attributeValue( "name" );
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
columnName, propertyPath
);
column.setName( mappings.getNamingStrategy().columnName(
columnName ) );
if ( table != null ) {
table.addColumn( column ); // table=null -> an association
// - fill it in later
//TODO fill in the mappings for table == null
mappings.addColumnBinding( logicalColumnName, column, table );
}
simpleValue.addColumn( column );
// column index
bindIndex( columnElement.attribute( "index" ), table, column, mappings );
bindIndex( node.attribute( "index" ), table, column, mappings );
//column unique-key
bindUniqueKey( columnElement.attribute( "unique-key" ), table, column, mappings );
bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
}
else if ( columnElement.getName().equals( "formula" ) ) {
Formula formula = new Formula();
formula.setFormula( columnElement.getText() );
simpleValue.addFormula( formula );
}
}
// todo : another GoodThing would be to go back after all parsing and see if all the columns
// (and no formulas) are contained in a defined unique key that only contains these columns.
// That too would mark this as a logical one-to-one
final Attribute uniqueAttribute = node.attribute( "unique" );
if ( uniqueAttribute != null
&& "true".equals( uniqueAttribute.getValue() )
&& ManyToOne.class.isInstance( simpleValue ) ) {
( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
}
}
else {
if ( node.elementIterator( "column" ).hasNext() ) {
throw new MappingException(
"column attribute may not be used together with <column> subelement" );
}
if ( node.elementIterator( "formula" ).hasNext() ) {
throw new MappingException(
"column attribute may not be used together with <formula> subelement" );
}
Column column = new Column();
column.setValue( simpleValue );
bindColumn( node, column, isNullable );
if ( column.isUnique() && ManyToOne.class.isInstance( simpleValue ) ) {
( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
}
final String columnName = columnAttribute.getValue();
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
columnName, propertyPath
);
column.setName( mappings.getNamingStrategy().columnName( columnName ) );
if ( table != null ) {
table.addColumn( column ); // table=null -> an association - fill
// it in later
//TODO fill in the mappings for table == null
mappings.addColumnBinding( logicalColumnName, column, table );
}
simpleValue.addColumn( column );
bindIndex( node.attribute( "index" ), table, column, mappings );
bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
}
if ( autoColumn && simpleValue.getColumnSpan() == 0 ) {
Column column = new Column();
column.setValue( simpleValue );
bindColumn( node, column, isNullable );
column.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) );
String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath );
mappings.addColumnBinding( logicalName, column, table );
/* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a
* slightly higer level in the stack (to get all the information we need)
* Right now HbmBinder does not support the