Java Code Examples for org.hibernate.persister.entity.Loadable#isVersioned()

The following examples show how to use org.hibernate.persister.entity.Loadable#isVersioned() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Loader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The entity instance is already in the session cache
 */
private void instanceAlreadyLoaded(
		final ResultSet rs,
		final int i,
		final Loadable persister,
		final EntityKey key,
		final Object object,
		final LockMode requestedLockMode,
		final SharedSessionContractImplementor session)
		throws HibernateException, SQLException {
	if ( !persister.isInstance( object ) ) {
		throw new WrongClassException(
				"loaded object was of wrong class " + object.getClass(),
				key.getIdentifier(),
				persister.getEntityName()
		);
	}

	if ( LockMode.NONE != requestedLockMode && upgradeLocks() ) { //no point doing this if NONE was requested
		final EntityEntry entry = session.getPersistenceContext().getEntry( object );
		if ( entry.getLockMode().lessThan( requestedLockMode ) ) {
			//we only check the version when _upgrading_ lock modes
			if ( persister.isVersioned() ) {
				checkVersion( i, persister, key.getIdentifier(), object, rs, session );
			}
			//we need to upgrade the lock mode to the mode requested
			entry.setLockMode( requestedLockMode );
		}
	}
}
 
Example 2
Source File: Loader.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * The entity instance is already in the session cache
 */
private void instanceAlreadyLoaded(
        final ResultSet rs,
        final int i,
        final Loadable persister,
        final EntityKey key,
        final Object object,
        final LockMode lockMode,
        final SessionImplementor session) 
throws HibernateException, SQLException {

	if ( !persister.isInstance( object, session.getEntityMode() ) ) {
		throw new WrongClassException( 
				"loaded object was of wrong class " + object.getClass(), 
				key.getIdentifier(), 
				persister.getEntityName() 
			);
	}

	if ( LockMode.NONE != lockMode && upgradeLocks() ) { //no point doing this if NONE was requested

		final boolean isVersionCheckNeeded = persister.isVersioned() &&
				session.getPersistenceContext().getEntry(object)
						.getLockMode().lessThan( lockMode );
		// we don't need to worry about existing version being uninitialized
		// because this block isn't called by a re-entrant load (re-entrant
		// loads _always_ have lock mode NONE)
		if (isVersionCheckNeeded) {
			//we only check the version when _upgrading_ lock modes
			checkVersion( i, persister, key.getIdentifier(), object, rs, session );
			//we need to upgrade the lock mode to the mode requested
			session.getPersistenceContext().getEntry(object)
					.setLockMode(lockMode);
		}
	}
}
 
Example 3
Source File: DefaultEntityAliases.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Calculate and cache select-clause suffixes.
 * @param map 
 */
public DefaultEntityAliases(Map userProvidedAliases, Loadable persister, String suffix) {
	this.suffix = suffix;
	this.userProvidedAliases = userProvidedAliases;
	
	String[] keyColumnsCandidates = getUserProvidedAliases(
			persister.getIdentifierPropertyName(), 
			(String[]) null
		); 
	if (keyColumnsCandidates==null) {
		suffixedKeyColumns = getUserProvidedAliases(
				"id", 
				getIdentifierAliases(persister, suffix)
			);
	} 
	else {
		suffixedKeyColumns = keyColumnsCandidates;
	}
	intern(suffixedKeyColumns);
	
	suffixedPropertyColumns = getSuffixedPropertyAliases(persister);
	suffixedDiscriminatorColumn = getUserProvidedAlias(
			"class", 
			getDiscriminatorAlias(persister, suffix)
		);
	if ( persister.isVersioned() ) { 
		suffixedVersionColumn = suffixedPropertyColumns[ persister.getVersionProperty() ];
	}
	else {
		suffixedVersionColumn = null;
	}
	rowIdAlias = Loadable.ROWID_ALIAS + suffix; // TODO: not visible to the user!
}
 
Example 4
Source File: DefaultEntityAliases.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String[] determineVersionAlias(Loadable persister) {
	return persister.isVersioned()
			? suffixedPropertyColumns[ persister.getVersionProperty() ]
			: null;
}