Class ReferenceResolver
- java.lang.Object
-
- org.eclipse.persistence.internal.oxm.ReferenceResolver
-
public final class ReferenceResolver extends Object
This class is leveraged by reference mappings. It plays 3 roles:- Stores objects with an ID
- Stores key based relationships
- Resolves key based relationships based on the objects stored by ID
-
-
Constructor Summary
Constructors Constructor Description ReferenceResolver()
The default constructor initializes the list of References.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addReference(Reference ref)
Add a Reference object to the list - these References will be resolved after unmarshalling is complete.Reference
getReference(ObjectReferenceMapping mapping, Object sourceObject)
Retrieve the reference for a given mapping instance.Reference
getReference(ObjectReferenceMapping mapping, Object sourceObject, Field xmlField)
Return a reference for the given mapping and source object, that doesn't already contain an entry for the provided field.void
putValue(Class clazz, Object key, Object object)
Store an instance by key based on a mapped class.void
resolveReferences(CoreAbstractSession session, IDResolver userSpecifiedResolver, ErrorHandler handler)
INTERNAL: Iterates through all references.
-
-
-
Method Detail
-
addReference
public void addReference(Reference ref)
Add a Reference object to the list - these References will be resolved after unmarshalling is complete.############################# # Strategy - Hash Collision # ############################# Suppose that hashing function is h(k) = k % 9; __________Input 9 entries_________________________ Key k | 0, 8, 7, 5, 5, 5, 1, 14, 3 | Position# p | 0, 1, 2, 3, 4, 5, 6, 7, 8 | Value = p * 3 | 0, 3, 6, 9, 12, 15, 18, 21, 24 | -------------------------------------------------- e.g. eighth entry is Entry#7{ key = 14, value = 21 } #################################### # Insert element - O(1) guaranteed # #################################### Processing the 9th key: 1. Attempt to insert Entry#7 with key '14' into map of references. > h(14) = 5; HashMap buckets: position | 0 1 2 3 4 5 6 7 8 entry(key) | 0 1 3 5 7 8 ^ > Bucket 5 is taken. 2. Store the entry in a separate list. List for unlucky references: position | 0 1 2 entry(key) | 5 5 ^ position | 0 1 2 entry(key) | 5 5 14 ^ 3. Store the position # p of this element, i.e. what spot it would have taken if all entries were stored in a position list, counting from zero. List storing position # of unlucky references: position | 0 1 2 entry # (p) | 4 5 ^ position | 0 1 2 entry # (p) | 4 5 7 ^ ##################################################### # Retrieve element - O(1) expected, O(n) worst case # ##################################################### Retrieve entry with key '14' 1. Attempt to retrieve it from map > h(14) = 5; HashMap buckets: position | 0 1 2 3 4 5 6 7 8 entry(key) | 0 1 3 5 7 8 ^ Hash function points to bucket # 5. Stored key is 5. > key 5 != 14. 2. Iterate through list of unluckyReferences, comparing key to all keys in the list. position | 0 1 2 entry(key) | 5 5 14 ^ > key 5 != 14 position | 0 1 2 entry(key) | 5 5 14 ^ > key 5 != 14 position | 0 1 2 entry(key) | 5 5 14 ^ > key 14 = 14, retrieve entry. ################################################## # Iterate through all elements - O(n) guaranteed # ################################################## 1. Create boolean array of size n that keeps track of unlucky positions: > boolean[] a = new boolean[lastPosition + 1]; 2. Set a[p] = true for elements that did not fit into hash map, p = position # of element. > for (Integer p : unluckyRefPositions) { > a[p] = true; > } 3. Iterate through LinkedMap and List as if they were one joined collection of size s = map.size() + list.size(), ordered by p = position # of element: > for (p = 0; p < s; p ++) { > if a[p] = false, take next element from linked map iterator, > if a[p] = true, take next element from list iterator, > }
-
getReference
public Reference getReference(ObjectReferenceMapping mapping, Object sourceObject)
Retrieve the reference for a given mapping instance. If more keys match, returns the first occurrence.
-
getReference
public Reference getReference(ObjectReferenceMapping mapping, Object sourceObject, Field xmlField)
Return a reference for the given mapping and source object, that doesn't already contain an entry for the provided field.
-
putValue
public void putValue(Class clazz, Object key, Object object)
Store an instance by key based on a mapped class. These values will be used when it comes time to resolve the references.- Since:
- EclipseLink 2.5.0
-
resolveReferences
public void resolveReferences(CoreAbstractSession session, IDResolver userSpecifiedResolver, ErrorHandler handler)
INTERNAL: Iterates through all references. Resolves them. Resets containers.- Parameters:
session
- typically will be a unit of workuserSpecifiedResolver
- a user-provided subclass of IDResolver, may be null
-
-