private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { if ( persister.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot( id, persister ); if ( snapshot == null ) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatistics() .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } return snapshot; } // TODO: optimize away this lookup for entities w/o unsaved-value="undefined" final EntityKey entityKey = session.generateEntityKey( id, persister ); return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey ); } }
protected boolean check( int rows, Serializable id, int tableNumber, Expectation expectation, PreparedStatement statement) throws HibernateException { try { expectation.verifyOutcome( rows, statement, -1 ); } catch (StaleStateException e) { if ( !isNullableTable( tableNumber ) ) { if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatistics().optimisticFailure( getEntityName() ); } throw new StaleObjectStateException( getEntityName(), id ); } return false; } catch (TooManyRowsAffectedException e) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } catch (Throwable t) { return false; } return true; }
/** * Check the version of the object in the <tt>ResultSet</tt> against * the object version in the session cache, throwing an exception * if the version numbers are different */ private void checkVersion( final int i, final Loadable persister, final Serializable id, final Object entity, final ResultSet rs, final SharedSessionContractImplementor session) throws HibernateException, SQLException { Object version = session.getPersistenceContext().getEntry( entity ).getVersion(); if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet final VersionType versionType = persister.getVersionType(); final Object currentVersion = versionType.nullSafeGet( rs, getEntityAliases()[i].getSuffixedVersionAliases(), session, null ); if ( !versionType.isEqual( version, currentVersion ) ) { if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatistics().optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } } }
session.getFactory().getStatistics().optimisticFailure( persister.getEntityName() ); throw new StaleObjectStateException( persister.getEntityName(), entityKey.getIdentifier() );
factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id );
factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id );
factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id );
source.getFactory().getStatistics().optimisticFailure( entityName ); throw new StaleObjectStateException( entityName, id );
factory.getStatistics().optimisticFailure( lockable.getEntityName() ); throw new StaleObjectStateException( lockable.getEntityName(), id );
factory.getStatistics().optimisticFailure( lockable.getEntityName() ); throw new StaleObjectStateException( lockable.getEntityName(), id );
factory.getStatistics().optimisticFailure( lockable.getEntityName() ); throw new StaleObjectStateException( lockable.getEntityName(), id );
int rows = session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st ); if ( rows != 1 ) { throw new StaleObjectStateException( getEntityName(), id );
protected boolean check(int rows, Serializable id, int tableNumber) throws HibernateException { if ( rows < 1 ) { if ( !isNullableTable( tableNumber ) ) { throw new StaleObjectStateException( getEntityName(), id ); } } else if ( rows > 1 ) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } return rows > 0; //it could be zero if we have a "nullable" table }
private void raiseStaleObjectStateException(Serializable id) { SessionFactoryImplementor factory = getFactory(); if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().optimisticFailure( getEntityName() ); } throw new StaleObjectStateException( getEntityName(), id ); }
public void check(Integer rows, PreparedStatement preparedStatement) { try { expectation.verifyOutcome( rows, preparedStatement, -1 ); } catch (StaleStateException e) { if ( isNullableTable ) { if ( factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().optimisticFailure( entityDescriptor.getEntityName() ); } throw new StaleObjectStateException( entityDescriptor.getEntityName(), id ); } isRowToUpdate = false; } catch (TooManyRowsAffectedException e) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( entityDescriptor, id, factory ) ); } catch (Throwable t) { isRowToUpdate = false; } isRowToUpdate = true; }
protected boolean check(int rows, Serializable id, int tableNumber, Expectation expectation, PreparedStatement statement) throws HibernateException { try { expectation.verifyOutcome( rows, statement, -1 ); } catch( StaleStateException e ) { if ( !isNullableTable( tableNumber ) ) { if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatisticsImplementor() .optimisticFailure( getEntityName() ); } throw new StaleObjectStateException( getEntityName(), id ); } return false; } catch( TooManyRowsAffectedException e ) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } catch ( Throwable t ) { return false; } return true; }
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityTypeDescriptor entityDescriptor, Object id) { if ( entityDescriptor.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot( id, entityDescriptor ); if ( snapshot == null ) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatistics() .optimisticFailure( entityDescriptor.getEntityName() ); } throw new StaleObjectStateException( entityDescriptor.getEntityName(), id ); } return snapshot; } // TODO: optimize away this lookup for entities w/o unsaved-value="undefined" final EntityKey entityKey = session.generateEntityKey( id, entityDescriptor ); return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey ); } }
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { if ( persister.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot(id, persister); if (snapshot==null) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatisticsImplementor() .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } return snapshot; } // TODO: optimize away this lookup for entities w/o unsaved-value="undefined" final EntityKey entityKey = session.generateEntityKey( id, persister ); return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey ); } }
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { if ( persister.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot(id, persister); if (snapshot==null) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatisticsImplementor() .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } return snapshot; } // TODO: optimize away this lookup for entities w/o unsaved-value="undefined" final EntityKey entityKey = session.generateEntityKey( id, persister ); return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey ); } }
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { if ( persister.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot(id, persister); if (snapshot==null) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatisticsImplementor() .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } else { return snapshot; } } else { //TODO: optimize away this lookup for entities w/o unsaved-value="undefined" EntityKey entityKey = new EntityKey( id, persister, session.getEntityMode() ); return session.getPersistenceContext() .getCachedDatabaseSnapshot( entityKey ); } }