HHH-6361 formatting

This commit is contained in:
brmeyer 2012-10-29 17:51:02 -04:00
parent 7bb43baf0b
commit f9049a1fd2
1 changed files with 65 additions and 46 deletions

View File

@ -518,8 +518,11 @@ public abstract class CollectionType extends AbstractType implements Association
( ( PersistentCollection ) result ).clearDirty(); ( ( PersistentCollection ) result ).clearDirty();
} }
if (elemType instanceof AssociationType) { if ( elemType instanceof AssociationType ) {
preserveSnapshot(( PersistentCollection )original, ( PersistentCollection ) result, (AssociationType) elemType, owner, copyCache, session); preserveSnapshot( (PersistentCollection) original,
(PersistentCollection) result,
(AssociationType) elemType, owner, copyCache,
session );
} }
} }
} }
@ -527,61 +530,77 @@ public abstract class CollectionType extends AbstractType implements Association
return result; return result;
} }
private void preserveSnapshot(PersistentCollection original ,PersistentCollection result, AssociationType elemType, Object owner, private void preserveSnapshot(PersistentCollection original,
Map copyCache, SessionImplementor session) { PersistentCollection result, AssociationType elemType,
Object owner, Map copyCache, SessionImplementor session) {
Serializable originalSnapshot = original.getStoredSnapshot(); Serializable originalSnapshot = original.getStoredSnapshot();
Serializable resultSnapshot = result.getStoredSnapshot(); Serializable resultSnapshot = result.getStoredSnapshot();
Serializable targetSnapshot; Serializable targetSnapshot;
if (originalSnapshot instanceof List) { if ( originalSnapshot instanceof List ) {
targetSnapshot = new ArrayList(((List) originalSnapshot).size()); targetSnapshot = new ArrayList(
for (Object obj : (List) originalSnapshot) { ( (List) originalSnapshot ).size() );
((List) targetSnapshot).add(elemType.replace(obj, null, session, owner, copyCache)); 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; else if ( originalSnapshot instanceof Map ) {
for (int i=0; i< arr.length; i++) { if ( originalSnapshot instanceof SortedMap ) {
arr[i] = elemType.replace(arr[i], null, session, owner, copyCache ); 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; targetSnapshot = originalSnapshot;
} else { }
else {
// retain the same snapshot // retain the same snapshot
targetSnapshot = resultSnapshot; targetSnapshot = resultSnapshot;
} }
CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(result); CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(
if (ce != null) { result );
ce.resetStoredSnapshot(result, targetSnapshot); if ( ce != null ) {
ce.resetStoredSnapshot( result, targetSnapshot );
} }
} }
/** /**