protected String generateLockString(int lockTimeout) { final SessionFactoryImplementor factory = getLockable().getFactory(); final LockOptions lockOptions = new LockOptions( getLockMode() ); lockOptions.setTimeOut( lockTimeout ); final SimpleSelect select = new SimpleSelect( factory.getDialect() ) .setLockOptions( lockOptions ) .setTableName( getLockable().getRootTableName() ) .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] ) .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" ); if ( getLockable().isVersioned() ) { select.addCondition( getLockable().getVersionColumnName(), "=?" ); } if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( getLockMode() + " lock " + getLockable().getEntityName() ); } return select.toStatementString(); } }
final PreparedStatement st = session.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 ); if ( !rs.next() ) { if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id ); throw session.getJdbcServices().getSqlExceptionHelper().convert( e, "could not lock: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ), sql );
protected String generateLockString(int lockTimeout) { SessionFactoryImplementor factory = getLockable().getFactory(); LockOptions lockOptions = new LockOptions( getLockMode() ); lockOptions.setTimeOut( lockTimeout ); SimpleSelect select = new SimpleSelect( factory.getDialect() ) .setLockOptions( lockOptions ) .setTableName( getLockable().getRootTableName() ) .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] ) .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" ); if ( getLockable().isVersioned() ) { select.addCondition( getLockable().getVersionColumnName(), "=?" ); } if ( factory.getSettings().isCommentsEnabled() ) { select.setComment( getLockMode() + " lock " + getLockable().getEntityName() ); } return select.toStatementString(); } }
protected String generateLockString(int lockTimeout) { SessionFactoryImplementor factory = getLockable().getFactory(); LockOptions lockOptions = new LockOptions( getLockMode() ); lockOptions.setTimeOut( lockTimeout ); SimpleSelect select = new SimpleSelect( factory.getDialect() ) .setLockOptions( lockOptions ) .setTableName( getLockable().getRootTableName() ) .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] ) .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" ); if ( getLockable().isVersioned() ) { select.addCondition( getLockable().getVersionColumnName(), "=?" ); } if ( factory.getSettings().isCommentsEnabled() ) { select.setComment( getLockMode() + " lock " + getLockable().getEntityName() ); } return select.toStatementString(); } }
protected String generateLockString(int lockTimeout) { final SessionFactoryImplementor factory = getLockable().getFactory(); final LockOptions lockOptions = new LockOptions( getLockMode() ); lockOptions.setTimeOut( lockTimeout ); final SimpleSelect select = new SimpleSelect( factory.getDialect() ) .setLockOptions( lockOptions ) .setTableName( getLockable().getRootTableName() ) .addColumn( getLockable().getRootTableIdentifierColumnNames()[0] ) .addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" ); if ( StringHelper.isNotEmpty( getLockable().getVersionColumnName() ) ) { select.addCondition( getLockable().getVersionColumnName(), "=?" ); } if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) { select.setComment( getLockMode() + " lock " + getLockable().getEntityName() ); } return select.toStatementString(); } }
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 ); if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatisticsImplementor() .optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id ); throw session.getFactory().getSQLExceptionHelper().convert( e, "could not lock: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ), sql );
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 ); if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatisticsImplementor() .optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id ); throw session.getFactory().getSQLExceptionHelper().convert( e, "could not lock: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ), sql );
final EntityIdentifier<Object, Object> identifierDescriptor = getLockable().getHierarchy().getIdentifierDescriptor(); identifierDescriptor.dehydrate( identifierDescriptor.unresolve( id, session ), throw session.getJdbcServices().getSqlExceptionHelper().convert( e, "Could not bind id value(s) to lock entity: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ), sql ); final VersionDescriptor<Object, Object> versionDescriptor = getLockable().getHierarchy().getVersionDescriptor(); throw session.getJdbcServices().getSqlExceptionHelper().convert( e, "Could not bind version value(s) to lock entity: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ), sql ); if ( !rs.next() ) { if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id ); throw session.getJdbcServices().getSqlExceptionHelper().convert( e, "could not lock: " + MessageHelper.infoString( getLockable(), id, session.getFactory() ), sql );