当前位置: 首页>>代码示例>>Java>>正文


Java PersistentCollection.isDirty方法代码示例

本文整理汇总了Java中org.hibernate.collection.spi.PersistentCollection.isDirty方法的典型用法代码示例。如果您正苦于以下问题:Java PersistentCollection.isDirty方法的具体用法?Java PersistentCollection.isDirty怎么用?Java PersistentCollection.isDirty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.collection.spi.PersistentCollection的用法示例。


在下文中一共展示了PersistentCollection.isDirty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dirty

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Determine if the collection is "really" dirty, by checking dirtiness
 * of the collection elements, if necessary
 */
private void dirty(PersistentCollection collection) throws HibernateException {

	boolean forceDirty = collection.wasInitialized() &&
			!collection.isDirty() && //optimization
			getLoadedPersister() != null &&
			getLoadedPersister().isMutable() && //optimization
			( collection.isDirectlyAccessible() || getLoadedPersister().getElementType().isMutable() ) && //optimization
			!collection.equalsSnapshot( getLoadedPersister() );

	if ( forceDirty ) {
		collection.dirty();
	}

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:CollectionEntry.java

示例2: preFlush

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
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() ) );
	}

	setDoupdate(false);
	setDoremove(false);
	setDorecreate(false);
	setReached(false);
	setProcessed(false);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:CollectionEntry.java

示例3: processCollection

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
	if ( collection == null ) {
		return null;
	}

	final SessionImplementor session = getSession();
	final CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );

	if ( collection instanceof PersistentCollection ) {
		final PersistentCollection persistentCollection = (PersistentCollection) collection;
		if ( persistentCollection.setCurrentSession( session ) ) {
			if ( isOwnerUnchanged( persistentCollection, persister, extractCollectionKeyFromOwner( persister ) ) ) {
				// a "detached" collection that originally belonged to the same entity
				if ( persistentCollection.isDirty() ) {
					throw new HibernateException( "reassociated object has dirty collection" );
				}
				reattachCollection( persistentCollection, type );
			}
			else {
				// a "detached" collection that belonged to a different entity
				throw new HibernateException( "reassociated object has dirty collection reference" );
			}
		}
		else {
			// a collection loaded in the current session
			// can not possibly be the collection belonging
			// to the entity passed to update()
			throw new HibernateException( "reassociated object has dirty collection reference" );
		}
	}
	else {
		// brand new collection
		//TODO: or an array!! we can't lock objects with arrays now??
		throw new HibernateException( "reassociated object has dirty collection reference (or an array)" );
	}

	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:OnLockVisitor.java

示例4: replaceElements

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * Replace the elements of a collection with the elements of another collection.
 *
 * @param original The 'source' of the replacement elements (where we copy from)
 * @param target The target of the replacement elements (where we copy to)
 * @param owner The owner of the collection being merged
 * @param copyCache The map of elements already replaced.
 * @param session The session from which the merge event originated.
 * @return The merged collection.
 */
public Object replaceElements(
		Object original,
		Object target,
		Object owner,
		Map copyCache,
		SessionImplementor session) {
	// TODO: does not work for EntityMode.DOM4J yet!
	java.util.Collection result = ( java.util.Collection ) target;
	result.clear();

	// copy elements into newly empty target collection
	Type elemType = getElementType( session.getFactory() );
	Iterator iter = ( (java.util.Collection) original ).iterator();
	while ( iter.hasNext() ) {
		result.add( elemType.replace( iter.next(), null, session, owner, copyCache ) );
	}

	// if the original is a PersistentCollection, and that original
	// was not flagged as dirty, then reset the target's dirty flag
	// here after the copy operation.
	// </p>
	// One thing to be careful of here is a "bare" original collection
	// in which case we should never ever ever reset the dirty flag
	// on the target because we simply do not know...
	if ( original instanceof PersistentCollection ) {
		if ( result instanceof PersistentCollection ) {
			final PersistentCollection originalPersistentCollection = (PersistentCollection) original;
			final PersistentCollection resultPersistentCollection = (PersistentCollection) result;

			preserveSnapshot( originalPersistentCollection, resultPersistentCollection, elemType, owner, copyCache, session );

			if ( ! originalPersistentCollection.isDirty() ) {
				resultPersistentCollection.clearDirty();
			}
		}
	}

	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:50,代码来源:CollectionType.java

示例5: prepareCollectionForUpdate

import org.hibernate.collection.spi.PersistentCollection; //导入方法依赖的package包/类
/**
 * 1. record the collection role that this collection is referenced by
 * 2. decide if the collection needs deleting/creating/updating (but
 *	don't actually schedule the action yet)
 */
@SuppressWarnings( {"JavaDoc"})
private static void prepareCollectionForUpdate(
		PersistentCollection collection,
		CollectionEntry entry,
		SessionFactoryImplementor factory) {
	if ( entry.isProcessed() ) {
		throw new AssertionFailure( "collection was processed twice by flush()" );
	}
	entry.setProcessed( true );

	final CollectionPersister loadedPersister = entry.getLoadedPersister();
	final CollectionPersister currentPersister = entry.getCurrentPersister();
	if ( loadedPersister != null || currentPersister != null ) {
		// it is or was referenced _somewhere_

		// if either its role changed, or its key changed
		final boolean ownerChanged = loadedPersister != currentPersister
				|| !currentPersister.getKeyType().isEqual( entry.getLoadedKey(), entry.getCurrentKey(), factory );

		if ( ownerChanged ) {
			// do a check
			final boolean orphanDeleteAndRoleChanged =
					loadedPersister != null && currentPersister != null && loadedPersister.hasOrphanDelete();

			if (orphanDeleteAndRoleChanged) {
				throw new HibernateException(
						"Don't change the reference to a collection with delete-orphan enabled : "
								+ loadedPersister.getRole()
				);
			}

			// do the work
			if ( currentPersister != null ) {
				entry.setDorecreate( true );
			}

			if ( loadedPersister != null ) {
				// we will need to remove ye olde entries
				entry.setDoremove( true );
				if ( entry.isDorecreate() ) {
					LOG.trace( "Forcing collection initialization" );
					collection.forceInitialization();
				}
			}
		}
		else if ( collection.isDirty() ) {
			// the collection's elements have changed
			entry.setDoupdate( true );
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:Collections.java


注:本文中的org.hibernate.collection.spi.PersistentCollection.isDirty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。