From: <one...@us...> - 2003-04-18 05:09:54
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister In directory sc8-pr-cvs1:/tmp/cvs-serv16387/hibernate/persister Modified Files: EntityPersister.java NormalizedEntityPersister.java Log Message: * code cleanups * collection where attribute now used for collection removal Index: EntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/EntityPersister.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** EntityPersister.java 6 Apr 2003 02:28:57 -0000 1.24 --- EntityPersister.java 18 Apr 2003 05:09:50 -0000 1.25 *************** *** 52,57 **** /** * The default implementation of the <tt>ClassPersister</tt> interface. ! * Implements the "table-per-class hierarchy" mapping strategy for an entity ! * class.<br> */ public class EntityPersister extends AbstractEntityPersister implements Queryable { --- 52,57 ---- /** * The default implementation of the <tt>ClassPersister</tt> interface. ! * Implements the "table-per-class-hierarchy" mapping strategy for an entity ! * class. */ public class EntityPersister extends AbstractEntityPersister implements Queryable { *************** *** 59,87 **** private final SessionFactoryImplementor factory; private final String qualifiedTableName; private final String[] tableNames; ! private final String deleteString; ! private final String insertString; ! private final String updateString; ! private final String identityInsertString; private final int[] propertyColumnSpans; ! private final boolean[] definedOnSubclass; private final String[][] propertyColumnNames; private final String[][] propertyColumnAliases; - private final String[][] subclassPropertyColumnNameClosure; ! private final String discriminatorColumnName; ! private final boolean forceDiscriminator; private final String[] subclassColumnClosure; private final String[] subclassColumnAliasClosure; private final Type[] subclassPropertyTypeClosure; ! private final Class[] subclassClosure; ! private final boolean hasUpdateableColumns; ! private final int[] joinedFetch; private final HashMap subclassesByDiscriminatorValue = new HashMap(); ! private final DiscriminatorType discriminatorType; private final String discriminatorSQLString; --- 59,95 ---- private final SessionFactoryImplementor factory; + // the class hierarchy structure private final String qualifiedTableName; private final String[] tableNames; + private final boolean hasUpdateableColumns; + private final Class[] subclassClosure; ! // SQL strings ! private final String sqlDeleteString; ! private final String sqlInsertString; ! private final String sqlUpdateString; ! private final String sqlIdentityInsertString; + // properties of this class, including inherited properties private final int[] propertyColumnSpans; ! private final boolean[] propertyDefinedOnSubclass; private final String[][] propertyColumnNames; private final String[][] propertyColumnAliases; ! // the closure of all columns used by the entire hierarchy including ! // subclasses and superclasses of this class private final String[] subclassColumnClosure; private final String[] subclassColumnAliasClosure; + + // the closure of all properties in the entire hierarchy including + // subclasses and superclasses of this class + private final String[][] subclassPropertyColumnNameClosure; private final Type[] subclassPropertyTypeClosure; ! private final int[] subclassPropertyEnableJoinedFetch; + // discriminator column private final HashMap subclassesByDiscriminatorValue = new HashMap(); ! private final boolean forceDiscriminator; ! private final String discriminatorColumnName; private final DiscriminatorType discriminatorType; private final String discriminatorSQLString; *************** *** 163,167 **** public boolean isDefinedOnSubclass(int i) { ! return definedOnSubclass[i]; } --- 171,175 ---- public boolean isDefinedOnSubclass(int i) { ! return propertyDefinedOnSubclass[i]; } *************** *** 171,175 **** public int enableJoinedFetch(int i) { ! return joinedFetch[i]; } --- 179,183 ---- public int enableJoinedFetch(int i) { ! return subclassPropertyEnableJoinedFetch[i]; } *************** *** 227,232 **** * The query that deletes a row by id (and version) */ ! protected final String sqlDelete() { ! return deleteString; } --- 235,240 ---- * The query that deletes a row by id (and version) */ ! protected final String getSQLDeleteString() { ! return sqlDeleteString; } *************** *** 234,239 **** * The query that inserts a row with a given id */ ! protected final String sqlInsert() { ! return insertString; } --- 242,247 ---- * The query that inserts a row with a given id */ ! protected final String getSQLInsertString() { ! return sqlInsertString; } *************** *** 241,246 **** * The query that inserts a row, letting the database generate an id */ ! protected final String sqlIdentityInsert() { ! return identityInsertString; } --- 249,254 ---- * The query that inserts a row, letting the database generate an id */ ! protected final String getSQLIdentityInsertString() { ! return sqlIdentityInsertString; } *************** *** 248,253 **** * The query that updates a row by id (and version) */ ! protected final String sqlUpdate() { ! return updateString; } --- 256,261 ---- * The query that updates a row by id (and version) */ ! protected final String getSQLUpdateString() { ! return sqlUpdateString; } *************** *** 427,431 **** // Render the SQL query ! PreparedStatement statement = session.getBatcher().prepareBatchStatement( sqlInsert() ); try { --- 435,439 ---- // Render the SQL query ! PreparedStatement statement = session.getBatcher().prepareBatchStatement( getSQLInsertString() ); try { *************** *** 458,462 **** // Render the SQL query ! PreparedStatement statement = session.getBatcher().prepareStatement( sqlIdentityInsert() ); try { --- 466,470 ---- // Render the SQL query ! PreparedStatement statement = session.getBatcher().prepareStatement( getSQLIdentityInsertString() ); try { *************** *** 513,520 **** final PreparedStatement statement;// = session.getPreparedStatement( sqlDelete() ); if ( isVersioned() ) { ! statement = session.getBatcher().prepareStatement( sqlDelete() ); } else { ! statement = session.getBatcher().prepareBatchStatement( sqlDelete() ); } --- 521,528 ---- final PreparedStatement statement;// = session.getPreparedStatement( sqlDelete() ); if ( isVersioned() ) { ! statement = session.getBatcher().prepareStatement( getSQLDeleteString() ); } else { ! statement = session.getBatcher().prepareBatchStatement( getSQLDeleteString() ); } *************** *** 564,568 **** } else { ! update(id, fields, getPropertyUpdateability(), oldVersion, object, sqlUpdate(), session); } } --- 572,576 ---- } else { ! update(id, fields, getPropertyUpdateability(), oldVersion, object, getSQLUpdateString(), session); } } *************** *** 729,747 **** subclassColumnAliasClosure = (String[]) aliases.toArray(STRING_ARRAY); ! joinedFetch = new int[ joinedFetchesList.size() ]; iter = joinedFetchesList.iterator(); int j=0; ! while ( iter.hasNext() ) joinedFetch[j++] = ( (Integer) iter.next() ).intValue(); ! definedOnSubclass = new boolean[ definedBySubclass.size() ]; iter = definedBySubclass.iterator(); j=0; ! while ( iter.hasNext() ) definedOnSubclass[j++] = ( (Boolean) iter.next() ).booleanValue(); ! deleteString = generateDeleteString(); ! insertString = generateInsertString( false, getPropertyInsertability() ); ! identityInsertString = isIdentifierAssignedByInsert() ? generateInsertString( true, getPropertyInsertability() ) : null; ! updateString = generateUpdateString( getPropertyUpdateability() ); String lockString = generateLockString(); --- 737,755 ---- subclassColumnAliasClosure = (String[]) aliases.toArray(STRING_ARRAY); ! subclassPropertyEnableJoinedFetch = new int[ joinedFetchesList.size() ]; iter = joinedFetchesList.iterator(); int j=0; ! while ( iter.hasNext() ) subclassPropertyEnableJoinedFetch[j++] = ( (Integer) iter.next() ).intValue(); ! propertyDefinedOnSubclass = new boolean[ definedBySubclass.size() ]; iter = definedBySubclass.iterator(); j=0; ! while ( iter.hasNext() ) propertyDefinedOnSubclass[j++] = ( (Boolean) iter.next() ).booleanValue(); ! sqlDeleteString = generateDeleteString(); ! sqlInsertString = generateInsertString( false, getPropertyInsertability() ); ! sqlIdentityInsertString = isIdentifierAssignedByInsert() ? generateInsertString( true, getPropertyInsertability() ) : null; ! sqlUpdateString = generateUpdateString( getPropertyUpdateability() ); String lockString = generateLockString(); Index: NormalizedEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/persister/NormalizedEntityPersister.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** NormalizedEntityPersister.java 6 Apr 2003 10:11:10 -0000 1.17 --- NormalizedEntityPersister.java 18 Apr 2003 05:09:50 -0000 1.18 *************** *** 60,93 **** private final SessionFactoryImplementor factory; private final String qualifiedTableName; private final String[] tableNames; private final String[][] tableKeyColumns; private final String[] subclassTableNameClosure; private final String[][] subclassTableKeyColumns; private final boolean[] isClassOrSuperclassTable; ! private final String[] deleteStrings; ! private final String[] insertStrings; ! private final String[] identityInsertStrings; ! private final String[] updateStrings; ! private final int[] joinedFetch; private final int[] propertyColumnSpans; private final int[] propertyTables; ! private final boolean[] hasColumns; private final String[][] propertyColumnNames; private final String[][] propertyColumnNameAliases; ! private final boolean[] definedOnSubclass; private final String[][] subclassPropertyColumnNameClosure; private final int[] subclassPropertyTableNumberClosure; private final String[] subclassColumnClosure; private final String[] subclassColumnClosureAliases; private final int[] subclassColumnTableNumberClosure; - private final Type[] subclassPropertyTypeClosure; - private final Class[] subclassClosure; - - private final HashMap tableNumberByPropertyPath = new HashMap(); private final HashMap subclassesByDiscriminatorValue = new HashMap(); private final String[] discriminators; --- 60,105 ---- private final SessionFactoryImplementor factory; + // the class hierarchy structure private final String qualifiedTableName; private final String[] tableNames; private final String[][] tableKeyColumns; + + private final Class[] subclassClosure; private final String[] subclassTableNameClosure; private final String[][] subclassTableKeyColumns; private final boolean[] isClassOrSuperclassTable; ! // SQL strings ! private final String[] sqlDeleteStrings; ! private final String[] sqlInsertStrings; ! private final String[] sqlIdentityInsertStrings; ! private final String[] sqlUpdateStrings; ! // properties of this class, including inherited properties private final int[] propertyColumnSpans; private final int[] propertyTables; ! private final boolean[] propertyHasColumns; private final String[][] propertyColumnNames; private final String[][] propertyColumnNameAliases; ! ! // the closure of all properties in the entire hierarchy including ! // subclasses and superclasses of this class private final String[][] subclassPropertyColumnNameClosure; private final int[] subclassPropertyTableNumberClosure; + private final Type[] subclassPropertyTypeClosure; + private final int[] subclassPropertyEnableJoinedFetch; + private final boolean[] propertyDefinedOnSubclass; + private final HashMap tableNumberByPropertyPath = new HashMap(); + + // the closure of all columns used by the entire hierarchy including + // subclasses and superclasses of this class private final String[] subclassColumnClosure; private final String[] subclassColumnClosureAliases; private final int[] subclassColumnTableNumberClosure; + // subclass discrimination works by assigning particular + // values to certain combinations of null primary key + // values in the outer join using an SQL CASE private final HashMap subclassesByDiscriminatorValue = new HashMap(); private final String[] discriminators; *************** *** 100,106 **** protected UniqueEntityLoader loader; - //protected final Map loaders = new HashMap(); protected final Map lockers = new HashMap(); private static final String[] STRING_ARRAY = {}; private static final Type[] TYPE_ARRAY = {}; --- 112,119 ---- protected UniqueEntityLoader loader; protected final Map lockers = new HashMap(); + private final boolean[] allProperties; + private static final String[] STRING_ARRAY = {}; private static final Type[] TYPE_ARRAY = {}; *************** *** 158,162 **** public boolean isDefinedOnSubclass(int i) { ! return definedOnSubclass[i]; } --- 171,175 ---- public boolean isDefinedOnSubclass(int i) { ! return propertyDefinedOnSubclass[i]; } *************** *** 201,205 **** public int enableJoinedFetch(int i) { ! return joinedFetch[i]; } --- 214,218 ---- public int enableJoinedFetch(int i) { ! return subclassPropertyEnableJoinedFetch[i]; } *************** *** 215,243 **** /** ! * The query that deletes a row by id (and version) */ ! protected final String[] sqlDelete() { ! return deleteStrings; } /** ! * The query that inserts a row with a given id */ ! protected final String[] sqlInsert() { ! return insertStrings; } /** ! * The query that inserts a row, letting the database generate an id */ ! protected final String[] sqlIdentityInsert() { ! return identityInsertStrings; } /** ! * The query that updates a row by id (and version) */ ! protected final String[] sqlUpdate() { ! return updateStrings; } --- 228,256 ---- /** ! * The queries that delete rows by id (and version) */ ! protected final String[] getSQLDeleteStrings() { ! return sqlDeleteStrings; } /** ! * The queries that insert rows with a given id */ ! protected final String[] getSQLInsertStrings() { ! return sqlInsertStrings; } /** ! * The queries that insert rows, letting the database generate an id */ ! protected final String[] getSQLIdentityInsertStrings() { ! return sqlIdentityInsertStrings; } /** ! * The queries that update rows by id (and version) */ ! protected final String[] getSQLUpdateStrings() { ! return sqlUpdateStrings; } *************** *** 245,249 **** /** ! * Generate the SQL that deletes a row by id (and version) */ protected String[] generateDeleteStrings() { --- 258,262 ---- /** ! * Generate the SQL that deletes rows by id (and version) */ protected String[] generateDeleteStrings() { *************** *** 260,264 **** /** ! * Generate the SQL that inserts a row */ protected String[] generateInsertStrings(boolean identityInsert, boolean[] includeProperty) { --- 273,277 ---- /** ! * Generate the SQL that inserts rows */ protected String[] generateInsertStrings(boolean identityInsert, boolean[] includeProperty) { *************** *** 290,294 **** /** ! * Generate the SQL that updates a row by id (and version) */ protected String[] generateUpdateStrings(boolean[] includeProperty) { --- 303,307 ---- /** ! * Generate the SQL that updates rows by id (and version) */ protected String[] generateUpdateStrings(boolean[] includeProperty) { *************** *** 426,436 **** } - //TODO: precalculate this - private boolean[] allProperties() { - boolean[] result = new boolean[hydrateSpan]; - Arrays.fill(result, true); - return result; - } - /** * Persist an object --- 439,442 ---- *************** *** 448,452 **** for ( int i=0; i<tableNames.length; i++ ) { ! statements[i] = session.getBatcher().prepareStatement( sqlInsert()[i] ); } --- 454,458 ---- for ( int i=0; i<tableNames.length; i++ ) { ! statements[i] = session.getBatcher().prepareStatement( getSQLInsertStrings()[i] ); } *************** *** 481,489 **** } ! String[] sql = sqlIdentityInsert(); PreparedStatement statement = session.getBatcher().prepareStatement( sql[0] ); try { ! dehydrate(null, fields, allProperties(), 0, statement, session); statement.executeUpdate(); } --- 487,495 ---- } ! String[] sql = getSQLIdentityInsertStrings(); PreparedStatement statement = session.getBatcher().prepareStatement( sql[0] ); try { ! dehydrate(null, fields, allProperties, 0, statement, session); statement.executeUpdate(); } *************** *** 525,529 **** try { ! dehydrate(id, fields, allProperties(), i, statement, session); statement.executeUpdate(); } --- 531,535 ---- try { ! dehydrate(id, fields, allProperties, i, statement, session); statement.executeUpdate(); } *************** *** 556,560 **** for ( int i=0; i<tableNames.length; i++ ) { ! statements[i] = session.getBatcher().prepareStatement( sqlDelete()[i] ); } --- 562,566 ---- for ( int i=0; i<tableNames.length; i++ ) { ! statements[i] = session.getBatcher().prepareStatement( getSQLDeleteStrings()[i] ); } *************** *** 591,595 **** boolean[] tableUpdateNeeded; if (dirtyFields==null) { ! tableUpdateNeeded = hasColumns; // for objects that came in via update() } else { --- 597,601 ---- boolean[] tableUpdateNeeded; if (dirtyFields==null) { ! tableUpdateNeeded = propertyHasColumns; // for objects that came in via update() } else { *************** *** 613,617 **** } else { ! update(id, fields, getPropertyUpdateability(), tableUpdateNeeded, oldVersion, object, sqlUpdate(), session); } } --- 619,623 ---- } else { ! update(id, fields, getPropertyUpdateability(), tableUpdateNeeded, oldVersion, object, getSQLUpdateStrings(), session); } } *************** *** 811,827 **** subclassPropertyColumnNameClosure = (String[][]) propColumns.toArray( new String[ propColumns.size() ][] ); ! joinedFetch = new int[ joinedFetchesList.size() ]; iter = joinedFetchesList.iterator(); int j=0; ! while ( iter.hasNext() ) joinedFetch[j++] = ( (Integer) iter.next() ).intValue(); ! definedOnSubclass = new boolean[ definedBySubclass.size() ]; iter = definedBySubclass.iterator(); j=0; ! while ( iter.hasNext() ) definedOnSubclass[j++] = ( (Boolean) iter.next() ).booleanValue(); ! deleteStrings = generateDeleteStrings(); ! insertStrings = generateInsertStrings( false, getPropertyInsertability() ); ! identityInsertStrings = isIdentifierAssignedByInsert() ? generateInsertStrings( true, getPropertyInsertability() ) : null; ! updateStrings = generateUpdateStrings( getPropertyUpdateability() ); String lockString = generateLockString(); --- 817,833 ---- subclassPropertyColumnNameClosure = (String[][]) propColumns.toArray( new String[ propColumns.size() ][] ); ! subclassPropertyEnableJoinedFetch = new int[ joinedFetchesList.size() ]; iter = joinedFetchesList.iterator(); int j=0; ! while ( iter.hasNext() ) subclassPropertyEnableJoinedFetch[j++] = ( (Integer) iter.next() ).intValue(); ! propertyDefinedOnSubclass = new boolean[ definedBySubclass.size() ]; iter = definedBySubclass.iterator(); j=0; ! while ( iter.hasNext() ) propertyDefinedOnSubclass[j++] = ( (Boolean) iter.next() ).booleanValue(); ! sqlDeleteStrings = generateDeleteStrings(); ! sqlInsertStrings = generateInsertStrings( false, getPropertyInsertability() ); ! sqlIdentityInsertStrings = isIdentifierAssignedByInsert() ? generateInsertStrings( true, getPropertyInsertability() ) : null; ! sqlUpdateStrings = generateUpdateStrings( getPropertyUpdateability() ); String lockString = generateLockString(); *************** *** 880,887 **** } ! hasColumns = new boolean[updateStrings.length]; ! for ( int m=0; m<updateStrings.length; m++ ) { ! hasColumns[m] = updateStrings[m]!=null; } } --- 886,896 ---- } ! propertyHasColumns = new boolean[sqlUpdateStrings.length]; ! for ( int m=0; m<sqlUpdateStrings.length; m++ ) { ! propertyHasColumns[m] = sqlUpdateStrings[m]!=null; } + + allProperties = new boolean[hydrateSpan]; + Arrays.fill(allProperties, true); } *************** *** 964,968 **** // work on some dbs. Also it doesn't work if there // are multiple columns of results because it ! // is not accounting for the suffix. // return new String[] { getDiscriminatorColumnName() }; --- 973,977 ---- // work on some dbs. Also it doesn't work if there // are multiple columns of results because it ! // is not accounting for the suffix: // return new String[] { getDiscriminatorColumnName() }; |