@Override public PersistentCollection instantiate(SharedSessionContractImplementor session, CollectionPersister persister, Serializable key) { return new PersistentList( session ); }
@Override public boolean needsUpdating(Object entry, int i, Type elemType) throws HibernateException { final List sn = (List) getSnapshot(); return i < sn.size() && sn.get( i ) != null && list.get( i ) != null && elemType.isDirty( list.get( i ), sn.get( i ), getSession() ); }
@Override @SuppressWarnings("unchecked") public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { final Serializable[] array = (Serializable[]) disassembled; final int size = array.length; beforeInitialize( persister, size ); for ( Serializable arrayElement : array ) { list.add( persister.getElementType().assemble( arrayElement, getSession(), owner ) ); } }
@Override public Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException { final List sn = (List) snapshot; return getOrphans( sn, list, entityName, getSession() ); }
@Override @SuppressWarnings("unchecked") public boolean retainAll(Collection coll) { initialize( true ); if ( list.retainAll( coll ) ) { dirty(); return true; } else { return false; } }
@Override public int size() { return readSize() ? getCachedSize() : list.size(); }
@Override public boolean remove(Object value) { final Boolean exists = isPutQueueEnabled() ? readElementExistence( value ) : null; if ( exists == null ) { initialize( true ); if ( list.remove( value ) ) { elementRemoved = true; dirty(); return true; } else { return false; } } else if ( exists ) { elementRemoved = true; queueOperation( new SimpleRemove( value ) ); return true; } else { return false; } }
@Override @SuppressWarnings("unchecked") public boolean add(Object object) { if ( !isOperationQueueEnabled() ) { write(); return list.add( object ); } else { queueOperation( new SimpleAdd( object ) ); return true; } }
@Override @SuppressWarnings("unchecked") public void clear() { if ( isClearQueueEnabled() ) { queueOperation( new Clear() ); } else { initialize( true ); if ( ! list.isEmpty() ) { list.clear(); dirty(); } } }
@Override @SuppressWarnings("unchecked") public Object remove(int index) { if ( index < 0 ) { throw new ArrayIndexOutOfBoundsException( "negative index" ); } final Object old = isPutQueueEnabled() ? readElementByIndex( index ) : UNKNOWN; elementRemoved = true; if ( old == UNKNOWN ) { write(); dirty(); return list.remove( index ); } else { queueOperation( new Remove( index, old ) ); return old; } }
@Override public boolean needsUpdating(Object entry, int i) throws HibernateException { final List sn = (List) getSnapshot(); return i < sn.size() && sn.get( i ) != null && list.get( i ) != null && getCollectionDescriptor().isDirty( list.get( i ), sn.get( i ), getSession() ); }
@Override public Object getSnapshotElement(Object entry, int i) { final List sn = (List) getSnapshot(); return sn.get( i ); }
@Override @SuppressWarnings("unchecked") public Serializable disassemble(CollectionPersister persister) throws HibernateException { final int length = list.size(); final Serializable[] result = new Serializable[length]; for ( int i=0; i<length; i++ ) { result[i] = persister.getElementType().disassemble( list.get( i ), getSession(), null ); } return result; }
return persistentSet; } else if (detachedCollection instanceof List) { PersistentList persistentList = new PersistentList(null, (List<?>) detachedCollection); changeCollectionOwner(persistentList, owner); ArrayList<Object> snapshot = new ArrayList<>(); if (varSnapshotCollection == null) { persistentList.clearDirty(); varSnapshotCollection = detachedCollection; snapshot.add(snapshotCollectionElement); persistentList.setSnapshot(owner.getId(), collectionRoleName, snapshot); return persistentList;
@Override @SuppressWarnings("unchecked") public void initializeFromCache( Serializable disassembled, Object owner, PersistentCollectionDescriptor<?,?,E> collectionDescriptor) throws HibernateException { final Serializable[] array = (Serializable[]) disassembled; final int size = array.length; beforeInitialize( size, collectionDescriptor ); for ( Serializable arrayElement : array ) { list.add( getCollectionDescriptor().getElementDescriptor().getJavaTypeDescriptor().getMutabilityPlan().assemble( arrayElement ) ); } }
@Override public boolean remove(Object value) { final Boolean exists = isPutQueueEnabled() ? readElementExistence( value ) : null; if ( exists == null ) { initialize( true ); if ( list.remove( value ) ) { elementRemoved = true; dirty(); return true; } else { return false; } } else if ( exists ) { elementRemoved = true; queueOperation( new SimpleRemove( value ) ); return true; } else { return false; } }
@Override @SuppressWarnings("unchecked") public boolean addAll(Collection values) { if ( values.size()==0 ) { return false; } if ( !isOperationQueueEnabled() ) { write(); return list.addAll( values ); } else { for ( Object value : values ) { queueOperation( new SimpleAdd( value ) ); } return values.size()>0; } }
/** * @see java.util.List#clear() */ public void clear() { if ( isClearQueueEnabled() ) { queueOperation( new Clear() ); } else { initialize( true ); if ( ! list.isEmpty() ) { list.clear(); dirty(); } } }
@Override @SuppressWarnings("unchecked") public E remove(int index) { if ( index < 0 ) { throw new ArrayIndexOutOfBoundsException( "negative index" ); } final Object old = isPutQueueEnabled() ? readElementByIndex( index ) : UNKNOWN; elementRemoved = true; if ( old == UNKNOWN ) { write(); dirty(); return list.remove( index ); } else { queueOperation( new Remove( index, old ) ); return (E) old; } }
@Override @SuppressWarnings("unchecked") public boolean removeAll(Collection coll) { if ( coll.size()>0 ) { initialize( true ); if ( list.removeAll( coll ) ) { elementRemoved = true; dirty(); return true; } else { return false; } } else { return false; } }