Should preserveSnapshot handle more Map types than just TreeMap + HashMap? Should more List types also be handled than ArrayList?
private void preserveSnapshot(PersistentCollection original, PersistentCollection result, AssociationType elemType, Object owner, Map copyCache, SessionImplementor session) { Serializable originalSnapshot = original.getStoredSnapshot(); Serializable resultSnapshot = result.getStoredSnapshot(); Serializable targetSnapshot; if ( originalSnapshot instanceof List ) { targetSnapshot = new ArrayList( ( (List) originalSnapshot ).size() ); for ( Object obj : (List) originalSnapshot ) { ( (List) targetSnapshot ).add( elemType.replace( obj, null, session, owner, copyCache ) ); } } else if ( originalSnapshot instanceof Map ) { if ( originalSnapshot instanceof SortedMap ) { targetSnapshot = new TreeMap( ( (SortedMap) originalSnapshot ).comparator() ); } else { targetSnapshot = new HashMap( CollectionHelper.determineProperSizing( ( (Map) originalSnapshot ).size() ), CollectionHelper.LOAD_FACTOR ); } for ( Map.Entry<Object, Object> entry : ( (Map<Object, Object>) originalSnapshot ).entrySet() ) { Object key = entry.getKey(); Object value = entry.getValue(); Object resultSnapshotValue = ( resultSnapshot == null ) ? null : ( (Map<Object, Object>) resultSnapshot ).get( key ); if ( key == value ) { Object newValue = elemType.replace( value, resultSnapshotValue, session, owner, copyCache ); ( (Map) targetSnapshot ).put( newValue, newValue ); } else { Object newValue = elemType.replace( value, resultSnapshotValue, session, owner, copyCache ); ( (Map) targetSnapshot ).put( key, newValue ); } } } else if ( originalSnapshot instanceof Object[] ) { Object[] arr = (Object[]) originalSnapshot; for ( int i = 0; i < arr.length; i++ ) { arr[i] = elemType.replace( arr[i], null, session, owner, copyCache ); } targetSnapshot = originalSnapshot; } else { // retain the same snapshot targetSnapshot = resultSnapshot; } CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( result ); if ( ce != null ) { ce.resetStoredSnapshot( result, targetSnapshot ); } }
Should preserveSnapshot handle more Map types than just TreeMap + HashMap? Should more List types also be handled than ArrayList?