From: <ste...@us...> - 2006-02-14 03:24:05
|
Update of /cvsroot/hibernate/Hibernate3/src/org/hibernate/persister/entity In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9926/src/org/hibernate/persister/entity Modified Files: AbstractEntityPersister.java EntityPersister.java Log Message: HHH-1416 & HHH-1421 : EJB3 LockModeTypes Index: AbstractEntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- AbstractEntityPersister.java 12 Feb 2006 00:21:44 -0000 1.28 +++ AbstractEntityPersister.java 14 Feb 2006 03:23:55 -0000 1.29 @@ -1210,6 +1210,69 @@ } + public Object forceVersionIncrement(Serializable id, Object currentVersion, SessionImplementor session) { + if ( !isVersioned() ) { + throw new AssertionFailure( "cannot force version increment on non-versioned entity" ); + } + + if ( isVersionPropertyGenerated() ) { + // the difficulty here is exactly what do we update in order to + // force the version to be incremented in the db... + throw new HibernateException( "LockMode.FORCE is currently not supported for generated version properties" ); + } + + Object nextVersion = getVersionType().next( currentVersion, session ); + if ( log.isTraceEnabled() ) { + log.trace( + "Forcing version increment [" + MessageHelper.infoString( this, id, getFactory() ) + + "; " + getVersionType().toLoggableString( currentVersion, getFactory() ) + + " -> " + getVersionType().toLoggableString( nextVersion, getFactory() ) + "]" + ); + } + + // todo : cache this sql... + String versionIncrementString = generateVersionIncrementUpdateString(); + PreparedStatement st = null; + try { + try { + st = session.getBatcher().prepareStatement( versionIncrementString ); + getVersionType().nullSafeSet( st, nextVersion, 1, session ); + getIdentifierType().nullSafeSet( st, id, 2, session ); + getVersionType().nullSafeSet( st, currentVersion, 2 + getIdentifierColumnSpan(), session ); + int rows = st.executeUpdate(); + if ( rows != 1 ) { + throw new StaleObjectStateException( getEntityName(), id ); + } + } + finally { + session.getBatcher().closeStatement( st ); + } + } + catch ( SQLException sqle ) { + throw JDBCExceptionHelper.convert( + getFactory().getSQLExceptionConverter(), + sqle, + "could not retrieve version: " + + MessageHelper.infoString( this, id, getFactory() ), + getVersionSelectString() + ); + } + + return nextVersion; + } + + private String generateVersionIncrementUpdateString() { + Update update = new Update( getFactory().getDialect() ); + update.setTableName( getTableName( 0 ) ); + if ( getFactory().getSettings().isCommentsEnabled() ) { + update.setComment( "forced version increment" ); + } + update.addColumn( getVersionColumnName() ); + update.setPrimaryKeyColumnNames( getIdentifierColumnNames() ); + update.setVersionColumnName( getVersionColumnName() ); + return update.toStatementString(); + } + /** * Retrieve the version number */ Index: EntityPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- EntityPersister.java 9 Feb 2006 20:48:43 -0000 1.23 +++ EntityPersister.java 14 Feb 2006 03:23:55 -0000 1.24 @@ -364,7 +364,10 @@ */ public Object getCurrentVersion(Serializable id, SessionImplementor session) throws HibernateException; - + + public Object forceVersionIncrement(Serializable id, Object currentVersion, SessionImplementor session) + throws HibernateException; + /** * Try to discover the entity mode from the entity instance */ |