本文整理汇总了Java中org.hibernate.collection.PersistentCollection类的典型用法代码示例。如果您正苦于以下问题:Java PersistentCollection类的具体用法?Java PersistentCollection怎么用?Java PersistentCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PersistentCollection类属于org.hibernate.collection包,在下文中一共展示了PersistentCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateRows
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void updateRows(PersistentCollection collection, Serializable id, SessionImplementor session)
throws HibernateException {
if ( !isInverse && collection.isRowUpdatePossible() ) {
if ( log.isDebugEnabled() ) {
log.debug( "Updating rows of collection: " + role + "#" + id );
}
//update all the modified entries
int count = doUpdateRows( id, collection, session );
if ( log.isDebugEnabled() ) {
log.debug( "done updating rows: " + count + " updated" );
}
}
}
示例2: serialize
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
@Override
public void serialize(PersistentCollection coll, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
// If lazy-loaded, not yet loaded, may serialize as null?
if (!_forceLazyLoading && !coll.wasInitialized()) {
jgen.writeNull();
return;
}
Object value = coll.getValue();
if (value == null) {
provider.defaultSerializeNull(jgen);
} else {
if (_serializer == null) { // sanity check...
throw new JsonMappingException("PersitentCollection does not have serializer set");
}
_serializer.serialize(value, jgen, provider);
}
}
示例3: initializeProperty
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
*
* @param o Set the object
* @param association Set the association to initialize
*/
protected Object initializeProperty(final Object o, final String association) {
Object object;
try {
object = PropertyUtils.getProperty(o, association);
} catch (Exception e) {
logger.debug("Cannot get proxy " + association + " for class " + o.getClass());
return null;
}
if (object == null) {
return null;
} else if (object instanceof HibernateProxy) {
((HibernateProxy) object).getHibernateLazyInitializer().initialize();
LazyInitializer lazyInitializer = ((HibernateProxy) object)
.getHibernateLazyInitializer();
return lazyInitializer.getImplementation();
} else if (object instanceof PersistentCollection) {
((PersistentCollection) object).forceInitialization();
return object;
} else {
return object;
}
}
示例4: deleteOrphans
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* Delete any entities that were removed from the collection
*/
private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException {
//TODO: suck this logic into the collection!
final Collection orphans;
if ( pc.wasInitialized() ) {
CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc);
orphans = ce==null ?
CollectionHelper.EMPTY_COLLECTION :
ce.getOrphans(entityName, pc);
}
else {
orphans = pc.getQueuedOrphans(entityName);
}
final Iterator orphanIter = orphans.iterator();
while ( orphanIter.hasNext() ) {
Object orphan = orphanIter.next();
if (orphan!=null) {
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
eventSource.delete( entityName, orphan, false, null );
}
}
}
示例5: CollectionEntry
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* For collections just loaded from the database
*/
public CollectionEntry(
final PersistentCollection collection,
final CollectionPersister loadedPersister,
final Serializable loadedKey,
final boolean ignore
) {
this.ignore=ignore;
//collection.clearDirty()
this.loadedKey = loadedKey;
setLoadedPersister(loadedPersister);
collection.setSnapshot(loadedKey, role, null);
//postInitialize() will be called after initialization
}
示例6: findSerializer
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
@Override
public JsonSerializer<?> findSerializer(
SerializationConfig config, JavaType type,
BeanDescription beanDesc)
{
Class<?> raw = type.getRawClass();
/* Note: PersistentCollection does not implement Collection, so we
* may get some types here...
*/
if (PersistentCollection.class.isAssignableFrom(raw)) {
// TODO: handle iterator types? Or PersistentArrayHolder?
}
if (HibernateProxy.class.isAssignableFrom(raw)) {
return new HibernateProxySerializer(isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
}
示例7: initializeNonLazyCollections
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* Force initialization of all non-lazy collections encountered during
* the current two-phase load (actually, this is a no-op, unless this
* is the "outermost" load)
*/
public void initializeNonLazyCollections() throws HibernateException {
if ( loadCounter == 0 ) {
log.debug( "initializing non-lazy collections" );
//do this work only at the very highest level of the load
loadCounter++; //don't let this method be called recursively
try {
int size;
while ( ( size = nonlazyCollections.size() ) > 0 ) {
//note that each iteration of the loop may add new elements
( (PersistentCollection) nonlazyCollections.remove( size - 1 ) ).forceInitialization();
}
}
finally {
loadCounter--;
clearNullProperties();
}
}
}
示例8: locateLoadingCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* Attempt to locate the loading collection given the owner's key. The lookup here
* occurs against all result-set contexts...
*
* @param persister The collection persister
* @param ownerKey The owner key
* @return The loading collection, or null if not found.
*/
public PersistentCollection locateLoadingCollection(CollectionPersister persister, Serializable ownerKey) {
LoadingCollectionEntry lce = locateLoadingCollectionEntry( new CollectionKey( persister, ownerKey, getEntityMode() ) );
if ( lce != null ) {
if ( log.isTraceEnabled() ) {
log.trace( "returning loading collection:" + MessageHelper.collectionInfoString( persister, ownerKey, getSession().getFactory() ) );
}
return lce.getCollection();
}
else {
// todo : should really move this log statement to CollectionType, where this is used from...
if ( log.isTraceEnabled() ) {
log.trace( "creating collection wrapper:" + MessageHelper.collectionInfoString( persister, ownerKey, getSession().getFactory() ) );
}
return null;
}
}
示例9: processCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
Object processCollection(Object collection, CollectionType collectionType)
throws HibernateException {
if ( collection!=null && (collection instanceof PersistentCollection) ) {
final SessionImplementor session = getSession();
PersistentCollection coll = (PersistentCollection) collection;
if ( coll.setCurrentSession(session) ) {
reattachCollection( coll, collectionType );
}
return null;
}
else {
return processArrayOrNewCollection(collection, collectionType);
}
}
示例10: evictCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void evictCollection(Object value, CollectionType type) {
final Object pc;
if ( type.hasHolder( getSession().getEntityMode() ) ) {
pc = getSession().getPersistenceContext().removeCollectionHolder(value);
}
else if ( value instanceof PersistentCollection ) {
pc = value;
}
else {
return; //EARLY EXIT!
}
PersistentCollection collection = (PersistentCollection) pc;
if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
}
示例11: execute
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void execute() throws HibernateException {
final PersistentCollection collection = getCollection();
getPersister().recreate( collection, getKey(), getSession() );
getSession().getPersistenceContext()
.getCollectionEntry(collection)
.afterAction(collection);
evict();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor()
.recreateCollection( getPersister().getRole() );
}
}
示例12: execute
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public void execute() throws HibernateException {
if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() );
final PersistentCollection collection = getCollection();
if (collection!=null) {
getSession().getPersistenceContext()
.getCollectionEntry(collection)
.afterAction(collection);
}
evict();
if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
getSession().getFactory().getStatisticsImplementor()
.removeCollection( getPersister().getRole() );
}
}
示例13: getCollection
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
/**
* instantiate a collection wrapper (called when loading an object)
*
* @param key The collection owner key
* @param session The session from which the request is originating.
* @param owner The collection owner
* @return The collection
*/
public Object getCollection(Serializable key, SessionImplementor session, Object owner) {
CollectionPersister persister = getPersister( session );
final PersistenceContext persistenceContext = session.getPersistenceContext();
final EntityMode entityMode = session.getEntityMode();
if (entityMode==EntityMode.DOM4J && !isEmbeddedInXML) {
return UNFETCHED_COLLECTION;
}
// check if collection is currently being loaded
PersistentCollection collection = persistenceContext.getLoadContexts().locateLoadingCollection( persister, key );
if ( collection == null ) {
// check if it is already completely loaded, but unowned
collection = persistenceContext.useUnownedCollection( new CollectionKey(persister, key, entityMode) );
if ( collection == null ) {
// create a new collection wrapper, to be initialized later
collection = instantiate( session, persister, key );
collection.setOwner( owner );
persistenceContext.addUninitializedCollection( persister, collection, key );
// some collections are not lazy:
if ( initializeImmediately( entityMode ) ) {
session.initializeCollection( collection, false );
}
else if ( !persister.isLazy() ) {
persistenceContext.addNonLazyCollection( collection );
}
if ( hasHolder( entityMode ) ) {
session.getPersistenceContext().addCollectionHolder( collection );
}
}
}
collection.setOwner( owner );
return collection.getValue();
}
示例14: replaceElements
import org.hibernate.collection.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 ) {
if ( ! ( ( PersistentCollection ) original ).isDirty() ) {
( ( PersistentCollection ) result ).clearDirty();
}
}
}
return result;
}
示例15: wrap
import org.hibernate.collection.PersistentCollection; //导入依赖的package包/类
public PersistentCollection wrap(SessionImplementor session, Object collection) {
if ( session.getEntityMode()==EntityMode.DOM4J ) {
return new PersistentMapElementHolder( session, (Element) collection );
}
else {
return new PersistentMap( session, (java.util.Map) collection );
}
}