From: <ste...@us...> - 2006-02-09 20:48:51
|
Update of /cvsroot/hibernate/Hibernate3/src/org/hibernate/persister/entity In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7349/src/org/hibernate/persister/entity Modified Files: AbstractEntityPersister.java EntityPersister.java Log Message: HHH-1457 : JBossCache 1.3.0 optimistic locking support Index: AbstractEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- AbstractEntityPersister.java 3 Feb 2006 22:08:24 -0000 1.26 +++ AbstractEntityPersister.java 9 Feb 2006 20:48:42 -0000 1.27 @@ -14,6 +14,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.Comparator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -290,7 +291,9 @@ } String[] result = new String[getTableSpan()]; result[0] = sqlUpdateByRowIdString; - for ( int i = 1; i < getTableSpan(); i++ ) result[i] = sqlUpdateStrings[i]; + for ( int i = 1; i < getTableSpan(); i++ ) { + result[i] = sqlUpdateStrings[i]; + } return result; } @@ -300,7 +303,9 @@ } String[] result = new String[getTableSpan()]; result[0] = sqlLazyUpdateByRowIdString; - for ( int i = 1; i < getTableSpan(); i++ ) result[i] = sqlLazyUpdateStrings[i]; + for ( int i = 1; i < getTableSpan(); i++ ) { + result[i] = sqlLazyUpdateStrings[i]; + } return result; } @@ -420,7 +425,9 @@ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int batch = persistentClass.getBatchSize(); - if (batch==-1) batch = factory.getSettings().getDefaultBatchFetchSize(); + if ( batch == -1 ) { + batch = factory.getSettings().getDefaultBatchFetchSize(); + } batchSize = batch; hasSubselectLoadableCollections = persistentClass.hasSubselectLoadableCollections(); @@ -631,16 +638,22 @@ subclassPropertyCascadeStyleClosure = new CascadeStyle[cascades.size()]; iter = cascades.iterator(); int j = 0; - while ( iter.hasNext() ) subclassPropertyCascadeStyleClosure[j++] = ( CascadeStyle ) iter.next(); + while ( iter.hasNext() ) { + subclassPropertyCascadeStyleClosure[j++] = ( CascadeStyle ) iter.next(); + } subclassPropertyFetchModeClosure = new FetchMode[joinedFetchesList.size()]; iter = joinedFetchesList.iterator(); j = 0; - while ( iter.hasNext() ) subclassPropertyFetchModeClosure[j++] = ( FetchMode ) iter.next(); + while ( iter.hasNext() ) { + subclassPropertyFetchModeClosure[j++] = ( FetchMode ) iter.next(); + } propertyDefinedOnSubclass = new boolean[definedBySubclass.size()]; iter = definedBySubclass.iterator(); j = 0; - while ( iter.hasNext() ) propertyDefinedOnSubclass[j++] = ( ( Boolean ) iter.next() ).booleanValue(); + while ( iter.hasNext() ) { + propertyDefinedOnSubclass[j++] = ( ( Boolean ) iter.next() ).booleanValue(); + } // Handle any filters applied to the class level filterHelper = new FilterHelper( persistentClass.getFilterMap(), factory.getDialect() ); @@ -651,7 +664,9 @@ protected String generateLazySelectString() { - if ( !entityMetamodel.hasLazyProperties() ) return null; + if ( !entityMetamodel.hasLazyProperties() ) { + return null; + } HashSet tableNumbers = new HashSet(); ArrayList columnNumbers = new ArrayList(); @@ -761,10 +776,14 @@ result = propValue; } } - if (rs!=null) rs.close(); + if ( rs != null ) { + rs.close(); + } } finally { - if (ps!=null) session.getBatcher().closeStatement(ps); + if ( ps != null ) { + session.getBatcher().closeStatement( ps ); + } } log.trace( "done initializing lazy properties" ); @@ -959,9 +978,13 @@ } } - if ( entityMetamodel.hasSubclasses() ) addDiscriminatorToSelect( select, name, suffix ); + if ( entityMetamodel.hasSubclasses() ) { + addDiscriminatorToSelect( select, name, suffix ); + } - if ( hasRowId() ) select.addColumn( name, rowIdName, ROWID_ALIAS ); + if ( hasRowId() ) { + select.addColumn( name, rowIdName, ROWID_ALIAS ); + } return select.toFragmentString(); } @@ -981,7 +1004,9 @@ ResultSet rs = ps.executeQuery(); try { //if there is no resulting row, return null - if ( !rs.next() ) return null; + if ( !rs.next() ) { + return null; + } //otherwise return the "hydrated" state (ie. associations are not resolved) Type[] types = getPropertyTypes(); @@ -1136,7 +1161,9 @@ if ( log.isTraceEnabled() ) { log.trace( "Locking entity: " + MessageHelper.infoString( this, id, getFactory() ) ); - if ( isVersioned() ) log.trace( "Version: " + version ); + if ( isVersioned() ) { + log.trace( "Version: " + version ); + } } final String sql = getLockString( lockMode ); @@ -1200,8 +1227,12 @@ ResultSet rs = st.executeQuery(); try { - if ( !rs.next() ) return null; - if ( !isVersioned() ) return this; + if ( !rs.next() ) { + return null; + } + if ( !isVersioned() ) { + return this; + } return getVersionType().nullSafeGet( rs, getVersionColumnName(), session, null ); } finally { @@ -1294,9 +1325,13 @@ } protected String generateTableAlias(String rootAlias, int tableNumber) { - if ( tableNumber == 0 ) return rootAlias; + if ( tableNumber == 0 ) { + return rootAlias; + } StringBuffer buf = new StringBuffer().append( rootAlias ); - if ( !rootAlias.endsWith( "_" ) ) buf.append( '_' ); + if ( !rootAlias.endsWith( "_" ) ) { + buf.append( '_' ); + } return buf.append( tableNumber ).append( '_' ).toString(); } @@ -1407,7 +1442,9 @@ public String[] getSubclassPropertyColumnAliases(String propertyName, String suffix) { String rawAliases[] = ( String[] ) subclassPropertyAliases.get( propertyName ); - if ( rawAliases == null ) return null; + if ( rawAliases == null ) { + return null; + } String result[] = new String[rawAliases.length]; for ( int i = 0; i < rawAliases.length; i++ ) { @@ -1611,7 +1648,9 @@ initOrdinaryPropertyPaths(mapping); initOrdinaryPropertyPaths(mapping); //do two passes, for collection property-ref! initIdentifierPropertyPaths(mapping); - if ( entityMetamodel.isPolymorphic() ) initDiscriminatorPropertyPath(mapping); + if ( entityMetamodel.isPolymorphic() ) { + initDiscriminatorPropertyPath( mapping ); + } } protected UniqueEntityLoader createEntityLoader(LockMode lockMode, Map enabledFilters) throws MappingException { @@ -1751,7 +1790,9 @@ } // add the discriminator - if ( j == 0 ) addDiscriminatorToInsert( insert ); + if ( j == 0 ) { + addDiscriminatorToInsert( insert ); + } // add the primary key if ( j == 0 && identityInsert ) { @@ -1782,7 +1823,9 @@ Delete delete = new Delete() .setTableName( getTableName( j ) ) .setPrimaryKeyColumnNames( getKeyColumns( j ) ); - if ( j == 0 ) delete.setVersionColumnName( getVersionColumnName() ); + if ( j == 0 ) { + delete.setVersionColumnName( getVersionColumnName() ); + } if ( getFactory().getSettings().isCommentsEnabled() ) { delete.setComment( "delete " + getEntityName() ); } @@ -1901,7 +1944,9 @@ } } - if ( sequentialResultSet != null ) sequentialResultSet.close(); + if ( sequentialResultSet != null ) { + sequentialResultSet.close(); + } return values; @@ -1937,7 +1982,9 @@ if ( log.isTraceEnabled() ) { log.trace( "Inserting entity: " + getEntityName() + " (native id)" ); - if ( isVersioned() ) log.trace( "Version: " + Versioning.getVersion( fields, this ) ); + if ( isVersioned() ) { + log.trace( "Version: " + Versioning.getVersion( fields, this ) ); + } } try { @@ -2022,15 +2069,21 @@ final SessionImplementor session) throws HibernateException { - if ( isInverseTable( j ) ) return; + if ( isInverseTable( j ) ) { + return; + } //note: it is conceptually possible that a UserType could map null to // a non-null value, so the following is arguable: - if ( isNullableTable( j ) && isAllNull( fields, j ) ) return; + if ( isNullableTable( j ) && isAllNull( fields, j ) ) { + return; + } if ( log.isTraceEnabled() ) { log.trace( "Inserting entity: " + MessageHelper.infoString( this, id, getFactory() ) ); - if ( j == 0 && isVersioned() ) log.trace( "Version: " + Versioning.getVersion( fields, this ) ); + if ( j == 0 && isVersioned() ) { + log.trace( "Version: " + Versioning.getVersion( fields, this ) ); + } } boolean callable = isInsertCallable( j ); @@ -2065,11 +2118,15 @@ } catch ( SQLException sqle ) { - if ( useBatch ) session.getBatcher().abortBatch( sqle ); + if ( useBatch ) { + session.getBatcher().abortBatch( sqle ); + } throw sqle; } finally { - if ( !useBatch ) session.getBatcher().closeStatement( insert ); + if ( !useBatch ) { + session.getBatcher().closeStatement( insert ); + } } } catch ( SQLException sqle ) { @@ -2145,7 +2202,9 @@ if ( log.isTraceEnabled() ) { log.trace( "Updating entity: " + MessageHelper.infoString( this, id, getFactory() ) ); - if ( useVersion ) log.trace( "Existing version: " + oldVersion + " -> New version: " + fields[getVersionProperty()] ); + if ( useVersion ) { + log.trace( "Existing version: " + oldVersion + " -> New version: " + fields[getVersionProperty()] ); + } } try { @@ -2208,11 +2267,15 @@ } catch ( SQLException sqle ) { - if ( useBatch ) session.getBatcher().abortBatch( sqle ); + if ( useBatch ) { + session.getBatcher().abortBatch( sqle ); + } throw sqle; } finally { - if ( !useBatch ) session.getBatcher().closeStatement( update ); + if ( !useBatch ) { + session.getBatcher().closeStatement( update ); + } } } @@ -2236,8 +2299,10 @@ final String sql, final SessionImplementor session) throws HibernateException { - - if ( isInverseTable( j ) ) return; + + if ( isInverseTable( j ) ) { + return; + } final boolean useVersion = j == 0 && isVersioned(); final boolean callable = isDeleteCallable( j ); @@ -2245,7 +2310,9 @@ if ( log.isTraceEnabled() ) { log.trace( "Deleting entity: " + MessageHelper.infoString( this, id, getFactory() ) ); - if ( useVersion ) log.trace( "Version: " + version ); + if ( useVersion ) { + log.trace( "Version: " + version ); + } } if ( isTableCascadeDeleteEnabled( j ) ) { @@ -2294,11 +2361,15 @@ } catch ( SQLException sqle ) { - if ( useBatch ) session.getBatcher().abortBatch( sqle ); + if ( useBatch ) { + session.getBatcher().abortBatch( sqle ); + } throw sqle; } finally { - if ( !useBatch ) session.getBatcher().closeStatement( delete ); + if ( !useBatch ) { + session.getBatcher().closeStatement( delete ); + } } } @@ -2443,18 +2514,30 @@ protected void logStaticSQL() { if ( log.isDebugEnabled() ) { log.debug( "Static SQL for entity: " + getEntityName() ); - if ( sqlLazySelectString != null ) log.debug( " Lazy select: " + sqlLazySelectString ); - if ( sqlVersionSelectString != null ) log.debug( " Version select: " + sqlVersionSelectString ); - if ( sqlSnapshotSelectString != null ) log.debug( " Snapshot select: " + sqlSnapshotSelectString ); + if ( sqlLazySelectString != null ) { + log.debug( " Lazy select: " + sqlLazySelectString ); + } + if ( sqlVersionSelectString != null ) { + log.debug( " Version select: " + sqlVersionSelectString ); + } + if ( sqlSnapshotSelectString != null ) { + log.debug( " Snapshot select: " + sqlSnapshotSelectString ); + } for ( int j = 0; j < getTableSpan(); j++ ) { log.debug( " Insert " + j + ": " + getSQLInsertStrings()[j] ); log.debug( " Update " + j + ": " + getSQLUpdateStrings()[j] ); log.debug( " Delete " + j + ": " + getSQLDeleteStrings()[j] ); } - if ( sqlIdentityInsertString != null ) log.debug( " Identity insert: " + sqlIdentityInsertString ); - if ( sqlUpdateByRowIdString != null ) log.debug( " Update by row id (all fields): " + sqlUpdateByRowIdString ); - if ( sqlLazyUpdateByRowIdString != null ) log.debug( " Update by row id (non-lazy fields): " + sqlLazyUpdateByRowIdString ); + if ( sqlIdentityInsertString != null ) { + log.debug( " Identity insert: " + sqlIdentityInsertString ); + } + if ( sqlUpdateByRowIdString != null ) { + log.debug( " Update by row id (all fields): " + sqlUpdateByRowIdString ); + } + if ( sqlLazyUpdateByRowIdString != null ) { + log.debug( " Update by row id (non-lazy fields): " + sqlLazyUpdateByRowIdString ); + } if ( sqlInsertGeneratedValuesSelectString != null ) { log.debug( "Insert-generated property select: " + sqlInsertGeneratedValuesSelectString ); } @@ -2707,7 +2790,9 @@ } protected void createQueryLoader() { - if ( loaderName != null ) queryLoader = new NamedQueryLoader( loaderName, this ); + if ( loaderName != null ) { + queryLoader = new NamedQueryLoader( loaderName, this ); + } } /** @@ -2748,7 +2833,9 @@ private boolean isAllNull(Object[] array, int tableNumber) { for ( int i = 0; i < array.length; i++ ) { - if ( isPropertyOfTable( i, tableNumber ) && array[i] != null ) return false; + if ( isPropertyOfTable( i, tableNumber ) && array[i] != null ) { + return false; + } } return true; } @@ -2766,7 +2853,9 @@ final boolean[] updateability = getPropertyUpdateability(); //no need to check laziness, dirty checking handles that for ( int j = 0; j < dirtyProperties.length; j++ ) { int property = dirtyProperties[j]; - if ( updateability[property] ) propsToUpdate[property] = true; + if ( updateability[property] ) { + propsToUpdate[property] = true; + } } if ( isVersioned() ) { propsToUpdate[ getVersionProperty() ] = @@ -2782,7 +2871,9 @@ protected boolean[] getPropertiesToInsert(Object[] fields) { boolean[] notNull = new boolean[fields.length]; boolean[] insertable = getPropertyInsertability(); - for ( int i = 0; i < fields.length; i++ ) notNull[i] = insertable[i] && fields[i] != null; + for ( int i = 0; i < fields.length; i++ ) { + notNull[i] = insertable[i] && fields[i] != null; + } return notNull; } @@ -2891,6 +2982,10 @@ return cacheEntryStructure; } + public Comparator getVersionComparator() { + return isVersioned() ? getVersionType().getComparator() : null; + } + // temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public final String getEntityName() { return entityMetamodel.getName(); @@ -2985,7 +3080,9 @@ } // we *always* assume an instance with a null // identifier or no identifier property is unsaved! - if ( id == null ) return Boolean.TRUE; + if ( id == null ) { + return Boolean.TRUE; + } // check the version unsaved-value, if appropriate final Object version = getVersion( entity, session.getEntityMode() ); @@ -2994,13 +3091,17 @@ // assigned identifiers Boolean result = entityMetamodel.getVersionProperty() .getUnsavedValue().isUnsaved( version ); - if ( result != null ) return result; + if ( result != null ) { + return result; + } } // check the id unsaved-value Boolean result = entityMetamodel.getIdentifierProperty() .getUnsavedValue().isUnsaved( id ); - if ( result != null ) return result; + if ( result != null ) { + return result; + } // check to see if it is in the second-level cache if ( hasCache() ) { Index: EntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- EntityPersister.java 5 Dec 2005 18:45:52 -0000 1.22 +++ EntityPersister.java 9 Feb 2006 20:48:43 -0000 1.23 @@ -9,6 +9,7 @@ import org.hibernate.MappingException; import org.hibernate.EntityMode; import org.hibernate.cache.CacheConcurrencyStrategy; +import org.hibernate.cache.OptimisticCacheSource; import org.hibernate.cache.entry.CacheEntryStructure; import org.hibernate.engine.CascadeStyle; import org.hibernate.engine.SessionFactoryImplementor; @@ -27,7 +28,7 @@ * * @author Gavin King */ -public interface EntityPersister { +public interface EntityPersister extends OptimisticCacheSource { /** * The property name of the "special" identifier property in HQL |