if ( ! attributeBinding.getAttribute().isSingular() ) {
// collections handled separately
continue;
}
final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding;
thisClassProperties.add( singularAttributeBinding );
propertySubclassNames[i] = ( (EntityBinding) singularAttributeBinding.getContainer() ).getEntity().getName();
int span = singularAttributeBinding.getSimpleValueSpan();
propertyColumnSpans[i] = span;
String[] colNames = new String[span];
String[] colAliases = new String[span];
String[] colReaderTemplates = new String[span];
String[] colWriters = new String[span];
String[] formulaTemplates = new String[span];
boolean[] propertyColumnInsertability = new boolean[span];
boolean[] propertyColumnUpdatability = new boolean[span];
int k = 0;
for ( SimpleValueBinding valueBinding : singularAttributeBinding.getSimpleValueBindings() ) {
colAliases[k] = valueBinding.getSimpleValue().getAlias( factory.getDialect() );
if ( valueBinding.isDerived() ) {
foundFormula = true;
formulaTemplates[ k ] = getTemplateFromString( ( (DerivedValue) valueBinding.getSimpleValue() ).getExpression(), factory );
}
else {
org.hibernate.metamodel.relational.Column col = ( org.hibernate.metamodel.relational.Column ) valueBinding.getSimpleValue();
colNames[k] = col.getColumnName().encloseInQuotesIfQuoted( factory.getDialect() );
colReaderTemplates[k] = getTemplateFromColumn( col, factory );
colWriters[k] = col.getWriteFragment() == null ? "?" : col.getWriteFragment();
}
propertyColumnInsertability[k] = valueBinding.isIncludeInInsert();
propertyColumnUpdatability[k] = valueBinding.isIncludeInUpdate();
k++;
}
propertyColumnNames[i] = colNames;
propertyColumnFormulaTemplates[i] = formulaTemplates;
propertyColumnReaderTemplates[i] = colReaderTemplates;
propertyColumnWriters[i] = colWriters;
propertyColumnAliases[i] = colAliases;
propertyColumnUpdateable[i] = propertyColumnUpdatability;
propertyColumnInsertable[i] = propertyColumnInsertability;
if ( lazyAvailable && singularAttributeBinding.isLazy() ) {
lazyProperties.add( singularAttributeBinding.getAttribute().getName() );
lazyNames.add( singularAttributeBinding.getAttribute().getName() );
lazyNumbers.add( i );
lazyTypes.add( singularAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping());
lazyColAliases.add( colAliases );
}
// TODO: fix this when backrefs are working
//propertySelectable[i] = singularAttributeBinding.isBackRef();
propertySelectable[i] = true;
propertyUniqueness[i] = singularAttributeBinding.isAlternateUniqueKey();
// TODO: Does this need AttributeBindings wired into lobProperties? Currently in Property only.
i++;
}
hasFormulaProperties = foundFormula;
lazyPropertyColumnAliases = ArrayHelper.to2DStringArray( lazyColAliases );
lazyPropertyNames = ArrayHelper.toStringArray( lazyNames );
lazyPropertyNumbers = ArrayHelper.toIntArray( lazyNumbers );
lazyPropertyTypes = ArrayHelper.toTypeArray( lazyTypes );
// SUBCLASS PROPERTY CLOSURE
List<String> columns = new ArrayList<String>();
List<Boolean> columnsLazy = new ArrayList<Boolean>();
List<String> columnReaderTemplates = new ArrayList<String>();
List<String> aliases = new ArrayList<String>();
List<String> formulas = new ArrayList<String>();
List<String> formulaAliases = new ArrayList<String>();
List<String> formulaTemplates = new ArrayList<String>();
List<Boolean> formulasLazy = new ArrayList<Boolean>();
List<Type> types = new ArrayList<Type>();
List<String> names = new ArrayList<String>();
List<String> classes = new ArrayList<String>();
List<String[]> templates = new ArrayList<String[]>();
List<String[]> propColumns = new ArrayList<String[]>();
List<String[]> propColumnReaders = new ArrayList<String[]>();
List<String[]> propColumnReaderTemplates = new ArrayList<String[]>();
List<FetchMode> joinedFetchesList = new ArrayList<FetchMode>();
List<CascadeStyle> cascades = new ArrayList<CascadeStyle>();
List<Boolean> definedBySubclass = new ArrayList<Boolean>();
List<int[]> propColumnNumbers = new ArrayList<int[]>();
List<int[]> propFormulaNumbers = new ArrayList<int[]>();
List<Boolean> columnSelectables = new ArrayList<Boolean>();
List<Boolean> propNullables = new ArrayList<Boolean>();
for ( AttributeBinding attributeBinding : entityBinding.getSubEntityAttributeBindingClosure() ) {
if ( attributeBinding == entityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding() ) {
// entity identifier is not considered a "normal" property
continue;
}
if ( ! attributeBinding.getAttribute().isSingular() ) {
// collections handled separately
continue;
}
final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding;
names.add( singularAttributeBinding.getAttribute().getName() );
classes.add( ( (EntityBinding) singularAttributeBinding.getContainer() ).getEntity().getName() );
boolean isDefinedBySubclass = ! thisClassProperties.contains( singularAttributeBinding );
definedBySubclass.add( isDefinedBySubclass );
propNullables.add( singularAttributeBinding.isNullable() || isDefinedBySubclass ); //TODO: is this completely correct?
types.add( singularAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping() );
final int span = singularAttributeBinding.getSimpleValueSpan();
String[] cols = new String[ span ];
String[] readers = new String[ span ];
String[] readerTemplates = new String[ span ];
String[] forms = new String[ span ];
int[] colnos = new int[ span ];
int[] formnos = new int[ span ];
int l = 0;
Boolean lazy = singularAttributeBinding.isLazy() && lazyAvailable;
for ( SimpleValueBinding valueBinding : singularAttributeBinding.getSimpleValueBindings() ) {
if ( valueBinding.isDerived() ) {
DerivedValue derivedValue = DerivedValue.class.cast( valueBinding.getSimpleValue() );
String template = getTemplateFromString( derivedValue.getExpression(), factory );
formnos[l] = formulaTemplates.size();
colnos[l] = -1;
formulaTemplates.add( template );
forms[l] = template;
formulas.add( derivedValue.getExpression() );
formulaAliases.add( derivedValue.getAlias( factory.getDialect() ) );
formulasLazy.add( lazy );
}
else {
org.hibernate.metamodel.relational.Column col = org.hibernate.metamodel.relational.Column.class.cast( valueBinding.getSimpleValue() );
String colName = col.getColumnName().encloseInQuotesIfQuoted( factory.getDialect() );
colnos[l] = columns.size(); //before add :-)
formnos[l] = -1;
columns.add( colName );
cols[l] = colName;
aliases.add( col.getAlias( factory.getDialect() ) );
columnsLazy.add( lazy );
// TODO: properties only selectable if they are non-plural???
columnSelectables.add( singularAttributeBinding.getAttribute().isSingular() );
readers[l] =
col.getReadFragment() == null ?
col.getColumnName().encloseInQuotesIfQuoted( factory.getDialect() ) :
col.getReadFragment();
String readerTemplate = getTemplateFromColumn( col, factory );
readerTemplates[l] = readerTemplate;
columnReaderTemplates.add( readerTemplate );
}
l++;
}
propColumns.add( cols );
propColumnReaders.add( readers );
propColumnReaderTemplates.add( readerTemplates );
templates.add( forms );
propColumnNumbers.add( colnos );
propFormulaNumbers.add( formnos );
if ( singularAttributeBinding.isAssociation() ) {
AssociationAttributeBinding associationAttributeBinding =
( AssociationAttributeBinding ) singularAttributeBinding;
cascades.add( associationAttributeBinding.getCascadeStyle() );
joinedFetchesList.add( associationAttributeBinding.getFetchMode() );
}