Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.collection.internal;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.CollectionAliases;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.Type;
/**
* An unordered, unkeyed collection that can contain the same element
* multiple times. The Java collections API, curiously, has no Bag.
* Most developers seem to use Lists to represent bag semantics,
* so Hibernate follows this practice.
*
* @author Gavin King
*/
public class PersistentBag extends AbstractPersistentCollection implements List {
protected List bag;
// The Collection provided to a PersistentBag constructor,
private Collection providedCollection;
/**
* Constructs a PersistentBag. Needed for SOAP libraries, etc
*/
@SuppressWarnings("UnusedDeclaration")
public PersistentBag() {
}
/**
* Constructs a PersistentBag
*
* @param session The session
*/
public PersistentBag(SharedSessionContractImplementor session) {
super( session );
}
/**
* Constructs a PersistentBag
*
* @param session The session
*
* @deprecated {@link #PersistentBag(SharedSessionContractImplementor)} should be used instead.
*/
@Deprecated
public PersistentBag(SessionImplementor session) {
this( (SharedSessionContractImplementor) session );
}
/**
* Constructs a PersistentBag
*
* @param session The session
* @param coll The base elements.
*/
@SuppressWarnings("unchecked")
public PersistentBag(SharedSessionContractImplementor session, Collection coll) {
super( session );
providedCollection = coll;
if ( coll instanceof List ) {
bag = (List) coll;
}
else {
bag = new ArrayList( coll );
}
setInitialized();
setDirectlyAccessible( true );
}
/**
* Constructs a PersistentBag
*
* @param session The session
* @param coll The base elements.
*
* @deprecated {@link #PersistentBag(SharedSessionContractImplementor, Collection)}
* should be used instead.
*/
@Deprecated
public PersistentBag(SessionImplementor session, Collection coll) {
this( (SharedSessionContractImplementor) session, coll );
}
@Override
public boolean isWrapper(Object collection) {
return bag == collection;
}
@Override
public boolean isDirectlyProvidedCollection(Object collection) {
return isDirectlyAccessible() && providedCollection == collection;
}
@Override
public boolean empty() {
return bag.isEmpty();
}
@Override
public Iterator entries(CollectionPersister persister) {
return bag.iterator();
}
@Override
@SuppressWarnings("unchecked")
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
throws HibernateException, SQLException {
// note that if we load this collection from a cartesian product
// the multiplicity would be broken ... so use an idbag instead
final Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() );
if ( element != null ) {
bag.add( element );
}
return element;
}
@Override
public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {
this.bag = (List) persister.getCollectionType().instantiate( anticipatedSize );
}
@Override
@SuppressWarnings("unchecked")
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final List