Skip to content

Instantly share code, notes, and snippets.

@sebersole
Created November 30, 2011 14:34
Show Gist options
  • Save sebersole/1409264 to your computer and use it in GitHub Desktop.
Save sebersole/1409264 to your computer and use it in GitHub Desktop.
try {
try {
PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( sql );
try {
getLockable().getIdentifierType().nullSafeSet( st, id, 1, session );
if ( getLockable().isVersioned() ) {
getLockable().getVersionType().nullSafeSet(
st,
version,
getLockable().getIdentifierType().getColumnSpan( factory ) + 1,
session
);
}
ResultSet rs = st.executeQuery();
try {
if ( !rs.next() ) {
if ( factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor()
.optimisticFailure( getLockable().getEntityName() );
}
throw new StaleObjectStateException( getLockable().getEntityName(), id );
}
}
finally {
rs.close();
}
}
finally {
st.close();
}
}
catch ( SQLException sqle ) {
throw session.getFactory().getSQLExceptionHelper().convert(
sqle,
"could not lock: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ),
sql
);
}
}
catch (PessimisticLockException pe) {
throw pe;
}
catch (JDBCException e) {
throw new PessimisticLockException( "could not obtain pessimistic lock", e, object );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment