Java Code Examples for org.hibernate.pretty.MessageHelper#collectionInfoString()

The following examples show how to use org.hibernate.pretty.MessageHelper#collectionInfoString() . 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: CollectionEntry.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void preFlush(PersistentCollection collection) throws HibernateException {
	if ( loadedKey == null && collection.getKey() != null ) {
		loadedKey = collection.getKey();
	}

	boolean nonMutableChange = collection.isDirty()
			&& getLoadedPersister() != null
			&& !getLoadedPersister().isMutable();
	if ( nonMutableChange ) {
		throw new HibernateException(
				"changed an immutable collection instance: " +
				MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() )
		);
	}

	dirty( collection );

	if ( LOG.isDebugEnabled() && collection.isDirty() && getLoadedPersister() != null ) {
		LOG.debugf(
				"Collection dirty: %s",
				MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() )
		);
	}

	setReached( false );
	setProcessed( false );

	setDoupdate( false );
	setDoremove( false );
	setDorecreate( false );
}
 
Example 2
Source File: CollectionEntry.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String toString() {
	String result = "CollectionEntry" +
			MessageHelper.collectionInfoString( loadedPersister.getRole(), loadedKey );
	if ( currentPersister != null ) {
		result += "->" +
				MessageHelper.collectionInfoString( currentPersister.getRole(), currentKey );
	}
	return result;
}
 
Example 3
Source File: CollectionEntry.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void preFlush(PersistentCollection collection) throws HibernateException {
	
	boolean nonMutableChange = collection.isDirty() && 
			getLoadedPersister()!=null && 
			!getLoadedPersister().isMutable();
	if (nonMutableChange) {
		throw new HibernateException(
				"changed an immutable collection instance: " + 
				MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() )
			);
	}
	
	dirty(collection);
	
	if ( log.isDebugEnabled() && collection.isDirty() && getLoadedPersister() != null ) {
		log.debug(
				"Collection dirty: " +
				MessageHelper.collectionInfoString( getLoadedPersister().getRole(), getLoadedKey() )
			);
	}

	setDoupdate(false);
	setDoremove(false);
	setDorecreate(false);
	setReached(false);
	setProcessed(false);
}
 
Example 4
Source File: CollectionEntry.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String toString() {
	String result = "CollectionEntry" + 
			MessageHelper.collectionInfoString( loadedPersister.getRole(), loadedKey );
	if (currentPersister!=null) {
		result += "->" + 
				MessageHelper.collectionInfoString( currentPersister.getRole(), currentKey );
	}
	return result;
}
 
Example 5
Source File: AbstractPersistentCollection.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Associate the collection with the given session.
 * @return false if the collection was already associated with the session
 * @throws HibernateException if the collection was already associated
 * with another open session
 */
public final boolean setCurrentSession(SessionImplementor session) throws HibernateException {
	if (session==this.session) {
		return false;
	}
	else {
		if ( isConnectedToSession() ) {
			CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(this);
			if (ce==null) {
				throw new HibernateException(
						"Illegal attempt to associate a collection with two open sessions"
					);
			}
			else {
				throw new HibernateException(
						"Illegal attempt to associate a collection with two open sessions: " +
						MessageHelper.collectionInfoString( 
								ce.getLoadedPersister(), 
								ce.getLoadedKey(), 
								session.getFactory() 
							)
					);
			}
		}
		else {
			this.session = session;
			return true;
		}
	}
}
 
Example 6
Source File: CollectionKey.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toString() {
	return "CollectionKey"
			+ MessageHelper.collectionInfoString( factory.getCollectionPersister( role ), key, factory );
}
 
Example 7
Source File: CollectionLoadContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Add the collection to the second-level cache
 *
 * @param lce The entry representing the collection to add
 * @param persister The persister
 */
private void addCollectionToCache(LoadingCollectionEntry lce, CollectionPersister persister) {
	final SharedSessionContractImplementor session = getLoadContext().getPersistenceContext().getSession();
	final SessionFactoryImplementor factory = session.getFactory();

	final boolean debugEnabled = LOG.isDebugEnabled();
	if ( debugEnabled ) {
		LOG.debugf( "Caching collection: %s", MessageHelper.collectionInfoString( persister, lce.getCollection(), lce.getKey(), session ) );
	}

	if ( !session.getLoadQueryInfluencers().getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( session ) ) {
		// some filters affecting the collection are enabled on the session, so do not do the put into the cache.
		if ( debugEnabled ) {
			LOG.debug( "Refusing to add to cache due to enabled filters" );
		}
		// todo : add the notion of enabled filters to the cache key to differentiate filtered collections from non-filtered;
		//      DefaultInitializeCollectionEventHandler.initializeCollectionFromCache() (which makes sure to not read from
		//      cache with enabled filters).
		// EARLY EXIT!!!!!
		return;
	}

	final Object version;
	if ( persister.isVersioned() ) {
		Object collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( lce.getKey(), persister );
		if ( collectionOwner == null ) {
			// generally speaking this would be caused by the collection key being defined by a property-ref, thus
			// the collection key and the owner key would not match up.  In this case, try to use the key of the
			// owner instance associated with the collection itself, if one.  If the collection does already know
			// about its owner, that owner should be the same instance as associated with the PC, but we do the
			// resolution against the PC anyway just to be safe since the lookup should not be costly.
			if ( lce.getCollection() != null ) {
				final Object linkedOwner = lce.getCollection().getOwner();
				if ( linkedOwner != null ) {
					final Serializable ownerKey = persister.getOwnerEntityPersister().getIdentifier( linkedOwner, session );
					collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( ownerKey, persister );
				}
			}
			if ( collectionOwner == null ) {
				throw new HibernateException(
						"Unable to resolve owner of loading collection [" +
								MessageHelper.collectionInfoString( persister, lce.getCollection(), lce.getKey(), session ) +
								"] for second level caching"
				);
			}
		}
		version = getLoadContext().getPersistenceContext().getEntry( collectionOwner ).getVersion();
	}
	else {
		version = null;
	}

	final CollectionCacheEntry entry = new CollectionCacheEntry( lce.getCollection(), persister );
	final CollectionDataAccess cacheAccess = persister.getCacheAccessStrategy();
	final Object cacheKey = cacheAccess.generateCacheKey(
			lce.getKey(),
			persister,
			session.getFactory(),
			session.getTenantIdentifier()
	);

	boolean isPutFromLoad = true;
	if ( persister.getElementType().isAssociationType() ) {
		for ( Serializable id : entry.getState() ) {
			EntityPersister entityPersister = ( (QueryableCollection) persister ).getElementPersister();
			if ( session.getPersistenceContext().wasInsertedDuringTransaction( entityPersister, id ) ) {
				isPutFromLoad = false;
				break;
			}
		}
	}

	// CollectionRegionAccessStrategy has no update, so avoid putting uncommitted data via putFromLoad
	if (isPutFromLoad) {
		try {
			session.getEventListenerManager().cachePutStart();
			final boolean put = cacheAccess.putFromLoad(
					session,
					cacheKey,
					persister.getCacheEntryStructure().structure( entry ),
					version,
					factory.getSessionFactoryOptions().isMinimalPutsEnabled() && session.getCacheMode()!= CacheMode.REFRESH
			);

			if ( put && factory.getStatistics().isStatisticsEnabled() ) {
				factory.getStatistics().collectionCachePut(
						persister.getNavigableRole(),
						persister.getCacheAccessStrategy().getRegion().getName()
				);
			}
		}
		finally {
			session.getEventListenerManager().cachePutEnd();
		}
	}
}
 
Example 8
Source File: LoadingCollectionEntry.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toString() {
	return getClass().getName() + "<rs=" + resultSet + ", coll=" + MessageHelper.collectionInfoString( persister.getRole(), key ) + ">@" + Integer.toHexString( hashCode() );
}
 
Example 9
Source File: CollectionUpdateAction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void execute() throws HibernateException {
	final Serializable id = getKey();
	final SharedSessionContractImplementor session = getSession();
	final CollectionPersister persister = getPersister();
	final PersistentCollection collection = getCollection();
	final boolean affectedByFilters = persister.isAffectedByEnabledFilters( session );

	preUpdate();

	if ( !collection.wasInitialized() ) {
		if ( !collection.hasQueuedOperations() ) {
			throw new AssertionFailure( "no queued adds" );
		}
		//do nothing - we only need to notify the cache... 
	}
	else if ( !affectedByFilters && collection.empty() ) {
		if ( !emptySnapshot ) {
			persister.remove( id, session );
		}
	}
	else if ( collection.needsRecreate( persister ) ) {
		if ( affectedByFilters ) {
			throw new HibernateException(
					"cannot recreate collection while filter is enabled: " +
							MessageHelper.collectionInfoString( persister, collection, id, session )
			);
		}
		if ( !emptySnapshot ) {
			persister.remove( id, session );
		}
		persister.recreate( collection, id, session );
	}
	else {
		persister.deleteRows( collection, id, session );
		persister.updateRows( collection, id, session );
		persister.insertRows( collection, id, session );
	}

	getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection );
	evict();
	postUpdate();

	if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
		getSession().getFactory().getStatistics().updateCollection( getPersister().getRole() );
	}
}
 
Example 10
Source File: CollectionKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String toString() {
	return "CollectionKey" +
	       MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory );
}
 
Example 11
Source File: LoadingCollectionEntry.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String toString() {
	return getClass().getName() + "<rs=" + resultSet + ", coll=" + MessageHelper.collectionInfoString( persister.getRole(), key ) + ">@" + Integer.toHexString( hashCode() );
}
 
Example 12
Source File: CollectionUpdateAction.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void execute() throws HibernateException {
	final Serializable id = getKey();
	final SessionImplementor session = getSession();
	final CollectionPersister persister = getPersister();
	final PersistentCollection collection = getCollection();
	boolean affectedByFilters = persister.isAffectedByEnabledFilters(session);

	if ( !collection.wasInitialized() ) {
		if ( !collection.hasQueuedOperations() ) throw new AssertionFailure( "no queued adds" );
		//do nothing - we only need to notify the cache...
	}
	else if ( !affectedByFilters && collection.empty() ) {
		if ( !emptySnapshot ) persister.remove( id, session );
	}
	else if ( collection.needsRecreate(persister) ) {
		if (affectedByFilters) {
			throw new HibernateException(
				"cannot recreate collection while filter is enabled: " + 
				MessageHelper.collectionInfoString( persister, id, persister.getFactory() )
			);
		}
		if ( !emptySnapshot ) persister.remove( id, session );
		persister.recreate( collection, id, session );
	}
	else {
		persister.deleteRows( collection, id, session );
		persister.updateRows( collection, id, session );
		persister.insertRows( collection, id, session );
	}

	getSession().getPersistenceContext()
		.getCollectionEntry(collection)
		.afterAction(collection);

	evict();

	if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
		getSession().getFactory().getStatisticsImplementor().
				updateCollection( getPersister().getRole() );
	}
}