genericize PersistentCollection hierarchy
This commit is contained in:
parent
40947297e4
commit
e631574922
|
@ -20,7 +20,6 @@ import org.hibernate.AssertionFailure;
|
|||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.internal.ForeignKeys;
|
||||
import org.hibernate.engine.spi.CollectionEntry;
|
||||
|
@ -54,7 +53,7 @@ import org.hibernate.type.UUIDCharType;
|
|||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public abstract class AbstractPersistentCollection implements Serializable, PersistentCollection {
|
||||
public abstract class AbstractPersistentCollection<E> implements Serializable, PersistentCollection<E> {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractPersistentCollection.class );
|
||||
|
||||
private transient SharedSessionContractImplementor session;
|
||||
|
@ -63,7 +62,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
private boolean initialized;
|
||||
private transient boolean initializing;
|
||||
|
||||
private transient List<DelayedOperation> operationQueue;
|
||||
private transient List<DelayedOperation<E>> operationQueue;
|
||||
private transient boolean directlyAccessible;
|
||||
private Object owner;
|
||||
private int cachedSize = -1;
|
||||
|
@ -154,7 +153,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
/**
|
||||
* Called by the {@link Collection#size} method
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean readSize() {
|
||||
if ( !initialized ) {
|
||||
if ( cachedSize != -1 && !hasQueuedOperations() ) {
|
||||
|
@ -162,34 +160,29 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
else {
|
||||
final boolean isExtraLazy = withTemporarySessionIfNeeded(
|
||||
new LazyInitializationWork<Boolean>() {
|
||||
@Override
|
||||
public Boolean doWork() {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
|
||||
() -> {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
|
||||
|
||||
if ( entry != null ) {
|
||||
final CollectionPersister persister = entry.getLoadedPersister();
|
||||
if ( persister.isExtraLazy() ) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
session.flush();
|
||||
}
|
||||
cachedSize = persister.getSize( entry.getLoadedKey(), session );
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
read();
|
||||
if ( entry != null ) {
|
||||
final CollectionPersister persister = entry.getLoadedPersister();
|
||||
if ( persister.isExtraLazy() ) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
session.flush();
|
||||
}
|
||||
cachedSize = persister.getSize( entry.getLoadedKey(), session );
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
throwLazyInitializationExceptionIfNotConnected();
|
||||
else {
|
||||
read();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
throwLazyInitializationExceptionIfNotConnected();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
if ( isExtraLazy ) {
|
||||
return true;
|
||||
}
|
||||
return isExtraLazy;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -200,13 +193,13 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
*
|
||||
* @param <T> The java type of the return for this LazyInitializationWork
|
||||
*/
|
||||
public static interface LazyInitializationWork<T> {
|
||||
public interface LazyInitializationWork<T> {
|
||||
/**
|
||||
* Do the represented work and return the result.
|
||||
*
|
||||
* @return The result
|
||||
*/
|
||||
public T doWork();
|
||||
T doWork();
|
||||
}
|
||||
|
||||
private <T> T withTemporarySessionIfNeeded(LazyInitializationWork<T> lazyInitializationWork) {
|
||||
|
@ -299,22 +292,19 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
protected Boolean readIndexExistence(final Object index) {
|
||||
if ( !initialized ) {
|
||||
final Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded(
|
||||
new LazyInitializationWork<Boolean>() {
|
||||
@Override
|
||||
public Boolean doWork() {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
|
||||
final CollectionPersister persister = entry.getLoadedPersister();
|
||||
if ( persister.isExtraLazy() ) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
session.flush();
|
||||
}
|
||||
return persister.indexExists( entry.getLoadedKey(), index, session );
|
||||
() -> {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
|
||||
final CollectionPersister persister = entry.getLoadedPersister();
|
||||
if ( persister.isExtraLazy() ) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
session.flush();
|
||||
}
|
||||
else {
|
||||
read();
|
||||
}
|
||||
return null;
|
||||
return persister.indexExists( entry.getLoadedKey(), index, session );
|
||||
}
|
||||
else {
|
||||
read();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
if ( extraLazyExistenceCheck != null ) {
|
||||
|
@ -327,22 +317,19 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
protected Boolean readElementExistence(final Object element) {
|
||||
if ( !initialized ) {
|
||||
final Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded(
|
||||
new LazyInitializationWork<Boolean>() {
|
||||
@Override
|
||||
public Boolean doWork() {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
|
||||
final CollectionPersister persister = entry.getLoadedPersister();
|
||||
if ( persister.isExtraLazy() ) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
session.flush();
|
||||
}
|
||||
return persister.elementExists( entry.getLoadedKey(), element, session );
|
||||
() -> {
|
||||
final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this );
|
||||
final CollectionPersister persister = entry.getLoadedPersister();
|
||||
if ( persister.isExtraLazy() ) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
session.flush();
|
||||
}
|
||||
else {
|
||||
read();
|
||||
}
|
||||
return null;
|
||||
return persister.elementExists( entry.getLoadedKey(), element, session );
|
||||
}
|
||||
else {
|
||||
read();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
if ( extraLazyExistenceCheck != null ) {
|
||||
|
@ -356,7 +343,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
|
||||
protected Object readElementByIndex(final Object index) {
|
||||
if ( !initialized ) {
|
||||
class ExtraLazyElementByIndexReader implements LazyInitializationWork {
|
||||
class ExtraLazyElementByIndexReader implements LazyInitializationWork<Object> {
|
||||
private boolean isExtraLazy;
|
||||
private Object element;
|
||||
|
||||
|
@ -379,7 +366,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
final ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
|
||||
//noinspection unchecked
|
||||
withTemporarySessionIfNeeded( reader );
|
||||
if ( reader.isExtraLazy ) {
|
||||
return reader.element;
|
||||
|
@ -415,7 +401,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* Is this collection in a state that would allow us to
|
||||
* "queue" operations?
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean isOperationQueueEnabled() {
|
||||
return !initialized
|
||||
&& isConnectedToSession()
|
||||
|
@ -427,7 +412,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* "queue" puts? This is a special case, because of orphan
|
||||
* delete.
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean isPutQueueEnabled() {
|
||||
return !initialized
|
||||
&& isConnectedToSession()
|
||||
|
@ -439,7 +423,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* "queue" clear? This is a special case, because of orphan
|
||||
* delete.
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean isClearQueueEnabled() {
|
||||
return !initialized
|
||||
&& isConnectedToSession()
|
||||
|
@ -449,7 +432,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
/**
|
||||
* Is this the "inverse" end of a bidirectional association?
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean isInverseCollection() {
|
||||
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
|
||||
return ce != null && ce.getLoadedPersister().isInverse();
|
||||
|
@ -459,7 +441,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* Is this the "inverse" end of a bidirectional association with
|
||||
* no orphan delete enabled?
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean isInverseCollectionNoOrphanDelete() {
|
||||
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
|
||||
if ( ce == null ) {
|
||||
|
@ -473,7 +454,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* Is this the "inverse" end of a bidirectional one-to-many, or
|
||||
* of a collection with no orphan delete?
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected boolean isInverseOneToManyOrNoOrphanDelete() {
|
||||
final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this );
|
||||
if ( ce == null ) {
|
||||
|
@ -486,8 +466,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
/**
|
||||
* Queue an addition
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected final void queueOperation(DelayedOperation operation) {
|
||||
protected final void queueOperation(DelayedOperation<E> operation) {
|
||||
if ( operationQueue == null ) {
|
||||
operationQueue = new ArrayList<>( 10 );
|
||||
}
|
||||
|
@ -503,9 +482,9 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* merged to managed copy.
|
||||
*/
|
||||
public final void replaceQueuedOperationValues(CollectionPersister persister, Map copyCache) {
|
||||
for ( DelayedOperation operation : operationQueue ) {
|
||||
for ( DelayedOperation<?> operation : operationQueue ) {
|
||||
if ( ValueDelayedOperation.class.isInstance( operation ) ) {
|
||||
( (ValueDelayedOperation) operation ).replace( persister, copyCache );
|
||||
( (ValueDelayedOperation<?>) operation ).replace( persister, copyCache );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +494,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* add the queued elements to the underlying collection.
|
||||
*/
|
||||
protected final void performQueuedOperations() {
|
||||
for ( DelayedOperation operation : operationQueue ) {
|
||||
for ( DelayedOperation<?> operation : operationQueue ) {
|
||||
operation.operate();
|
||||
}
|
||||
clearOperationQueue();
|
||||
|
@ -588,12 +567,9 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
withTemporarySessionIfNeeded(
|
||||
new LazyInitializationWork<Object>() {
|
||||
@Override
|
||||
public Object doWork() {
|
||||
session.initializeCollection( AbstractPersistentCollection.this, writing );
|
||||
return null;
|
||||
}
|
||||
() -> {
|
||||
session.initializeCollection( AbstractPersistentCollection.this, writing );
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -792,7 +768,6 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
/**
|
||||
* Get the current snapshot from the session
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
protected final Serializable getSnapshot() {
|
||||
return session.getPersistenceContext().getSnapshot( this );
|
||||
}
|
||||
|
@ -813,13 +788,13 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public final Iterator queuedAdditionIterator() {
|
||||
public final Iterator<E> queuedAdditionIterator() {
|
||||
if ( hasQueuedOperations() ) {
|
||||
return new Iterator() {
|
||||
return new Iterator<E>() {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
public Object next() {
|
||||
public E next() {
|
||||
return operationQueue.get( index++ ).getAddedInstance();
|
||||
}
|
||||
|
||||
|
@ -840,19 +815,18 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public final Collection getQueuedOrphans(String entityName) {
|
||||
public final Collection<E> getQueuedOrphans(String entityName) {
|
||||
if ( hasQueuedOperations() ) {
|
||||
final Collection additions = new ArrayList( operationQueue.size() );
|
||||
final Collection removals = new ArrayList( operationQueue.size() );
|
||||
for ( DelayedOperation operation : operationQueue ) {
|
||||
final Collection<E> additions = new ArrayList<>( operationQueue.size() );
|
||||
final Collection<E> removals = new ArrayList<>( operationQueue.size() );
|
||||
for ( DelayedOperation<E> operation : operationQueue ) {
|
||||
additions.add( operation.getAddedInstance() );
|
||||
removals.add( operation.getOrphan() );
|
||||
}
|
||||
return getOrphans( removals, additions, entityName, session );
|
||||
}
|
||||
else {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -865,7 +839,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public abstract Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException;
|
||||
public abstract Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException;
|
||||
|
||||
/**
|
||||
* Get the session currently associated with this collection.
|
||||
|
@ -876,10 +850,10 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
return session;
|
||||
}
|
||||
|
||||
protected final class IteratorProxy implements Iterator {
|
||||
protected final Iterator itr;
|
||||
protected final class IteratorProxy<E> implements Iterator<E> {
|
||||
protected final Iterator<E> itr;
|
||||
|
||||
public IteratorProxy(Iterator itr) {
|
||||
public IteratorProxy(Iterator<E> itr) {
|
||||
this.itr = itr;
|
||||
}
|
||||
|
||||
|
@ -889,7 +863,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object next() {
|
||||
public E next() {
|
||||
return itr.next();
|
||||
}
|
||||
|
||||
|
@ -900,16 +874,15 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
}
|
||||
|
||||
protected final class ListIteratorProxy implements ListIterator {
|
||||
protected final ListIterator itr;
|
||||
protected final class ListIteratorProxy implements ListIterator<E> {
|
||||
protected final ListIterator<E> itr;
|
||||
|
||||
public ListIteratorProxy(ListIterator itr) {
|
||||
public ListIteratorProxy(ListIterator<E> itr) {
|
||||
this.itr = itr;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public void add(Object o) {
|
||||
public void add(E o) {
|
||||
write();
|
||||
itr.add( o );
|
||||
}
|
||||
|
@ -925,7 +898,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object next() {
|
||||
public E next() {
|
||||
return itr.next();
|
||||
}
|
||||
|
||||
|
@ -935,7 +908,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object previous() {
|
||||
public E previous() {
|
||||
return itr.previous();
|
||||
}
|
||||
|
||||
|
@ -951,30 +924,27 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public void set(Object o) {
|
||||
public void set(E o) {
|
||||
write();
|
||||
itr.set( o );
|
||||
}
|
||||
}
|
||||
|
||||
protected class SetProxy implements java.util.Set {
|
||||
protected final Collection set;
|
||||
protected class SetProxy<E> implements java.util.Set<E> {
|
||||
protected final Collection<E> set;
|
||||
|
||||
public SetProxy(Collection set) {
|
||||
public SetProxy(Collection<E> set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean add(Object o) {
|
||||
public boolean add(E o) {
|
||||
write();
|
||||
return set.add( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean addAll(Collection c) {
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
write();
|
||||
return set.addAll( c );
|
||||
}
|
||||
|
@ -991,8 +961,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsAll(Collection c) {
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return set.containsAll( c );
|
||||
}
|
||||
|
||||
|
@ -1002,8 +971,8 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
return new IteratorProxy( set.iterator() );
|
||||
public Iterator<E> iterator() {
|
||||
return new IteratorProxy<>( set.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1013,15 +982,13 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean removeAll(Collection c) {
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
write();
|
||||
return set.removeAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean retainAll(Collection c) {
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
write();
|
||||
return set.retainAll( c );
|
||||
}
|
||||
|
@ -1037,43 +1004,38 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public Object[] toArray(Object[] array) {
|
||||
public <A> A[] toArray(A[] array) {
|
||||
return set.toArray( array );
|
||||
}
|
||||
}
|
||||
|
||||
protected final class ListProxy implements java.util.List {
|
||||
protected final List list;
|
||||
protected final class ListProxy implements java.util.List<E> {
|
||||
protected final List<E> list;
|
||||
|
||||
public ListProxy(List list) {
|
||||
public ListProxy(List<E> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public void add(int index, Object value) {
|
||||
public void add(int index, E value) {
|
||||
write();
|
||||
list.add( index, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean add(Object o) {
|
||||
public boolean add(E o) {
|
||||
write();
|
||||
return list.add( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean addAll(Collection c) {
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
write();
|
||||
return list.addAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public boolean addAll(int i, Collection c) {
|
||||
public boolean addAll(int i, Collection<? extends E> c) {
|
||||
write();
|
||||
return list.addAll( i, c );
|
||||
}
|
||||
|
@ -1090,13 +1052,12 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsAll(Collection c) {
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return list.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int i) {
|
||||
public E get(int i) {
|
||||
return list.get( i );
|
||||
}
|
||||
|
||||
|
@ -1111,8 +1072,8 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
return new IteratorProxy( list.iterator() );
|
||||
public Iterator<E> iterator() {
|
||||
return new IteratorProxy<>( list.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1121,17 +1082,17 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public ListIterator listIterator() {
|
||||
public ListIterator<E> listIterator() {
|
||||
return new ListIteratorProxy( list.listIterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator listIterator(int i) {
|
||||
public ListIterator<E> listIterator(int i) {
|
||||
return new ListIteratorProxy( list.listIterator( i ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(int i) {
|
||||
public E remove(int i) {
|
||||
write();
|
||||
return list.remove( i );
|
||||
}
|
||||
|
@ -1143,22 +1104,19 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean removeAll(Collection c) {
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
write();
|
||||
return list.removeAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean retainAll(Collection c) {
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
write();
|
||||
return list.retainAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public Object set(int i, Object o) {
|
||||
public E set(int i, E o) {
|
||||
write();
|
||||
return list.set( i, o );
|
||||
}
|
||||
|
@ -1169,7 +1127,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
public List subList(int i, int j) {
|
||||
public List<E> subList(int i, int j) {
|
||||
return list.subList( i, j );
|
||||
}
|
||||
|
||||
|
@ -1179,8 +1137,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public Object[] toArray(Object[] array) {
|
||||
public <A> A[] toArray(A[] array) {
|
||||
return list.toArray( array );
|
||||
}
|
||||
|
||||
|
@ -1189,23 +1146,23 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
/**
|
||||
* Contract for operations which are part of a collection's operation queue.
|
||||
*/
|
||||
protected interface DelayedOperation {
|
||||
public void operate();
|
||||
protected interface DelayedOperation<E> {
|
||||
void operate();
|
||||
|
||||
public Object getAddedInstance();
|
||||
E getAddedInstance();
|
||||
|
||||
public Object getOrphan();
|
||||
E getOrphan();
|
||||
}
|
||||
|
||||
protected interface ValueDelayedOperation extends DelayedOperation {
|
||||
protected interface ValueDelayedOperation<E> extends DelayedOperation<E> {
|
||||
void replace(CollectionPersister collectionPersister, Map copyCache);
|
||||
}
|
||||
|
||||
protected abstract class AbstractValueDelayedOperation implements ValueDelayedOperation {
|
||||
private Object addedValue;
|
||||
private Object orphan;
|
||||
protected abstract class AbstractValueDelayedOperation implements ValueDelayedOperation<E> {
|
||||
private E addedValue;
|
||||
private E orphan;
|
||||
|
||||
protected AbstractValueDelayedOperation(Object addedValue, Object orphan) {
|
||||
protected AbstractValueDelayedOperation(E addedValue, E orphan) {
|
||||
this.addedValue = addedValue;
|
||||
this.orphan = orphan;
|
||||
}
|
||||
|
@ -1216,17 +1173,17 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
}
|
||||
|
||||
protected final Object getReplacement(Type type, Object current, Map copyCache) {
|
||||
return type.replace( current, null, session, owner, copyCache );
|
||||
protected final E getReplacement(Type type, Object current, Map copyCache) {
|
||||
return (E) type.replace( current, null, session, owner, copyCache );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object getAddedInstance() {
|
||||
public final E getAddedInstance() {
|
||||
return addedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object getOrphan() {
|
||||
public final E getOrphan() {
|
||||
return orphan;
|
||||
}
|
||||
}
|
||||
|
@ -1236,10 +1193,9 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* belong to the collection, and a collection of instances
|
||||
* that currently belong, return a collection of orphans
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc", "unchecked"})
|
||||
protected static Collection getOrphans(
|
||||
Collection oldElements,
|
||||
Collection currentElements,
|
||||
protected static <E> Collection<E> getOrphans(
|
||||
Collection<E> oldElements,
|
||||
Collection<E> currentElements,
|
||||
String entityName,
|
||||
SharedSessionContractImplementor session) throws HibernateException {
|
||||
|
||||
|
@ -1258,11 +1214,11 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
final boolean useIdDirect = mayUseIdDirect( idType );
|
||||
|
||||
// create the collection holding the Orphans
|
||||
final Collection res = new ArrayList();
|
||||
final Collection<E> res = new ArrayList<>();
|
||||
|
||||
// collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access
|
||||
final java.util.Set currentIds = new HashSet();
|
||||
final java.util.Set currentSaving = new IdentitySet();
|
||||
final java.util.Set<Object> currentIds = new HashSet<>();
|
||||
final java.util.Set<Object> currentSaving = new IdentitySet<>();
|
||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||
for ( Object current : currentElements ) {
|
||||
if ( current != null && ForeignKeys.isNotTransient( entityName, current, null, session ) ) {
|
||||
|
@ -1282,7 +1238,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
|
||||
// iterate over the *old* list
|
||||
for ( Object old : oldElements ) {
|
||||
for ( E old : oldElements ) {
|
||||
if ( !currentSaving.contains( old ) ) {
|
||||
final Object oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session );
|
||||
if ( !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) {
|
||||
|
@ -1312,7 +1268,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
* @param session The session
|
||||
*/
|
||||
public static void identityRemove(
|
||||
Collection list,
|
||||
Collection<?> list,
|
||||
Object entityInstance,
|
||||
String entityName,
|
||||
SharedSessionContractImplementor session) {
|
||||
|
@ -1322,7 +1278,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
final Type idType = entityPersister.getIdentifierType();
|
||||
|
||||
final Object idOfCurrent = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, entityInstance, session );
|
||||
final Iterator itr = list.iterator();
|
||||
final Iterator<?> itr = list.iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final Object idOfOld = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, itr.next(), session );
|
||||
if ( idType.isEqual( idOfCurrent, idOfOld, session.getFactory() ) ) {
|
||||
|
@ -1347,7 +1303,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
*/
|
||||
@Deprecated
|
||||
public static void identityRemove(
|
||||
Collection list,
|
||||
Collection<?> list,
|
||||
Object entityInstance,
|
||||
String entityName,
|
||||
SessionImplementor session) {
|
||||
|
|
|
@ -32,14 +32,14 @@ import org.hibernate.type.Type;
|
|||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PersistentBag extends AbstractPersistentCollection implements List {
|
||||
public class PersistentBag<E> extends AbstractPersistentCollection<E> implements List<E> {
|
||||
|
||||
protected List bag;
|
||||
protected List<E> bag;
|
||||
|
||||
/**
|
||||
* The Collection provided to a PersistentBag constructor
|
||||
*/
|
||||
private Collection providedCollection;
|
||||
private Collection<E> providedCollection;
|
||||
|
||||
/**
|
||||
* Constructs a PersistentBag. Needed for SOAP libraries, etc
|
||||
|
@ -75,15 +75,14 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
* @param session The session
|
||||
* @param coll The base elements.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public PersistentBag(SharedSessionContractImplementor session, Collection coll) {
|
||||
public PersistentBag(SharedSessionContractImplementor session, Collection<E> coll) {
|
||||
super( session );
|
||||
providedCollection = coll;
|
||||
if ( coll instanceof List ) {
|
||||
bag = (List) coll;
|
||||
bag = (List<E>) coll;
|
||||
}
|
||||
else {
|
||||
bag = new ArrayList( coll );
|
||||
bag = new ArrayList<>( coll );
|
||||
}
|
||||
setInitialized();
|
||||
setDirectlyAccessible( true );
|
||||
|
@ -99,7 +98,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
* should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentBag(SessionImplementor session, Collection coll) {
|
||||
public PersistentBag(SessionImplementor session, Collection<E> coll) {
|
||||
this( (SharedSessionContractImplementor) session, coll );
|
||||
}
|
||||
|
||||
|
@ -119,33 +118,31 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator entries(CollectionPersister persister) {
|
||||
public Iterator<E> entries(CollectionPersister persister) {
|
||||
return bag.iterator();
|
||||
}
|
||||
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingState) {
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState) {
|
||||
assert bag == null;
|
||||
|
||||
final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor();
|
||||
final CollectionSemantics collectionSemantics = collectionDescriptor.getCollectionSemantics();
|
||||
final CollectionSemantics<?> collectionSemantics = collectionDescriptor.getCollectionSemantics();
|
||||
|
||||
final int elementCount = loadingState == null ? 0 : loadingState.size();
|
||||
|
||||
this.bag = (List) collectionSemantics.instantiateRaw( elementCount, collectionDescriptor );
|
||||
this.bag = (List<E>) collectionSemantics.instantiateRaw( elementCount, collectionDescriptor );
|
||||
|
||||
if ( loadingState != null ) {
|
||||
for ( int i = 0; i < elementCount; i++ ) {
|
||||
//noinspection unchecked
|
||||
bag.add( loadingState.get( i ) );
|
||||
bag.add( (E) loadingState.get( i ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final List<Object> sn = (List<Object>) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
if ( sn.size() != bag.size() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -196,7 +193,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
*
|
||||
* @return Map of "equality" hashCode to List of objects
|
||||
*/
|
||||
private Map<Integer, List<Object>> groupByEqualityHash(List<Object> searchedBag, Type elementType) {
|
||||
private Map<Integer, List<Object>> groupByEqualityHash(List<?> searchedBag, Type elementType) {
|
||||
if ( searchedBag.isEmpty() ) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
@ -208,8 +205,6 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
/**
|
||||
* @param o
|
||||
* @param elementType
|
||||
* @return the default elementType hashcode of the object o, or null if the object is null
|
||||
*/
|
||||
private Integer nullableHashCode(Object o, Type elementType) {
|
||||
|
@ -223,7 +218,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
|
||||
@Override
|
||||
public boolean isSnapshotEmpty(Serializable snapshot) {
|
||||
return ( (Collection) snapshot ).isEmpty();
|
||||
return ( (Collection<?>) snapshot ).isEmpty();
|
||||
}
|
||||
|
||||
private int countOccurrences(Object element, List<Object> list, Type elementType) {
|
||||
|
@ -249,26 +244,25 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Serializable getSnapshot(CollectionPersister persister)
|
||||
throws HibernateException {
|
||||
final ArrayList clonedList = new ArrayList( bag.size() );
|
||||
for ( Object item : bag ) {
|
||||
clonedList.add( persister.getElementType().deepCopy( item, persister.getFactory() ) );
|
||||
final ArrayList<E> clonedList = new ArrayList<>( bag.size() );
|
||||
for ( E item : bag ) {
|
||||
clonedList.add( (E) persister.getElementType().deepCopy( item, persister.getFactory() ) );
|
||||
}
|
||||
return clonedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final List sn = (List) snapshot;
|
||||
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final List<E> sn = (List<E>) snapshot;
|
||||
return getOrphans( sn, bag, entityName, getSession() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeEmptyCollection(CollectionPersister persister) {
|
||||
assert bag == null;
|
||||
bag = (List) persister.getCollectionType().instantiate( 0 );
|
||||
bag = (List<E>) persister.getCollectionType().instantiate( 0 );
|
||||
endRead();
|
||||
}
|
||||
|
||||
|
@ -283,7 +277,6 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializeFromCache(CollectionPersister collectionDescriptor, Object disassembled, Object owner)
|
||||
throws HibernateException {
|
||||
assert bag == null;
|
||||
|
@ -291,12 +284,12 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
final Serializable[] array = (Serializable[]) disassembled;
|
||||
final int size = array.length;
|
||||
|
||||
this.bag = (List) collectionDescriptor.getCollectionSemantics().instantiateRaw( size, collectionDescriptor );
|
||||
this.bag = (List<E>) collectionDescriptor.getCollectionSemantics().instantiateRaw( size, collectionDescriptor );
|
||||
|
||||
for ( Serializable item : array ) {
|
||||
final Object element = collectionDescriptor.getElementType().assemble( item, getSession(), owner );
|
||||
if ( element != null ) {
|
||||
bag.add( element );
|
||||
bag.add( (E) element );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,16 +308,15 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
// <one-to-many> <bag>!
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final ArrayList deletes = new ArrayList();
|
||||
final List sn = (List) getSnapshot();
|
||||
final Iterator olditer = sn.iterator();
|
||||
final ArrayList<Object> deletes = new ArrayList<>();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
final Iterator<?> olditer = sn.iterator();
|
||||
int i = 0;
|
||||
while ( olditer.hasNext() ) {
|
||||
final Object old = olditer.next();
|
||||
final Iterator newiter = bag.iterator();
|
||||
final Iterator<E> newiter = bag.iterator();
|
||||
boolean found = false;
|
||||
if ( bag.size() > i && elementType.isSame( old, bag.get( i++ ) ) ) {
|
||||
//a shortcut if its location didn't change!
|
||||
|
@ -349,7 +341,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
|
||||
@Override
|
||||
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException {
|
||||
final List sn = (List) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
if ( sn.size() > i && elemType.isSame( sn.get( i ), entry ) ) {
|
||||
//a shortcut if its location didn't change!
|
||||
return false;
|
||||
|
@ -393,9 +385,9 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
public Iterator<E> iterator() {
|
||||
read();
|
||||
return new IteratorProxy( bag.iterator() );
|
||||
return new IteratorProxy<>( bag.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -405,14 +397,13 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray(Object[] a) {
|
||||
public <A> A[] toArray(A[] a) {
|
||||
read();
|
||||
return bag.toArray( a );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean add(Object object) {
|
||||
public boolean add(E object) {
|
||||
if ( !isOperationQueueEnabled() ) {
|
||||
write();
|
||||
return bag.add( object );
|
||||
|
@ -437,15 +428,13 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsAll(Collection c) {
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
read();
|
||||
return bag.containsAll( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean addAll(Collection values) {
|
||||
public boolean addAll(Collection<? extends E> values) {
|
||||
if ( values.size() == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -454,7 +443,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
return bag.addAll( values );
|
||||
}
|
||||
else {
|
||||
for ( Object value : values ) {
|
||||
for ( E value : values ) {
|
||||
queueOperation( new SimpleAdd( value ) );
|
||||
}
|
||||
return values.size() > 0;
|
||||
|
@ -462,8 +451,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean removeAll(Collection c) {
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
if ( c.size() > 0 ) {
|
||||
initialize( true );
|
||||
if ( bag.removeAll( c ) ) {
|
||||
|
@ -481,8 +469,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean retainAll(Collection c) {
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
initialize( true );
|
||||
if ( bag.retainAll( c ) ) {
|
||||
dirty();
|
||||
|
@ -494,7 +481,6 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void clear() {
|
||||
if ( isClearQueueEnabled() ) {
|
||||
queueOperation( new Clear() );
|
||||
|
@ -520,7 +506,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
|
||||
@Override
|
||||
public Object getSnapshotElement(Object entry, int i) {
|
||||
final List sn = (List) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
return sn.get( i );
|
||||
}
|
||||
|
||||
|
@ -534,7 +520,7 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
@SuppressWarnings("UnusedDeclaration")
|
||||
public int occurrences(Object o) {
|
||||
read();
|
||||
final Iterator itr = bag.iterator();
|
||||
final Iterator<E> itr = bag.iterator();
|
||||
int result = 0;
|
||||
while ( itr.hasNext() ) {
|
||||
if ( o.equals( itr.next() ) ) {
|
||||
|
@ -547,15 +533,13 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
// List OPERATIONS:
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void add(int i, Object o) {
|
||||
public void add(int i, E o) {
|
||||
write();
|
||||
bag.add( i, o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean addAll(int i, Collection c) {
|
||||
public boolean addAll(int i, Collection<? extends E> c) {
|
||||
if ( c.size() > 0 ) {
|
||||
write();
|
||||
return bag.addAll( i, c );
|
||||
|
@ -566,57 +550,49 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object get(int i) {
|
||||
public E get(int i) {
|
||||
read();
|
||||
return bag.get( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int indexOf(Object o) {
|
||||
read();
|
||||
return bag.indexOf( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int lastIndexOf(Object o) {
|
||||
read();
|
||||
return bag.lastIndexOf( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ListIterator listIterator() {
|
||||
public ListIterator<E> listIterator() {
|
||||
read();
|
||||
return new ListIteratorProxy( bag.listIterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ListIterator listIterator(int i) {
|
||||
public ListIterator<E> listIterator(int i) {
|
||||
read();
|
||||
return new ListIteratorProxy( bag.listIterator( i ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object remove(int i) {
|
||||
public E remove(int i) {
|
||||
write();
|
||||
return bag.remove( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object set(int i, Object o) {
|
||||
public E set(int i, E o) {
|
||||
write();
|
||||
return bag.set( i, o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List subList(int start, int end) {
|
||||
public List<E> subList(int start, int end) {
|
||||
read();
|
||||
return new ListProxy( bag.subList( start, end ) );
|
||||
}
|
||||
|
@ -652,31 +628,30 @@ public class PersistentBag extends AbstractPersistentCollection implements List
|
|||
return super.hashCode();
|
||||
}
|
||||
|
||||
final class Clear implements DelayedOperation {
|
||||
final class Clear implements DelayedOperation<E> {
|
||||
@Override
|
||||
public void operate() {
|
||||
bag.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAddedInstance() {
|
||||
public E getAddedInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOrphan() {
|
||||
public E getOrphan() {
|
||||
throw new UnsupportedOperationException( "queued clear cannot be used with orphan delete" );
|
||||
}
|
||||
}
|
||||
|
||||
final class SimpleAdd extends AbstractValueDelayedOperation {
|
||||
|
||||
public SimpleAdd(Object addedValue) {
|
||||
public SimpleAdd(E addedValue) {
|
||||
super( addedValue, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
bag.add( getAddedInstance() );
|
||||
}
|
||||
|
|
|
@ -35,14 +35,14 @@ import org.hibernate.type.Type;
|
|||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PersistentIdentifierBag extends AbstractPersistentCollection implements List {
|
||||
protected List<Object> values;
|
||||
public class PersistentIdentifierBag<E> extends AbstractPersistentCollection<E> implements List<E> {
|
||||
protected List<E> values;
|
||||
protected Map<Integer, Object> identifiers;
|
||||
|
||||
/**
|
||||
* The Collection provided to a PersistentIdentifierBag constructor
|
||||
*/
|
||||
private Collection providedValues;
|
||||
private Collection<E> providedValues;
|
||||
|
||||
/**
|
||||
* Constructs a PersistentIdentifierBag. This form needed for SOAP libraries, etc
|
||||
|
@ -77,12 +77,11 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
* @param session The session
|
||||
* @param coll The base elements
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public PersistentIdentifierBag(SharedSessionContractImplementor session, Collection coll) {
|
||||
public PersistentIdentifierBag(SharedSessionContractImplementor session, Collection<E> coll) {
|
||||
super( session );
|
||||
providedValues = coll;
|
||||
if (coll instanceof List) {
|
||||
values = (List<Object>) coll;
|
||||
values = (List<E>) coll;
|
||||
}
|
||||
else {
|
||||
values = new ArrayList<>( coll );
|
||||
|
@ -100,7 +99,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
* @deprecated {@link #PersistentIdentifierBag(SharedSessionContractImplementor, Collection)} should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentIdentifierBag(SessionImplementor session, Collection coll) {
|
||||
public PersistentIdentifierBag(SessionImplementor session, Collection<E> coll) {
|
||||
this( (SharedSessionContractImplementor) session, coll );
|
||||
}
|
||||
|
||||
|
@ -123,7 +122,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
(i/2),
|
||||
persister.getIdentifierType().assemble( array[i], getSession(), owner )
|
||||
);
|
||||
values.add( persister.getElementType().assemble( array[i+1], getSession(), owner ) );
|
||||
values.add( (E) persister.getElementType().assemble( array[i+1], getSession(), owner ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,7 +142,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Object o) {
|
||||
public boolean add(E o) {
|
||||
write();
|
||||
values.add( o );
|
||||
return true;
|
||||
|
@ -166,7 +165,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection c) {
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
read();
|
||||
return values.containsAll( c );
|
||||
}
|
||||
|
@ -177,9 +176,9 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
public Iterator<E> iterator() {
|
||||
read();
|
||||
return new IteratorProxy( values.iterator() );
|
||||
return new IteratorProxy<>( values.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -215,7 +214,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection c) {
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
initialize( true );
|
||||
if ( values.retainAll( c ) ) {
|
||||
dirty();
|
||||
|
@ -238,7 +237,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray(Object[] a) {
|
||||
public <A> A[] toArray(A[] a) {
|
||||
read();
|
||||
return values.toArray( a );
|
||||
}
|
||||
|
@ -261,7 +260,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator entries(CollectionPersister persister) {
|
||||
public Iterator<E> entries(CollectionPersister persister) {
|
||||
return values.iterator();
|
||||
}
|
||||
|
||||
|
@ -273,7 +272,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
@Override
|
||||
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final Map snap = (Map) getSnapshot();
|
||||
final Map<?,?> snap = (Map<?,?>) getSnapshot();
|
||||
if ( snap.size()!= values.size() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -293,14 +292,13 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
|
||||
@Override
|
||||
public boolean isSnapshotEmpty(Serializable snapshot) {
|
||||
return ( (Map) snapshot ).isEmpty();
|
||||
return ( (Map<?,?>) snapshot ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final Map snap = (Map) getSnapshot();
|
||||
final List deletes = new ArrayList( snap.keySet() );
|
||||
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final Map<?,?> snap = (Map<?,?>) getSnapshot();
|
||||
final List<Object> deletes = new ArrayList<>( snap.keySet() );
|
||||
for ( int i=0; i<values.size(); i++ ) {
|
||||
if ( values.get( i ) != null ) {
|
||||
deletes.remove( identifiers.get( i ) );
|
||||
|
@ -321,7 +319,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
|
||||
@Override
|
||||
public Object getSnapshotElement(Object entry, int i) {
|
||||
final Map snap = (Map) getSnapshot();
|
||||
final Map<?,?> snap = (Map<?,?>) getSnapshot();
|
||||
final Object id = identifiers.get( i );
|
||||
return snap.get( id );
|
||||
}
|
||||
|
@ -329,7 +327,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
@Override
|
||||
public boolean needsInserting(Object entry, int i, Type elemType)
|
||||
throws HibernateException {
|
||||
final Map snap = (Map) getSnapshot();
|
||||
final Map<?,?> snap = (Map<?,?>) getSnapshot();
|
||||
final Object id = identifiers.get( i );
|
||||
return entry != null
|
||||
&& ( id==null || snap.get( id )==null );
|
||||
|
@ -341,7 +339,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
return false;
|
||||
}
|
||||
|
||||
final Map snap = (Map) getSnapshot();
|
||||
final Map<?,?> snap = (Map<?,?>) getSnapshot();
|
||||
final Object id = identifiers.get( i );
|
||||
if ( id == null ) {
|
||||
return false;
|
||||
|
@ -352,24 +350,23 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final HashMap map = CollectionHelper.mapOfSize( values.size() );
|
||||
final Iterator iter = values.iterator();
|
||||
final HashMap<Object,E> map = CollectionHelper.mapOfSize( values.size() );
|
||||
final Iterator<E> iter = values.iterator();
|
||||
int i=0;
|
||||
while ( iter.hasNext() ) {
|
||||
final Object value = iter.next();
|
||||
map.put(
|
||||
identifiers.get( i++ ),
|
||||
persister.getElementType().deepCopy( value, persister.getFactory() )
|
||||
(E) persister.getElementType().deepCopy( value, persister.getFactory() )
|
||||
);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final Map sn = (Map) snapshot;
|
||||
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final Map<Object,E> sn = (Map<Object,E>) snapshot;
|
||||
return getOrphans( sn.values(), values, entityName, getSession() );
|
||||
}
|
||||
|
||||
|
@ -383,10 +380,10 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
|
||||
@Override
|
||||
public void preInsert(CollectionPersister persister) throws HibernateException {
|
||||
final Iterator itr = values.iterator();
|
||||
final Iterator<E> itr = values.iterator();
|
||||
int i = 0;
|
||||
while ( itr.hasNext() ) {
|
||||
final Object entry = itr.next();
|
||||
final E entry = itr.next();
|
||||
final Integer loc = i++;
|
||||
if ( !identifiers.containsKey( loc ) ) {
|
||||
//TODO: native ids
|
||||
|
@ -397,16 +394,16 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Object element) {
|
||||
public void add(int index, E element) {
|
||||
write();
|
||||
beforeAdd( index );
|
||||
values.add( index, element );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection c) {
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
if ( c.size() > 0 ) {
|
||||
for ( Object element : c ) {
|
||||
for ( E element : c ) {
|
||||
add( index++, element );
|
||||
}
|
||||
return true;
|
||||
|
@ -417,7 +414,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
public E get(int index) {
|
||||
read();
|
||||
return values.get( index );
|
||||
}
|
||||
|
@ -435,13 +432,13 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public ListIterator listIterator() {
|
||||
public ListIterator<E> listIterator() {
|
||||
read();
|
||||
return new ListIteratorProxy( values.listIterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator listIterator(int index) {
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
read();
|
||||
return new ListIteratorProxy( values.listIterator( index ) );
|
||||
}
|
||||
|
@ -469,26 +466,26 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object remove(int index) {
|
||||
public E remove(int index) {
|
||||
write();
|
||||
beforeRemove( index );
|
||||
return values.remove( index );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object set(int index, Object element) {
|
||||
public E set(int index, E element) {
|
||||
write();
|
||||
return values.set( index, element );
|
||||
}
|
||||
|
||||
@Override
|
||||
public List subList(int fromIndex, int toIndex) {
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
read();
|
||||
return new ListProxy( values.subList( fromIndex, toIndex ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection c) {
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
if ( c.size()> 0 ) {
|
||||
write();
|
||||
return values.addAll( c );
|
||||
|
@ -506,7 +503,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
//TODO: if we are using identity columns, fetch the identifier
|
||||
}
|
||||
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingState) {
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState) {
|
||||
assert identifiers == null;
|
||||
assert values == null;
|
||||
|
||||
|
@ -516,7 +513,7 @@ public class PersistentIdentifierBag extends AbstractPersistentCollection implem
|
|||
for ( int i = 0; i < loadingState.size(); i++ ) {
|
||||
final Object[] row = (Object[]) loadingState.get( i );
|
||||
final Object identifier = row[0];
|
||||
final Object element = row[1];
|
||||
final E element = (E) row[1];
|
||||
|
||||
Object old = identifiers.put( values.size(), identifier );
|
||||
if ( old == null ) {
|
||||
|
|
|
@ -27,8 +27,8 @@ import org.hibernate.type.Type;
|
|||
* @see java.util.ArrayList
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PersistentList extends AbstractPersistentCollection implements List {
|
||||
protected List list;
|
||||
public class PersistentList<E> extends AbstractPersistentCollection<E> implements List<E> {
|
||||
protected List<E> list;
|
||||
|
||||
/**
|
||||
* Constructs a PersistentList. This form needed for SOAP libraries, etc
|
||||
|
@ -62,7 +62,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
* @param session The session
|
||||
* @param list The raw list
|
||||
*/
|
||||
public PersistentList(SharedSessionContractImplementor session, List list) {
|
||||
public PersistentList(SharedSessionContractImplementor session, List<E> list) {
|
||||
super( session );
|
||||
this.list = list;
|
||||
setInitialized();
|
||||
|
@ -77,14 +77,13 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
* @deprecated {@link #PersistentList(SharedSessionContractImplementor, List)} should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentList(SessionImplementor session, List list) {
|
||||
public PersistentList(SessionImplementor session, List<E> list) {
|
||||
this( (SharedSessionContractImplementor) session, list );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final ArrayList clonedList = new ArrayList( list.size() );
|
||||
final ArrayList<Object> clonedList = new ArrayList<>( list.size() );
|
||||
for ( Object element : list ) {
|
||||
final Object deepCopy = persister.getElementType().deepCopy( element, persister.getFactory() );
|
||||
clonedList.add( deepCopy );
|
||||
|
@ -93,27 +92,27 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final List sn = (List) snapshot;
|
||||
return getOrphans( sn, list, entityName, getSession() );
|
||||
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
return getOrphans( (List<E>) snapshot, list, entityName, getSession() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializeEmptyCollection(CollectionPersister persister) {
|
||||
assert list == null;
|
||||
list = (List) persister.getCollectionType().instantiate( 0 );
|
||||
list = (List<E>) persister.getCollectionType().instantiate( 0 );
|
||||
endRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final List sn = (List) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
if ( sn.size() != this.list.size() ) {
|
||||
return false;
|
||||
}
|
||||
final Iterator itr = list.iterator();
|
||||
final Iterator snapshotItr = sn.iterator();
|
||||
final Iterator<?> itr = list.iterator();
|
||||
final Iterator<?> snapshotItr = sn.iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
if ( elementType.isDirty( itr.next(), snapshotItr.next(), getSession() ) ) {
|
||||
return false;
|
||||
|
@ -124,7 +123,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
@Override
|
||||
public boolean isSnapshotEmpty(Serializable snapshot) {
|
||||
return ( (Collection) snapshot ).isEmpty();
|
||||
return ( (Collection<?>) snapshot ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,27 +134,26 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
final int size = array.length;
|
||||
|
||||
assert list == null;
|
||||
this.list = (List) persister.getCollectionType().instantiate( size );
|
||||
this.list = (List<E>) persister.getCollectionType().instantiate( size );
|
||||
|
||||
for ( Serializable arrayElement : array ) {
|
||||
list.add( persister.getElementType().assemble( arrayElement, getSession(), owner ) );
|
||||
list.add( (E) persister.getElementType().assemble( arrayElement, getSession(), owner ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingStateList) {
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingStateList) {
|
||||
assert isInitializing();
|
||||
assert list == null;
|
||||
|
||||
final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor();
|
||||
|
||||
this.list = (List) collectionDescriptor.getCollectionSemantics().instantiateRaw(
|
||||
this.list = (List<E>) collectionDescriptor.getCollectionSemantics().instantiateRaw(
|
||||
loadingStateList.size(),
|
||||
collectionDescriptor
|
||||
);
|
||||
|
||||
//noinspection unchecked
|
||||
list.addAll( loadingStateList );
|
||||
list.addAll( (List<E>) loadingStateList );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,9 +180,9 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
public Iterator<E> iterator() {
|
||||
read();
|
||||
return new IteratorProxy( list.iterator() );
|
||||
return new IteratorProxy<>( list.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -194,14 +192,13 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray(Object[] array) {
|
||||
public <A> A[] toArray(A[] array) {
|
||||
read();
|
||||
return list.toArray( array );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean add(Object object) {
|
||||
public boolean add(E object) {
|
||||
if ( !isOperationQueueEnabled() ) {
|
||||
write();
|
||||
return list.add( object );
|
||||
|
@ -228,7 +225,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
else if ( exists ) {
|
||||
elementRemoved = true;
|
||||
queueOperation( new SimpleRemove( value ) );
|
||||
queueOperation( new SimpleRemove( (E) value ) );
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -237,15 +234,13 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection coll) {
|
||||
public boolean containsAll(Collection<?> coll) {
|
||||
read();
|
||||
//noinspection unchecked
|
||||
return list.containsAll( coll );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean addAll(Collection values) {
|
||||
public boolean addAll(Collection<? extends E> values) {
|
||||
if ( values.size() == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -254,7 +249,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
return list.addAll( values );
|
||||
}
|
||||
else {
|
||||
for ( Object value : values ) {
|
||||
for ( E value : values ) {
|
||||
queueOperation( new SimpleAdd( value ) );
|
||||
}
|
||||
return values.size() > 0;
|
||||
|
@ -262,11 +257,10 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean addAll(int index, Collection coll) {
|
||||
public boolean addAll(int index, Collection<? extends E> coll) {
|
||||
if ( coll.size() > 0 ) {
|
||||
write();
|
||||
return list.addAll( index, coll );
|
||||
return list.addAll( index, coll );
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
@ -274,8 +268,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean removeAll(Collection coll) {
|
||||
public boolean removeAll(Collection<?> coll) {
|
||||
if ( coll.size() > 0 ) {
|
||||
initialize( true );
|
||||
if ( list.removeAll( coll ) ) {
|
||||
|
@ -293,9 +286,8 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection coll) {
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
initialize( true );
|
||||
//noinspection unchecked
|
||||
if ( list.retainAll( coll ) ) {
|
||||
dirty();
|
||||
return true;
|
||||
|
@ -320,16 +312,16 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
public E get(int index) {
|
||||
if ( index < 0 ) {
|
||||
throw new ArrayIndexOutOfBoundsException( "negative index" );
|
||||
}
|
||||
final Object result = readElementByIndex( index );
|
||||
return result == UNKNOWN ? list.get( index ) : result;
|
||||
return result == UNKNOWN ? list.get( index ) : (E) result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object set(int index, Object value) {
|
||||
public E set(int index, E value) {
|
||||
if (index<0) {
|
||||
throw new ArrayIndexOutOfBoundsException("negative index");
|
||||
}
|
||||
|
@ -338,17 +330,16 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
if ( old==UNKNOWN ) {
|
||||
write();
|
||||
//noinspection unchecked
|
||||
return list.set( index, value );
|
||||
}
|
||||
else {
|
||||
queueOperation( new Set( index, value, old ) );
|
||||
return old;
|
||||
queueOperation( new Set( index, value, (E) old ) );
|
||||
return (E) old;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(int index) {
|
||||
public E remove(int index) {
|
||||
if ( index < 0 ) {
|
||||
throw new ArrayIndexOutOfBoundsException( "negative index" );
|
||||
}
|
||||
|
@ -360,18 +351,17 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
return list.remove( index );
|
||||
}
|
||||
else {
|
||||
queueOperation( new Remove( index, old ) );
|
||||
return old;
|
||||
queueOperation( new Remove( index, (E) old ) );
|
||||
return (E) old;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Object value) {
|
||||
public void add(int index, E value) {
|
||||
if ( index < 0 ) {
|
||||
throw new ArrayIndexOutOfBoundsException( "negative index" );
|
||||
}
|
||||
write();
|
||||
//noinspection unchecked
|
||||
list.add( index, value );
|
||||
}
|
||||
|
||||
|
@ -388,19 +378,19 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public ListIterator listIterator() {
|
||||
public ListIterator<E> listIterator() {
|
||||
read();
|
||||
return new ListIteratorProxy( list.listIterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator listIterator(int index) {
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
read();
|
||||
return new ListIteratorProxy( list.listIterator( index ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List subList(int from, int to) {
|
||||
public java.util.List<E> subList(int from, int to) {
|
||||
read();
|
||||
return new ListProxy( list.subList( from, to ) );
|
||||
}
|
||||
|
@ -417,7 +407,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator entries(CollectionPersister persister) {
|
||||
public Iterator<E> entries(CollectionPersister persister) {
|
||||
return list.iterator();
|
||||
}
|
||||
|
||||
|
@ -432,10 +422,9 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final List deletes = new ArrayList();
|
||||
final List sn = (List) getSnapshot();
|
||||
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final List<Object> deletes = new ArrayList<>();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
int end;
|
||||
if ( sn.size() > list.size() ) {
|
||||
for ( int i=list.size(); i<sn.size(); i++ ) {
|
||||
|
@ -458,13 +447,13 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
@Override
|
||||
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException {
|
||||
final List sn = (List) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
return list.get( i ) != null && ( i >= sn.size() || sn.get( i ) == null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException {
|
||||
final List sn = (List) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
return i < sn.size()
|
||||
&& sn.get( i ) != null
|
||||
&& list.get( i ) != null
|
||||
|
@ -483,7 +472,7 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
@Override
|
||||
public Object getSnapshotElement(Object entry, int i) {
|
||||
final List sn = (List) getSnapshot();
|
||||
final List<?> sn = (List<?>) getSnapshot();
|
||||
return sn.get( i );
|
||||
}
|
||||
|
||||
|
@ -505,40 +494,39 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
return entry!=null;
|
||||
}
|
||||
|
||||
final class Clear implements DelayedOperation {
|
||||
final class Clear implements DelayedOperation<E> {
|
||||
@Override
|
||||
public void operate() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAddedInstance() {
|
||||
public E getAddedInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOrphan() {
|
||||
public E getOrphan() {
|
||||
throw new UnsupportedOperationException( "queued clear cannot be used with orphan delete" );
|
||||
}
|
||||
}
|
||||
|
||||
final class SimpleAdd extends AbstractValueDelayedOperation {
|
||||
|
||||
public SimpleAdd(Object addedValue) {
|
||||
public SimpleAdd(E addedValue) {
|
||||
super( addedValue, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
list.add( getAddedInstance() );
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractListValueDelayedOperation extends AbstractValueDelayedOperation {
|
||||
private int index;
|
||||
private final int index;
|
||||
|
||||
AbstractListValueDelayedOperation(Integer index, Object addedValue, Object orphan) {
|
||||
AbstractListValueDelayedOperation(Integer index, E addedValue, E orphan) {
|
||||
super( addedValue, orphan );
|
||||
this.index = index;
|
||||
}
|
||||
|
@ -550,12 +538,11 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
final class Add extends AbstractListValueDelayedOperation {
|
||||
|
||||
public Add(int index, Object addedValue) {
|
||||
public Add(int index, E addedValue) {
|
||||
super( index, addedValue, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
list.add( getIndex(), getAddedInstance() );
|
||||
}
|
||||
|
@ -563,12 +550,11 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
final class Set extends AbstractListValueDelayedOperation {
|
||||
|
||||
public Set(int index, Object addedValue, Object orphan) {
|
||||
public Set(int index, E addedValue, E orphan) {
|
||||
super( index, addedValue, orphan );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
list.set( getIndex(), getAddedInstance() );
|
||||
}
|
||||
|
@ -576,12 +562,11 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
final class Remove extends AbstractListValueDelayedOperation {
|
||||
|
||||
public Remove(int index, Object orphan) {
|
||||
public Remove(int index, E orphan) {
|
||||
super( index, null, orphan );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
list.remove( getIndex() );
|
||||
}
|
||||
|
@ -589,12 +574,11 @@ public class PersistentList extends AbstractPersistentCollection implements List
|
|||
|
||||
final class SimpleRemove extends AbstractValueDelayedOperation {
|
||||
|
||||
public SimpleRemove(Object orphan) {
|
||||
public SimpleRemove(E orphan) {
|
||||
super( null, orphan );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
list.remove( getOrphan() );
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ import org.hibernate.type.Type;
|
|||
* @see java.util.HashMap
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PersistentMap extends AbstractPersistentCollection implements Map {
|
||||
public class PersistentMap<K,E> extends AbstractPersistentCollection<E> implements Map<K,E> {
|
||||
|
||||
protected Map map;
|
||||
protected Map<K,E> map;
|
||||
|
||||
/**
|
||||
* Empty constructor.
|
||||
|
@ -72,7 +72,7 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
* @param session The session to which this map will belong.
|
||||
* @param map The underlying map data.
|
||||
*/
|
||||
public PersistentMap(SharedSessionContractImplementor session, Map map) {
|
||||
public PersistentMap(SharedSessionContractImplementor session, Map<K,E> map) {
|
||||
super( session );
|
||||
this.map = map;
|
||||
setInitialized();
|
||||
|
@ -88,45 +88,42 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
* @deprecated {@link #PersistentMap(SharedSessionContractImplementor, Map)} should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentMap(SessionImplementor session, Map map) {
|
||||
public PersistentMap(SessionImplementor session, Map<K,E> map) {
|
||||
this( (SharedSessionContractImplementor) session, map );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final HashMap clonedMap = CollectionHelper.mapOfSize( map.size() );
|
||||
for ( Object o : map.entrySet() ) {
|
||||
final Entry e = (Entry) o;
|
||||
final Object copy = persister.getElementType().deepCopy( e.getValue(), persister.getFactory() );
|
||||
final HashMap<K,E> clonedMap = CollectionHelper.mapOfSize( map.size() );
|
||||
for ( Entry<K,E> e : map.entrySet() ) {
|
||||
final E copy = (E) persister.getElementType().deepCopy( e.getValue(), persister.getFactory() );
|
||||
clonedMap.put( e.getKey(), copy );
|
||||
}
|
||||
return clonedMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final Map sn = (Map) snapshot;
|
||||
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final Map<K,E> sn = (Map<K,E>) snapshot;
|
||||
return getOrphans( sn.values(), map.values(), entityName, getSession() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeEmptyCollection(CollectionPersister persister) {
|
||||
assert map == null;
|
||||
map = (Map) persister.getCollectionType().instantiate( 0 );
|
||||
map = (Map<K,E>) persister.getCollectionType().instantiate( 0 );
|
||||
endRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final Map snapshotMap = (Map) getSnapshot();
|
||||
final Map<?,?> snapshotMap = (Map<?,?>) getSnapshot();
|
||||
if ( snapshotMap.size() != this.map.size() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ( Object o : map.entrySet() ) {
|
||||
final Entry entry = (Entry) o;
|
||||
for ( Entry<?,?> entry : map.entrySet() ) {
|
||||
if ( elementType.isDirty( entry.getValue(), snapshotMap.get( entry.getKey() ), getSession() ) ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -136,7 +133,7 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
|
||||
@Override
|
||||
public boolean isSnapshotEmpty(Serializable snapshot) {
|
||||
return ( (Map) snapshot ).isEmpty();
|
||||
return ( (Map<?,?>) snapshot ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -169,25 +166,24 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object get(Object key) {
|
||||
public E get(Object key) {
|
||||
final Object result = readElementByIndex( key );
|
||||
return result == UNKNOWN
|
||||
? map.get( key )
|
||||
: result;
|
||||
: (E) result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object put(Object key, Object value) {
|
||||
public E put(K key, E value) {
|
||||
if ( isPutQueueEnabled() ) {
|
||||
final Object old = readElementByIndex( key );
|
||||
if ( old != UNKNOWN ) {
|
||||
queueOperation( new Put( key, value, old ) );
|
||||
return old;
|
||||
queueOperation( new Put( key, value, (E) old ) );
|
||||
return (E) old;
|
||||
}
|
||||
}
|
||||
initialize( true );
|
||||
//noinspection unchecked
|
||||
final Object old = map.put( key, value );
|
||||
final E old = map.put( key, value );
|
||||
// would be better to use the element-type to determine
|
||||
// whether the old and the new are equal here; the problem being
|
||||
// we do not necessarily have access to the element type in all
|
||||
|
@ -199,13 +195,13 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object remove(Object key) {
|
||||
public E remove(Object key) {
|
||||
if ( isPutQueueEnabled() ) {
|
||||
final Object old = readElementByIndex( key );
|
||||
if ( old != UNKNOWN ) {
|
||||
elementRemoved = true;
|
||||
queueOperation( new Remove( key, old ) );
|
||||
return old;
|
||||
queueOperation( new Remove( (K) key, (E) old ) );
|
||||
return (E) old;
|
||||
}
|
||||
}
|
||||
// TODO : safe to interpret "map.remove(key) == null" as non-dirty?
|
||||
|
@ -218,11 +214,10 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map puts) {
|
||||
public void putAll(Map<? extends K,? extends E> puts) {
|
||||
if ( puts.size() > 0 ) {
|
||||
initialize( true );
|
||||
for ( Object o : puts.entrySet() ) {
|
||||
final Entry entry = (Entry) o;
|
||||
for ( Entry<? extends K,? extends E> entry : puts.entrySet() ) {
|
||||
put( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
@ -243,19 +238,19 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set keySet() {
|
||||
public Set<K> keySet() {
|
||||
read();
|
||||
return new SetProxy( map.keySet() );
|
||||
return new SetProxy<>( map.keySet() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection values() {
|
||||
public Collection<E> values() {
|
||||
read();
|
||||
return new SetProxy( map.values() );
|
||||
return new SetProxy<>( map.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set entrySet() {
|
||||
public Set<Entry<K,E>> entrySet() {
|
||||
read();
|
||||
return new EntrySetProxy( map.entrySet() );
|
||||
}
|
||||
|
@ -272,37 +267,35 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator entries(CollectionPersister persister) {
|
||||
public Iterator<Entry<K,E>> entries(CollectionPersister persister) {
|
||||
return map.entrySet().iterator();
|
||||
}
|
||||
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingState) {
|
||||
public void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState) {
|
||||
assert isInitializing();
|
||||
assert map == null;
|
||||
|
||||
final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor();
|
||||
this.map = (Map) collectionDescriptor.getCollectionSemantics().instantiateRaw( loadingState.size(), collectionDescriptor );
|
||||
this.map = (Map<K,E>) collectionDescriptor.getCollectionSemantics().instantiateRaw( loadingState.size(), collectionDescriptor );
|
||||
|
||||
for ( int i = 0; i < loadingState.size(); i++ ) {
|
||||
final Object[] keyVal = (Object[]) loadingState.get( i );
|
||||
//noinspection unchecked
|
||||
map.put( keyVal[0], keyVal[1] );
|
||||
map.put( (K) keyVal[0], (E) keyVal[1] );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializeFromCache(CollectionPersister persister, Object disassembled, Object owner)
|
||||
throws HibernateException {
|
||||
final Serializable[] array = (Serializable[]) disassembled;
|
||||
final int size = array.length;
|
||||
|
||||
this.map = (Map) persister.getCollectionSemantics().instantiateRaw( size, persister );
|
||||
this.map = (Map<K,E>) persister.getCollectionSemantics().instantiateRaw( size, persister );
|
||||
|
||||
for ( int i = 0; i < size; i+=2 ) {
|
||||
map.put(
|
||||
persister.getIndexType().assemble( array[i], getSession(), owner ),
|
||||
persister.getElementType().assemble( array[i+1], getSession(), owner )
|
||||
(K) persister.getIndexType().assemble( array[i], getSession(), owner ),
|
||||
(E) persister.getElementType().assemble( array[i+1], getSession(), owner )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -310,10 +303,10 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
@Override
|
||||
public Object disassemble(CollectionPersister persister) throws HibernateException {
|
||||
final Object[] result = new Object[ map.size() * 2 ];
|
||||
final Iterator itr = map.entrySet().iterator();
|
||||
final Iterator<Entry<K,E>> itr = map.entrySet().iterator();
|
||||
int i=0;
|
||||
while ( itr.hasNext() ) {
|
||||
final Map.Entry e = (Map.Entry) itr.next();
|
||||
final Map.Entry<K,E> e = itr.next();
|
||||
result[i++] = persister.getIndexType().disassemble( e.getKey(), getSession(), null );
|
||||
result[i++] = persister.getElementType().disassemble( e.getValue(), getSession(), null );
|
||||
}
|
||||
|
@ -324,80 +317,69 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
/**
|
||||
* a wrapper for Map.Entry sets
|
||||
*/
|
||||
class EntrySetProxy implements Set {
|
||||
private final Set set;
|
||||
EntrySetProxy(Set set) {
|
||||
class EntrySetProxy implements Set<Entry<K,E>> {
|
||||
private final Set<Entry<K,E>> set;
|
||||
EntrySetProxy(Set<Entry<K,E>> set) {
|
||||
this.set=set;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean add(Object entry) {
|
||||
public boolean add(Entry<K,E> entry) {
|
||||
//write(); -- doesn't
|
||||
return set.add( entry );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean addAll(Collection entries) {
|
||||
public boolean addAll(Collection<? extends Entry<K,E>> entries) {
|
||||
//write(); -- doesn't
|
||||
return set.addAll( entries );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void clear() {
|
||||
write();
|
||||
set.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean contains(Object entry) {
|
||||
return set.contains( entry );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsAll(Collection entries) {
|
||||
public boolean containsAll(Collection<?> entries) {
|
||||
return set.containsAll( entries );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isEmpty() {
|
||||
return set.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator iterator() {
|
||||
public Iterator<Entry<K,E>> iterator() {
|
||||
return new EntryIteratorProxy( set.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean remove(Object entry) {
|
||||
write();
|
||||
return set.remove( entry );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean removeAll(Collection entries) {
|
||||
public boolean removeAll(Collection<?> entries) {
|
||||
write();
|
||||
return set.removeAll( entries );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean retainAll(Collection entries) {
|
||||
public boolean retainAll(Collection<?> entries) {
|
||||
write();
|
||||
return set.retainAll( entries );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int size() {
|
||||
return set.size();
|
||||
}
|
||||
|
@ -406,89 +388,78 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
// uses iterator() to fill the array
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray() {
|
||||
return set.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray(Object[] array) {
|
||||
public <A> A[] toArray(A[] array) {
|
||||
return set.toArray( array );
|
||||
}
|
||||
}
|
||||
|
||||
final class EntryIteratorProxy implements Iterator {
|
||||
private final Iterator iter;
|
||||
EntryIteratorProxy(Iterator iter) {
|
||||
final class EntryIteratorProxy implements Iterator<Entry<K,E>> {
|
||||
private final Iterator<Entry<K,E>> iter;
|
||||
EntryIteratorProxy(Iterator<Entry<K,E>> iter) {
|
||||
this.iter=iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean hasNext() {
|
||||
return iter.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object next() {
|
||||
return new MapEntryProxy( (Map.Entry) iter.next() );
|
||||
public Entry<K,E> next() {
|
||||
return new MapEntryProxy( iter.next() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void remove() {
|
||||
write();
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
final class MapEntryProxy implements Map.Entry {
|
||||
private final Map.Entry me;
|
||||
MapEntryProxy( Map.Entry me ) {
|
||||
final class MapEntryProxy implements Map.Entry<K,E> {
|
||||
private final Map.Entry<K,E> me;
|
||||
MapEntryProxy(Map.Entry<K,E> me) {
|
||||
this.me = me;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getKey() {
|
||||
public K getKey() {
|
||||
return me.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getValue() {
|
||||
public E getValue() {
|
||||
return me.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "EqualsWhichDoesntCheckParameterClass"})
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object o) {
|
||||
return me.equals( o );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int hashCode() {
|
||||
return me.hashCode();
|
||||
}
|
||||
|
||||
// finally, what it's all about...
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object setValue(Object value) {
|
||||
public E setValue(E value) {
|
||||
write();
|
||||
return me.setValue( value );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final List deletes = new ArrayList();
|
||||
for ( Object o : ((Map) getSnapshot()).entrySet() ) {
|
||||
final Entry e = (Entry) o;
|
||||
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final List<Object> deletes = new ArrayList<>();
|
||||
for ( Entry<?,?> e : ((Map<?,?>) getSnapshot()).entrySet() ) {
|
||||
final Object key = e.getKey();
|
||||
if ( e.getValue() != null && map.get( key ) == null ) {
|
||||
deletes.add( indexIsFormula ? e.getValue() : key );
|
||||
|
@ -498,18 +469,16 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException {
|
||||
final Map sn = (Map) getSnapshot();
|
||||
final Map.Entry e = (Map.Entry) entry;
|
||||
final Map<?,?> sn = (Map<?,?>) getSnapshot();
|
||||
final Map.Entry<?,?> e = (Map.Entry<?,?>) entry;
|
||||
return e.getValue() != null && sn.get( e.getKey() ) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException {
|
||||
final Map sn = (Map) getSnapshot();
|
||||
final Map.Entry e = (Map.Entry) entry;
|
||||
final Map<?,?> sn = (Map<?,?>) getSnapshot();
|
||||
final Map.Entry<?,?> e = (Map.Entry<?,?>) entry;
|
||||
final Object snValue = sn.get( e.getKey() );
|
||||
return e.getValue() != null
|
||||
&& snValue != null
|
||||
|
@ -517,82 +486,76 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getIndex(Object entry, int i, CollectionPersister persister) {
|
||||
return ( (Map.Entry) entry ).getKey();
|
||||
return ( (Map.Entry<?,?>) entry ).getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getElement(Object entry) {
|
||||
return ( (Map.Entry) entry ).getValue();
|
||||
return ( (Map.Entry<?,?>) entry ).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getSnapshotElement(Object entry, int i) {
|
||||
final Map sn = (Map) getSnapshot();
|
||||
return sn.get( ( (Map.Entry) entry ).getKey() );
|
||||
final Map<?,?> sn = (Map<?,?>) getSnapshot();
|
||||
return sn.get( ( (Map.Entry<?,?>) entry ).getKey() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "EqualsWhichDoesntCheckParameterClass"})
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object other) {
|
||||
read();
|
||||
return map.equals( other );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int hashCode() {
|
||||
read();
|
||||
return map.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean entryExists(Object entry, int i) {
|
||||
return ( (Map.Entry) entry ).getValue() != null;
|
||||
return ( (Map.Entry<?,?>) entry ).getValue() != null;
|
||||
}
|
||||
|
||||
final class Clear implements DelayedOperation {
|
||||
final class Clear implements DelayedOperation<E> {
|
||||
@Override
|
||||
public void operate() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAddedInstance() {
|
||||
public E getAddedInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOrphan() {
|
||||
public E getOrphan() {
|
||||
throw new UnsupportedOperationException( "queued clear cannot be used with orphan delete" );
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractMapValueDelayedOperation extends AbstractValueDelayedOperation {
|
||||
private Object index;
|
||||
private final K index;
|
||||
|
||||
protected AbstractMapValueDelayedOperation(Object index, Object addedValue, Object orphan) {
|
||||
protected AbstractMapValueDelayedOperation(K index, E addedValue, E orphan) {
|
||||
super( addedValue, orphan );
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
protected final Object getIndex() {
|
||||
protected final K getIndex() {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
final class Put extends AbstractMapValueDelayedOperation {
|
||||
|
||||
public Put(Object index, Object addedValue, Object orphan) {
|
||||
public Put(K index, E addedValue, E orphan) {
|
||||
super( index, addedValue, orphan );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
map.put( getIndex(), getAddedInstance() );
|
||||
}
|
||||
|
@ -600,12 +563,11 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
|
||||
final class Remove extends AbstractMapValueDelayedOperation {
|
||||
|
||||
public Remove(Object index, Object orphan) {
|
||||
public Remove(K index, E orphan) {
|
||||
super( index, null, orphan );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
map.remove( getIndex() );
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.hibernate.type.Type;
|
|||
* @see java.util.HashSet
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class PersistentSet extends AbstractPersistentCollection implements java.util.Set {
|
||||
protected Set set;
|
||||
public class PersistentSet<E> extends AbstractPersistentCollection<E> implements java.util.Set<E> {
|
||||
protected Set<E> set;
|
||||
|
||||
/**
|
||||
* Empty constructor.
|
||||
|
@ -71,7 +71,7 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
* @param session The session to which this set will belong.
|
||||
* @param set The underlying set data.
|
||||
*/
|
||||
public PersistentSet(SharedSessionContractImplementor session, java.util.Set set) {
|
||||
public PersistentSet(SharedSessionContractImplementor session, java.util.Set<E> set) {
|
||||
super( session );
|
||||
// Sets can be just a view of a part of another collection.
|
||||
// do we need to copy it to be sure it won't be changing
|
||||
|
@ -91,38 +91,37 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
* @deprecated {@link #PersistentSet(SharedSessionContractImplementor, java.util.Set)} should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentSet(SessionImplementor session, java.util.Set set) {
|
||||
public PersistentSet(SessionImplementor session, java.util.Set<E> set) {
|
||||
this( (SharedSessionContractImplementor) session, set );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( {"unchecked"})
|
||||
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final HashMap clonedSet = CollectionHelper.mapOfSize( set.size() );
|
||||
for ( Object aSet : set ) {
|
||||
final Object copied = persister.getElementType().deepCopy( aSet, persister.getFactory() );
|
||||
final HashMap<E,E> clonedSet = CollectionHelper.mapOfSize( set.size() );
|
||||
for ( E aSet : set ) {
|
||||
final E copied = (E) persister.getElementType().deepCopy( aSet, persister.getFactory() );
|
||||
clonedSet.put( copied, copied );
|
||||
}
|
||||
return clonedSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final java.util.Map sn = (java.util.Map) snapshot;
|
||||
public Collection<E> getOrphans(Serializable snapshot, String entityName) throws HibernateException {
|
||||
final java.util.Map<E,E> sn = (java.util.Map<E,E>) snapshot;
|
||||
return getOrphans( sn.keySet(), set, entityName, getSession() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeEmptyCollection(CollectionPersister persister) {
|
||||
assert set == null;
|
||||
set = (Set) persister.getCollectionType().instantiate( 0 );
|
||||
set = (Set<E>) persister.getCollectionType().instantiate( 0 );
|
||||
endRead();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final java.util.Map sn = (java.util.Map) getSnapshot();
|
||||
final java.util.Map<?,?> sn = (java.util.Map<?,?>) getSnapshot();
|
||||
if ( sn.size()!=set.size() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -139,22 +138,21 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
|
||||
@Override
|
||||
public boolean isSnapshotEmpty(Serializable snapshot) {
|
||||
return ( (java.util.Map) snapshot ).isEmpty();
|
||||
return ( (java.util.Map<?,?>) snapshot ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializeFromCache(CollectionPersister persister, Object disassembled, Object owner)
|
||||
throws HibernateException {
|
||||
final Serializable[] array = (Serializable[]) disassembled;
|
||||
final int size = array.length;
|
||||
|
||||
this.set = (Set) persister.getCollectionSemantics().instantiateRaw( size, persister );
|
||||
this.set = (Set<E>) persister.getCollectionSemantics().instantiateRaw( size, persister );
|
||||
|
||||
for ( Serializable arrayElement : array ) {
|
||||
final Object assembledArrayElement = persister.getElementType().assemble( arrayElement, getSession(), owner );
|
||||
if ( assembledArrayElement != null ) {
|
||||
set.add( assembledArrayElement );
|
||||
set.add( (E) assembledArrayElement );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,13 +163,11 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int size() {
|
||||
return readSize() ? getCachedSize() : set.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isEmpty() {
|
||||
return readSize() ? getCachedSize()==0 : set.isEmpty();
|
||||
}
|
||||
|
@ -185,28 +181,25 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator iterator() {
|
||||
public Iterator<E> iterator() {
|
||||
read();
|
||||
return new IteratorProxy( set.iterator() );
|
||||
return new IteratorProxy<>( set.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray() {
|
||||
read();
|
||||
return set.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray(Object[] array) {
|
||||
public <A> A[] toArray(A[] array) {
|
||||
read();
|
||||
return set.toArray( array );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Object value) {
|
||||
public boolean add(E value) {
|
||||
final Boolean exists = isOperationQueueEnabled() ? readElementExistence( value ) : null;
|
||||
if ( exists == null ) {
|
||||
initialize( true );
|
||||
|
@ -243,7 +236,7 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
else if ( exists ) {
|
||||
elementRemoved = true;
|
||||
queueOperation( new SimpleRemove( value ) );
|
||||
queueOperation( new SimpleRemove( (E) value ) );
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -252,15 +245,13 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsAll(Collection coll) {
|
||||
public boolean containsAll(Collection<?> coll) {
|
||||
read();
|
||||
return set.containsAll( coll );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean addAll(Collection coll) {
|
||||
public boolean addAll(Collection<? extends E> coll) {
|
||||
if ( coll.size() > 0 ) {
|
||||
initialize( true );
|
||||
if ( set.addAll( coll ) ) {
|
||||
|
@ -277,8 +268,7 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean retainAll(Collection coll) {
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
initialize( true );
|
||||
if ( set.retainAll( coll ) ) {
|
||||
dirty();
|
||||
|
@ -290,8 +280,7 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean removeAll(Collection coll) {
|
||||
public boolean removeAll(Collection<?> coll) {
|
||||
if ( coll.size() > 0 ) {
|
||||
initialize( true );
|
||||
if ( set.removeAll( coll ) ) {
|
||||
|
@ -330,19 +319,18 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
|
||||
public void injectLoadedState(
|
||||
PluralAttributeMapping attributeMapping,
|
||||
List loadingStateList) {
|
||||
List<?> loadingStateList) {
|
||||
final CollectionPersister collectionDescriptor = attributeMapping.getCollectionDescriptor();
|
||||
if ( loadingStateList != null ) {
|
||||
this.set = (Set) attributeMapping.getCollectionDescriptor().getCollectionSemantics().instantiateRaw(
|
||||
this.set = (Set<E>) attributeMapping.getCollectionDescriptor().getCollectionSemantics().instantiateRaw(
|
||||
loadingStateList.size(),
|
||||
collectionDescriptor
|
||||
);
|
||||
|
||||
//noinspection unchecked
|
||||
this.set.addAll( loadingStateList );
|
||||
this.set.addAll( (List<E>) loadingStateList );
|
||||
}
|
||||
else {
|
||||
this.set = (Set) attributeMapping.getCollectionDescriptor().getCollectionSemantics().instantiateRaw(
|
||||
this.set = (Set<E>) attributeMapping.getCollectionDescriptor().getCollectionSemantics().instantiateRaw(
|
||||
0,
|
||||
collectionDescriptor
|
||||
);
|
||||
|
@ -350,14 +338,14 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterator entries(CollectionPersister persister) {
|
||||
public Iterator<E> entries(CollectionPersister persister) {
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object disassemble(CollectionPersister persister) throws HibernateException {
|
||||
final Object[] result = new Object[ set.size() ];
|
||||
final Iterator itr = set.iterator();
|
||||
final Iterator<E> itr = set.iterator();
|
||||
int i=0;
|
||||
while ( itr.hasNext() ) {
|
||||
result[i++] = persister.getElementType().disassemble( itr.next(), getSession(), null );
|
||||
|
@ -366,13 +354,12 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
public Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
|
||||
final Type elementType = persister.getElementType();
|
||||
final java.util.Map sn = (java.util.Map) getSnapshot();
|
||||
final ArrayList deletes = new ArrayList( sn.size() );
|
||||
final java.util.Map<?,?> sn = (java.util.Map<?,?>) getSnapshot();
|
||||
final ArrayList<Object> deletes = new ArrayList<>( sn.size() );
|
||||
|
||||
Iterator itr = sn.keySet().iterator();
|
||||
Iterator<?> itr = sn.keySet().iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final Object test = itr.next();
|
||||
if ( !set.contains( test ) ) {
|
||||
|
@ -395,96 +382,87 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException {
|
||||
final Object oldValue = ( (java.util.Map) getSnapshot() ).get( entry );
|
||||
final Object oldValue = ( (java.util.Map<?,?>) getSnapshot() ).get( entry );
|
||||
// note that it might be better to iterate the snapshot but this is safe,
|
||||
// assuming the user implements equals() properly, as required by the Set
|
||||
// contract!
|
||||
return ( oldValue == null && entry != null ) || elemType.isDirty( oldValue, entry, getSession() );
|
||||
return oldValue == null && entry != null
|
||||
|| elemType.isDirty( oldValue, entry, getSession() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean needsUpdating(Object entry, int i, Type elemType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isRowUpdatePossible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getIndex(Object entry, int i, CollectionPersister persister) {
|
||||
throw new UnsupportedOperationException("Sets don't have indexes");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getElement(Object entry) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getSnapshotElement(Object entry, int i) {
|
||||
throw new UnsupportedOperationException("Sets don't support updating by element");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "EqualsWhichDoesntCheckParameterClass"})
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object other) {
|
||||
read();
|
||||
return set.equals( other );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int hashCode() {
|
||||
read();
|
||||
return set.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean entryExists(Object key, int i) {
|
||||
return key != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isWrapper(Object collection) {
|
||||
return set==collection;
|
||||
}
|
||||
|
||||
final class Clear implements DelayedOperation {
|
||||
final class Clear implements DelayedOperation<E> {
|
||||
@Override
|
||||
public void operate() {
|
||||
set.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAddedInstance() {
|
||||
public E getAddedInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOrphan() {
|
||||
public E getOrphan() {
|
||||
throw new UnsupportedOperationException("queued clear cannot be used with orphan delete");
|
||||
}
|
||||
}
|
||||
|
||||
final class SimpleAdd extends AbstractValueDelayedOperation {
|
||||
|
||||
public SimpleAdd(Object addedValue) {
|
||||
public SimpleAdd(E addedValue) {
|
||||
super( addedValue, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
set.add( getAddedInstance() );
|
||||
}
|
||||
|
@ -492,12 +470,11 @@ public class PersistentSet extends AbstractPersistentCollection implements java.
|
|||
|
||||
final class SimpleRemove extends AbstractValueDelayedOperation {
|
||||
|
||||
public SimpleRemove(Object orphan) {
|
||||
public SimpleRemove(E orphan) {
|
||||
super( null, orphan );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void operate() {
|
||||
set.remove( getOrphan() );
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ import org.hibernate.persister.collection.BasicCollectionPersister;
|
|||
* @see java.util.TreeMap
|
||||
* @author <a href="mailto:doug.currie@alum.mit.edu">e</a>
|
||||
*/
|
||||
public class PersistentSortedMap extends PersistentMap implements SortedMap {
|
||||
protected Comparator comparator;
|
||||
public class PersistentSortedMap<K,E> extends PersistentMap<K,E> implements SortedMap<K,E> {
|
||||
protected Comparator<? super K> comparator;
|
||||
|
||||
/**
|
||||
* Constructs a PersistentSortedMap. This form needed for SOAP libraries, etc
|
||||
|
@ -63,7 +63,7 @@ public class PersistentSortedMap extends PersistentMap implements SortedMap {
|
|||
* @param session The session
|
||||
* @param map The underlying map data
|
||||
*/
|
||||
public PersistentSortedMap(SharedSessionContractImplementor session, SortedMap map) {
|
||||
public PersistentSortedMap(SharedSessionContractImplementor session, SortedMap<K,E> map) {
|
||||
super( session, map );
|
||||
comparator = map.comparator();
|
||||
}
|
||||
|
@ -76,186 +76,162 @@ public class PersistentSortedMap extends PersistentMap implements SortedMap {
|
|||
* @deprecated {@link #PersistentSortedMap(SharedSessionContractImplementor, SortedMap)} should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentSortedMap(SessionImplementor session, SortedMap map) {
|
||||
public PersistentSortedMap(SessionImplementor session, SortedMap<K,E> map) {
|
||||
this( (SharedSessionContractImplementor) session, map );
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "UnusedParameters"})
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
protected Serializable snapshot(BasicCollectionPersister persister, EntityMode entityMode) throws HibernateException {
|
||||
final TreeMap clonedMap = new TreeMap( comparator );
|
||||
for ( Object o : map.entrySet() ) {
|
||||
final Entry e = (Entry) o;
|
||||
clonedMap.put( e.getKey(), persister.getElementType().deepCopy( e.getValue(), persister.getFactory() ) );
|
||||
final TreeMap<K,E> clonedMap = new TreeMap<>( comparator );
|
||||
for ( Entry<K,E> e : map.entrySet() ) {
|
||||
clonedMap.put( e.getKey(), (E) persister.getElementType().deepCopy( e.getValue(), persister.getFactory() ) );
|
||||
}
|
||||
return clonedMap;
|
||||
}
|
||||
|
||||
public void setComparator(Comparator comparator) {
|
||||
public void setComparator(Comparator<? super K> comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator comparator() {
|
||||
public Comparator<? super K> comparator() {
|
||||
return comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedMap subMap(Object fromKey, Object toKey) {
|
||||
public SortedMap<K,E> subMap(K fromKey, K toKey) {
|
||||
read();
|
||||
final SortedMap subMap = ( (SortedMap) map ).subMap( fromKey, toKey );
|
||||
final SortedMap<K,E> subMap = ( (SortedMap<K,E>) map ).subMap( fromKey, toKey );
|
||||
return new SortedSubMap( subMap );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedMap headMap(Object toKey) {
|
||||
public SortedMap<K,E> headMap(K toKey) {
|
||||
read();
|
||||
final SortedMap headMap = ( (SortedMap) map ).headMap( toKey );
|
||||
final SortedMap<K,E> headMap = ( (SortedMap<K,E>) map ).headMap( toKey );
|
||||
return new SortedSubMap( headMap );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedMap tailMap(Object fromKey) {
|
||||
public SortedMap<K,E> tailMap(K fromKey) {
|
||||
read();
|
||||
final SortedMap tailMap = ( (SortedMap) map ).tailMap( fromKey );
|
||||
final SortedMap<K,E> tailMap = ( (SortedMap<K,E>) map ).tailMap( fromKey );
|
||||
return new SortedSubMap( tailMap );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object firstKey() {
|
||||
public K firstKey() {
|
||||
read();
|
||||
return ( (SortedMap) map ).firstKey();
|
||||
return ( (SortedMap<K,E>) map ).firstKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object lastKey() {
|
||||
public K lastKey() {
|
||||
read();
|
||||
return ( (SortedMap) map ).lastKey();
|
||||
return ( (SortedMap<K,E>) map ).lastKey();
|
||||
}
|
||||
|
||||
class SortedSubMap implements SortedMap {
|
||||
SortedMap subMap;
|
||||
class SortedSubMap implements SortedMap<K,E> {
|
||||
SortedMap<K,E> subMap;
|
||||
|
||||
SortedSubMap(SortedMap subMap) {
|
||||
SortedSubMap(SortedMap<K,E> subMap) {
|
||||
this.subMap = subMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public int size() {
|
||||
return subMap.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isEmpty() {
|
||||
return subMap.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsKey(Object key) {
|
||||
return subMap.containsKey( key );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsValue(Object key) {
|
||||
return subMap.containsValue( key ) ;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object get(Object key) {
|
||||
public E get(Object key) {
|
||||
return subMap.get( key );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object put(Object key, Object value) {
|
||||
public E put(K key, E value) {
|
||||
write();
|
||||
return subMap.put( key, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object remove(Object key) {
|
||||
public E remove(Object key) {
|
||||
write();
|
||||
return subMap.remove( key );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void putAll(Map other) {
|
||||
public void putAll(Map<? extends K,? extends E> other) {
|
||||
write();
|
||||
subMap.putAll( other );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void clear() {
|
||||
write();
|
||||
subMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set keySet() {
|
||||
return new SetProxy( subMap.keySet() );
|
||||
public Set<K> keySet() {
|
||||
return new SetProxy<>( subMap.keySet() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection values() {
|
||||
return new SetProxy( subMap.values() );
|
||||
public Collection<E> values() {
|
||||
return new SetProxy<>( subMap.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Set entrySet() {
|
||||
public Set<Entry<K,E>> entrySet() {
|
||||
return new EntrySetProxy( subMap.entrySet() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Comparator comparator() {
|
||||
public Comparator<? super K> comparator() {
|
||||
return subMap.comparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedMap subMap(Object fromKey, Object toKey) {
|
||||
final SortedMap subMap = this.subMap.subMap( fromKey, toKey );
|
||||
public SortedMap<K,E> subMap(K fromKey, K toKey) {
|
||||
final SortedMap<K,E> subMap = this.subMap.subMap( fromKey, toKey );
|
||||
return new SortedSubMap( subMap );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedMap headMap(Object toKey) {
|
||||
final SortedMap headMap = subMap.headMap( toKey );
|
||||
public SortedMap<K,E> headMap(K toKey) {
|
||||
final SortedMap<K,E> headMap = subMap.headMap( toKey );
|
||||
return new SortedSubMap( headMap );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedMap tailMap(Object fromKey) {
|
||||
final SortedMap tailMap = subMap.tailMap( fromKey );
|
||||
public SortedMap<K,E> tailMap(K fromKey) {
|
||||
final SortedMap<K,E> tailMap = subMap.tailMap( fromKey );
|
||||
return new SortedSubMap( tailMap );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object firstKey() {
|
||||
public K firstKey() {
|
||||
return subMap.firstKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object lastKey() {
|
||||
public K lastKey() {
|
||||
return subMap.lastKey();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.hibernate.persister.collection.BasicCollectionPersister;
|
|||
* @see java.util.TreeSet
|
||||
* @author <a href="mailto:doug.currie@alum.mit.edu">e</a>
|
||||
*/
|
||||
public class PersistentSortedSet extends PersistentSet implements SortedSet {
|
||||
protected Comparator comparator;
|
||||
public class PersistentSortedSet<E> extends PersistentSet<E> implements SortedSet<E> {
|
||||
protected Comparator<? super E> comparator;
|
||||
|
||||
/**
|
||||
* Constructs a PersistentSortedSet. This form needed for SOAP libraries, etc
|
||||
|
@ -60,7 +60,7 @@ public class PersistentSortedSet extends PersistentSet implements SortedSet {
|
|||
* @param session The session
|
||||
* @param set The underlying set data
|
||||
*/
|
||||
public PersistentSortedSet(SharedSessionContractImplementor session, SortedSet set) {
|
||||
public PersistentSortedSet(SharedSessionContractImplementor session, SortedSet<E> set) {
|
||||
super( session, set );
|
||||
comparator = set.comparator();
|
||||
}
|
||||
|
@ -73,110 +73,99 @@ public class PersistentSortedSet extends PersistentSet implements SortedSet {
|
|||
* @deprecated {@link #PersistentSortedSet(SharedSessionContractImplementor, SortedSet)} should be used instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PersistentSortedSet(SessionImplementor session, SortedSet set) {
|
||||
public PersistentSortedSet(SessionImplementor session, SortedSet<E> set) {
|
||||
this( (SharedSessionContractImplementor) session, set );
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "UnusedParameters"})
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
protected Serializable snapshot(BasicCollectionPersister persister, EntityMode entityMode)
|
||||
throws HibernateException {
|
||||
final TreeMap clonedSet = new TreeMap( comparator );
|
||||
for ( Object setElement : set ) {
|
||||
final Object copy = persister.getElementType().deepCopy( setElement, persister.getFactory() );
|
||||
final TreeMap<E,E> clonedSet = new TreeMap<>( comparator );
|
||||
for ( E setElement : set ) {
|
||||
final E copy = (E) persister.getElementType().deepCopy( setElement, persister.getFactory() );
|
||||
clonedSet.put( copy, copy );
|
||||
}
|
||||
return clonedSet;
|
||||
}
|
||||
|
||||
public void setComparator(Comparator comparator) {
|
||||
public void setComparator(Comparator<? super E> comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator comparator() {
|
||||
public Comparator<? super E> comparator() {
|
||||
return comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedSet subSet(Object fromElement, Object toElement) {
|
||||
public SortedSet<E> subSet(E fromElement, E toElement) {
|
||||
read();
|
||||
final SortedSet subSet = ( (SortedSet) set ).subSet( fromElement, toElement );
|
||||
final SortedSet<E> subSet = ( (SortedSet<E>) set ).subSet( fromElement, toElement );
|
||||
return new SubSetProxy( subSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedSet headSet(Object toElement) {
|
||||
public SortedSet<E> headSet(E toElement) {
|
||||
read();
|
||||
final SortedSet headSet = ( (SortedSet) set ).headSet( toElement );
|
||||
final SortedSet<E> headSet = ( (SortedSet<E>) set ).headSet( toElement );
|
||||
return new SubSetProxy( headSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedSet tailSet(Object fromElement) {
|
||||
public SortedSet<E> tailSet(E fromElement) {
|
||||
read();
|
||||
final SortedSet tailSet = ( (SortedSet) set ).tailSet( fromElement );
|
||||
final SortedSet<E> tailSet = ( (SortedSet<E>) set ).tailSet( fromElement );
|
||||
return new SubSetProxy( tailSet );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object first() {
|
||||
public E first() {
|
||||
read();
|
||||
return ( (SortedSet) set ).first();
|
||||
return ( (SortedSet<E>) set ).first();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object last() {
|
||||
public E last() {
|
||||
read();
|
||||
return ( (SortedSet) set ).last();
|
||||
return ( (SortedSet<E>) set ).last();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for subSets to propagate write to its backing set
|
||||
*/
|
||||
class SubSetProxy extends SetProxy implements SortedSet {
|
||||
SubSetProxy(SortedSet s) {
|
||||
class SubSetProxy extends SetProxy<E> implements SortedSet<E> {
|
||||
SubSetProxy(SortedSet<E> s) {
|
||||
super( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Comparator comparator() {
|
||||
return ( (SortedSet) this.set ).comparator();
|
||||
public Comparator<? super E> comparator() {
|
||||
return ( (SortedSet<E>) this.set ).comparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object first() {
|
||||
return ( (SortedSet) this.set ).first();
|
||||
public E first() {
|
||||
return ( (SortedSet<E>) this.set ).first();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedSet headSet(Object toValue) {
|
||||
return new SubSetProxy( ( (SortedSet) this.set ).headSet( toValue ) );
|
||||
public SortedSet<E> headSet(E toValue) {
|
||||
return new SubSetProxy( ( (SortedSet<E>) this.set ).headSet( toValue ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object last() {
|
||||
return ( (SortedSet) this.set ).last();
|
||||
public E last() {
|
||||
return ( (SortedSet<E>) this.set ).last();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedSet subSet(Object fromValue, Object toValue) {
|
||||
return new SubSetProxy( ( (SortedSet) this.set ).subSet( fromValue, toValue ) );
|
||||
public SortedSet<E> subSet(E fromValue, E toValue) {
|
||||
return new SubSetProxy( ( (SortedSet<E>) this.set ).subSet( fromValue, toValue ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public SortedSet tailSet(Object fromValue) {
|
||||
return new SubSetProxy( ( (SortedSet) this.set ).tailSet( fromValue ) );
|
||||
public SortedSet<E> tailSet(E fromValue) {
|
||||
return new SubSetProxy( ( (SortedSet<E>) this.set ).tailSet( fromValue ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.hibernate.type.Type;
|
|||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public interface PersistentCollection {
|
||||
public interface PersistentCollection<E> {
|
||||
/**
|
||||
* Get the owning entity. Note that the owner is only
|
||||
* set during the flush cycle, and when a new collection
|
||||
|
@ -125,7 +125,7 @@ public interface PersistentCollection {
|
|||
*
|
||||
* @return The iterator
|
||||
*/
|
||||
Iterator entries(CollectionPersister persister);
|
||||
Iterator<?> entries(CollectionPersister persister);
|
||||
|
||||
/**
|
||||
* Get the identifier of the given collection entry. This refers to the collection identifier, not the
|
||||
|
@ -260,7 +260,7 @@ public interface PersistentCollection {
|
|||
*
|
||||
* @return An iterator over the elements to delete
|
||||
*/
|
||||
Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula);
|
||||
Iterator<?> getDeletes(CollectionPersister persister, boolean indexIsFormula);
|
||||
|
||||
/**
|
||||
* Is this the wrapper for the given collection instance?
|
||||
|
@ -306,7 +306,7 @@ public interface PersistentCollection {
|
|||
/**
|
||||
* Inject the state loaded for a collection instance.
|
||||
*/
|
||||
void injectLoadedState(PluralAttributeMapping attributeMapping, List loadingState);
|
||||
void injectLoadedState(PluralAttributeMapping attributeMapping, List<?> loadingState);
|
||||
|
||||
/**
|
||||
* Called after reading all rows from the JDBC result set. Pairs with {@link #beginRead}
|
||||
|
@ -342,7 +342,7 @@ public interface PersistentCollection {
|
|||
*
|
||||
* @return The iterator
|
||||
*/
|
||||
Iterator queuedAdditionIterator();
|
||||
Iterator<E> queuedAdditionIterator();
|
||||
|
||||
/**
|
||||
* Get the "queued" orphans
|
||||
|
@ -351,7 +351,7 @@ public interface PersistentCollection {
|
|||
*
|
||||
* @return The orphaned elements
|
||||
*/
|
||||
Collection getQueuedOrphans(String entityName);
|
||||
Collection<E> getQueuedOrphans(String entityName);
|
||||
|
||||
/**
|
||||
* Get the current collection key value
|
||||
|
@ -446,7 +446,7 @@ public interface PersistentCollection {
|
|||
*
|
||||
* @return The orphans
|
||||
*/
|
||||
Collection getOrphans(Serializable snapshot, String entityName);
|
||||
Collection<E> getOrphans(Serializable snapshot, String entityName);
|
||||
|
||||
void initializeEmptyCollection(CollectionPersister persister);
|
||||
|
||||
|
|
|
@ -1541,7 +1541,7 @@ public abstract class AbstractCollectionPersister
|
|||
final Expectation expectation = Expectations.appropriateExpectation( getDeleteCheckStyle() );
|
||||
try {
|
||||
// delete all the deleted entries
|
||||
Iterator deletes = collection.getDeletes( this, !deleteByIndex );
|
||||
Iterator<?> deletes = collection.getDeletes( this, !deleteByIndex );
|
||||
if ( deletes.hasNext() ) {
|
||||
int offset = 1;
|
||||
int count = 0;
|
||||
|
|
Loading…
Reference in New Issue