diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 06e8291715..c8a87aa48b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -96,7 +96,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { private final boolean[] subclassTableSequentialSelect; private final boolean[] subclassTableIsLazyClosure; - + // subclass discrimination works by assigning particular // values to certain combinations of null primary key // values in the outer join using an SQL CASE @@ -110,9 +110,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { private final String discriminatorSQLString; - //Span of the tables directly mapped by this entity and super-classes, if any + // Span of the tables directly mapped by this entity and super-classes, if any private final int coreTableSpan; - // only contains values for SecondaryTables ie. not tables part of the "coreTableSpan" + // only contains values for SecondaryTables, ie. not tables part of the "coreTableSpan" private final boolean[] isNullableTable; //INITIALIZATION: @@ -133,8 +133,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { discriminatorValue = new Integer( persistentClass.getSubclassId() ); discriminatorSQLString = discriminatorValue.toString(); } - catch (Exception e) { - throw new MappingException("Could not format discriminator value to SQL string", e ); + catch ( Exception e ) { + throw new MappingException( "Could not format discriminator value to SQL string", e ); } } else { @@ -165,136 +165,135 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); - tables.add(tabname); + tables.add( tabname ); String[] keyCols = new String[idColumnSpan]; String[] keyColReaders = new String[idColumnSpan]; String[] keyColReaderTemplates = new String[idColumnSpan]; Iterator citer = key.getColumnIterator(); - for ( int k=0; k= 0 ; i--, currentPosition++ ) { + for ( int i = naturalOrderSubclassTableNameClosure.length - 1; i >= 0; i--, currentPosition++ ) { constraintOrderedTableNames[currentPosition] = naturalOrderSubclassTableNameClosure[i]; constraintOrderedKeyColumnNames[currentPosition] = naturalOrderSubclassTableKeyColumnClosure[i]; - } + } /** * Suppose an entity Client extends Person, mapped to the tables CLIENT and PERSON respectively. @@ -305,15 +304,15 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { * the first table as it will the driving table. * tableNames -> CLIENT, PERSON */ - + tableSpan = naturalOrderTableNames.length; - tableNames = reverse(naturalOrderTableNames, coreTableSpan); - tableKeyColumns = reverse(naturalOrderTableKeyColumns, coreTableSpan); - tableKeyColumnReaders = reverse(naturalOrderTableKeyColumnReaders, coreTableSpan); - tableKeyColumnReaderTemplates = reverse(naturalOrderTableKeyColumnReaderTemplates, coreTableSpan); - subclassTableNameClosure = reverse(naturalOrderSubclassTableNameClosure, coreTableSpan); - subclassTableKeyColumnClosure = reverse(naturalOrderSubclassTableKeyColumnClosure, coreTableSpan); - + tableNames = reverse( naturalOrderTableNames, coreTableSpan ); + tableKeyColumns = reverse( naturalOrderTableKeyColumns, coreTableSpan ); + tableKeyColumnReaders = reverse( naturalOrderTableKeyColumnReaders, coreTableSpan ); + tableKeyColumnReaderTemplates = reverse( naturalOrderTableKeyColumnReaderTemplates, coreTableSpan ); + subclassTableNameClosure = reverse( naturalOrderSubclassTableNameClosure, coreTableSpan ); + subclassTableKeyColumnClosure = reverse( naturalOrderSubclassTableKeyColumnClosure, coreTableSpan ); + spaces = ArrayHelper.join( tableNames, ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() ) @@ -331,71 +330,71 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan]; PersistentClass pc = persistentClass; - int jk = coreTableSpan-1; - while (pc!=null) { + int jk = coreTableSpan - 1; + while ( pc != null ) { customSQLInsert[jk] = pc.getCustomSQLInsert(); insertCallable[jk] = customSQLInsert[jk] != null && pc.isCustomInsertCallable(); insertResultCheckStyles[jk] = pc.getCustomSQLInsertCheckStyle() == null - ? ExecuteUpdateResultCheckStyle.determineDefault( + ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[jk], insertCallable[jk] ) - : pc.getCustomSQLInsertCheckStyle(); + : pc.getCustomSQLInsertCheckStyle(); customSQLUpdate[jk] = pc.getCustomSQLUpdate(); updateCallable[jk] = customSQLUpdate[jk] != null && pc.isCustomUpdateCallable(); updateResultCheckStyles[jk] = pc.getCustomSQLUpdateCheckStyle() == null - ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[jk], updateCallable[jk] ) - : pc.getCustomSQLUpdateCheckStyle(); + ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[jk], updateCallable[jk] ) + : pc.getCustomSQLUpdateCheckStyle(); customSQLDelete[jk] = pc.getCustomSQLDelete(); deleteCallable[jk] = customSQLDelete[jk] != null && pc.isCustomDeleteCallable(); deleteResultCheckStyles[jk] = pc.getCustomSQLDeleteCheckStyle() == null - ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[jk], deleteCallable[jk] ) - : pc.getCustomSQLDeleteCheckStyle(); + ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[jk], deleteCallable[jk] ) + : pc.getCustomSQLDeleteCheckStyle(); jk--; pc = pc.getSuperclass(); } - + if ( jk != -1 ) { throw new AssertionFailure( "Tablespan does not match height of joined-subclass hiearchy." ); } - + joinIter = persistentClass.getJoinClosureIterator(); int j = coreTableSpan; while ( joinIter.hasNext() ) { Join join = (Join) joinIter.next(); - + customSQLInsert[j] = join.getCustomSQLInsert(); insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable(); insertResultCheckStyles[j] = join.getCustomSQLInsertCheckStyle() == null - ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] ) - : join.getCustomSQLInsertCheckStyle(); + ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] ) + : join.getCustomSQLInsertCheckStyle(); customSQLUpdate[j] = join.getCustomSQLUpdate(); updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable(); updateResultCheckStyles[j] = join.getCustomSQLUpdateCheckStyle() == null - ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] ) - : join.getCustomSQLUpdateCheckStyle(); + ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] ) + : join.getCustomSQLUpdateCheckStyle(); customSQLDelete[j] = join.getCustomSQLDelete(); deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable(); deleteResultCheckStyles[j] = join.getCustomSQLDeleteCheckStyle() == null - ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] ) - : join.getCustomSQLDeleteCheckStyle(); + ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] ) + : join.getCustomSQLDeleteCheckStyle(); j++; } - + // PROPERTIES int hydrateSpan = getPropertySpan(); naturalOrderPropertyTableNumbers = new int[hydrateSpan]; propertyTableNumbers = new int[hydrateSpan]; Iterator iter = persistentClass.getPropertyClosureIterator(); - int i=0; - while( iter.hasNext() ) { + int i = 0; + while ( iter.hasNext() ) { Property prop = (Property) iter.next(); String tabname = prop.getValue().getTable().getQualifiedName( - factory.getDialect(), - factory.getSettings().getDefaultCatalogName(), - factory.getSettings().getDefaultSchemaName() + factory.getDialect(), + factory.getSettings().getDefaultCatalogName(), + factory.getSettings().getDefaultSchemaName() ); - propertyTableNumbers[i] = getTableId(tabname, tableNames); - naturalOrderPropertyTableNumbers[i] = getTableId(tabname, naturalOrderTableNames); + propertyTableNumbers[i] = getTableId( tabname, tableNames ); + naturalOrderPropertyTableNumbers[i] = getTableId( tabname, naturalOrderTableNames ); i++; } @@ -416,47 +415,47 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); - Integer tabnum = new Integer( getTableId(tabname, subclassTableNameClosure) ); - propTableNumbers.add(tabnum); + Integer tabnum = new Integer( getTableId( tabname, subclassTableNameClosure ) ); + propTableNumbers.add( tabnum ); Iterator citer = prop.getColumnIterator(); while ( citer.hasNext() ) { Selectable thing = (Selectable) citer.next(); if ( thing.isFormula() ) { - formulaTableNumbers.add(tabnum); + formulaTableNumbers.add( tabnum ); } else { - columnTableNumbers.add(tabnum); + columnTableNumbers.add( tabnum ); } } } - subclassColumnTableNumberClosure = ArrayHelper.toIntArray(columnTableNumbers); - subclassPropertyTableNumberClosure = ArrayHelper.toIntArray(propTableNumbers); - subclassFormulaTableNumberClosure = ArrayHelper.toIntArray(formulaTableNumbers); + subclassColumnTableNumberClosure = ArrayHelper.toIntArray( columnTableNumbers ); + subclassPropertyTableNumberClosure = ArrayHelper.toIntArray( propTableNumbers ); + subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaTableNumbers ); // SUBCLASSES - + int subclassSpan = persistentClass.getSubclassSpan() + 1; subclassClosure = new String[subclassSpan]; - subclassClosure[subclassSpan-1] = getEntityName(); + subclassClosure[subclassSpan - 1] = getEntityName(); if ( persistentClass.isPolymorphic() ) { subclassesByDiscriminatorValue.put( discriminatorValue, getEntityName() ); discriminatorValues = new String[subclassSpan]; - discriminatorValues[subclassSpan-1] = discriminatorSQLString; + discriminatorValues[subclassSpan - 1] = discriminatorSQLString; notNullColumnTableNumbers = new int[subclassSpan]; final int id = getTableId( - persistentClass.getTable().getQualifiedName( - factory.getDialect(), - factory.getSettings().getDefaultCatalogName(), - factory.getSettings().getDefaultSchemaName() - ), - subclassTableNameClosure + persistentClass.getTable().getQualifiedName( + factory.getDialect(), + factory.getSettings().getDefaultCatalogName(), + factory.getSettings().getDefaultSchemaName() + ), + subclassTableNameClosure ); - notNullColumnTableNumbers[subclassSpan-1] = id; + notNullColumnTableNumbers[subclassSpan - 1] = id; notNullColumnNames = new String[subclassSpan]; - notNullColumnNames[subclassSpan-1] = subclassTableKeyColumnClosure[id][0]; //( (Column) model.getTable().getPrimaryKey().getColumnIterator().next() ).getName(); + notNullColumnNames[subclassSpan - 1] = subclassTableKeyColumnClosure[id][0]; //( (Column) model.getTable().getPrimaryKey().getColumnIterator().next() ).getName(); } else { discriminatorValues = null; @@ -465,7 +464,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } iter = persistentClass.getSubclassIterator(); - int k=0; + int k = 0; while ( iter.hasNext() ) { Subclass sc = (Subclass) iter.next(); subclassClosure[k] = sc.getEntityName(); @@ -478,28 +477,28 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { subclassesByDiscriminatorValue.put( subclassId, sc.getEntityName() ); discriminatorValues[k] = subclassId.toString(); int id = getTableId( - sc.getTable().getQualifiedName( - factory.getDialect(), - factory.getSettings().getDefaultCatalogName(), - factory.getSettings().getDefaultSchemaName() - ), - subclassTableNameClosure + sc.getTable().getQualifiedName( + factory.getDialect(), + factory.getSettings().getDefaultCatalogName(), + factory.getSettings().getDefaultSchemaName() + ), + subclassTableNameClosure ); notNullColumnTableNumbers[k] = id; notNullColumnNames[k] = subclassTableKeyColumnClosure[id][0]; //( (Column) sc.getTable().getPrimaryKey().getColumnIterator().next() ).getName(); } } - catch (Exception e) { - throw new MappingException("Error parsing discriminator value", e ); + catch ( Exception e ) { + throw new MappingException( "Error parsing discriminator value", e ); } k++; } initLockers(); - initSubclassPropertyAliasesMap(persistentClass); + initSubclassPropertyAliasesMap( persistentClass ); - postConstruct(mapping); + postConstruct( mapping ); } @@ -523,7 +522,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { spaces = null; subclassClosure = null; subclassTableNameClosure = null; - subclassTableKeyColumnClosure= null; + subclassTableKeyColumnClosure = null; isClassOrSuperclassTable = null; naturalOrderPropertyTableNumbers = null; propertyTableNumbers = null; @@ -543,16 +542,16 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } protected boolean isNullableTable(int j) { - if (j < coreTableSpan) - return false; - return isNullableTable[j-coreTableSpan]; + if ( j < coreTableSpan ) { + return false; + } + return isNullableTable[j - coreTableSpan]; } protected boolean isSubclassTableSequentialSelect(int j) { return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j]; } - - + /*public void postInstantiate() throws MappingException { super.postInstantiate(); //TODO: other lock modes? @@ -560,7 +559,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { }*/ public String getSubclassPropertyTableName(int i) { - return subclassTableNameClosure[ subclassPropertyTableNumberClosure[i] ]; + return subclassTableNameClosure[subclassPropertyTableNumberClosure[i]]; } public Type getDiscriminatorType() { @@ -573,7 +572,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { public String getSubclassForDiscriminatorValue(Object value) { - return (String) subclassesByDiscriminatorValue.get(value); + return (String) subclassesByDiscriminatorValue.get( value ); } public Serializable[] getPropertySpaces() { @@ -594,7 +593,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { } protected boolean isPropertyOfTable(int property, int j) { - return naturalOrderPropertyTableNumbers[property]==j; + return naturalOrderPropertyTableNumbers[property] == j; } /** @@ -622,62 +621,64 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { throw new JDBCException( "could not load by id: " + MessageHelper.infoString(this, id), sqle ); } }*/ - private static final void reverse(Object[] objects, int len) { Object[] temp = new Object[len]; - for (int i=0; i