|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.elca.el4j.services.persistence.generic.dao.AbstractIdentityFixer
public abstract class AbstractIdentityFixer
Fixes object identities mangled by loosing ORM context or by remoting.
Given a definition of logical identity and a means to recognize immutable value types, an instance of this class fixes the identities of the objects passing through it while propagating state updates to the logical object's unique representative.
id(Object)
, immutableValue(Object)
and prepareObject(Object)
.
AbstractIdentityFixer.GenericInterceptor
provides a generic Spring AOP
interceptor to be wrapped around the identity-mangling objects. As an
alternative, manual
access to identity translation is granted by merge(Object, Object)
.
IdentityFixerMergePolicy
or by its
default policy -, and notify registered observers about every such update.
These guarantees extend to objects (directly or indirectly) referenced by the
translated object unless they are recognized as immutable values by
immutableValue(Object)
.
needsAdditionalProcessing(Object)
to identify the replaced collections.reverseMerge(java.lang.Object, java.util.IdentityHashMap, boolean)
on every object you pass to the sourcemerge(T, T, boolean, java.util.IdentityHashMap, java.util.List, java.util.IdentityHashMap)
as usual on the objects coming from the source This class needs ReflectPermission
"suppressAccessChecks" if a security manager is present and an object
requiring fixing has non-public fields.
Nested Class Summary | |
---|---|
class |
AbstractIdentityFixer.GenericInterceptor
A generic "around advice" (as defined in AOP terminology) for remote objects. |
Field Summary | |
---|---|
protected static Object |
ANONYMOUS
Id for objects of anonymous types (= value types). |
Constructor Summary | |
---|---|
AbstractIdentityFixer()
Constructs a new IdentityFixer. |
|
AbstractIdentityFixer(DaoChangeNotifier changeNotifier)
Constructor. |
Method Summary | ||
---|---|---|
DaoChangeNotifier |
getChangeNotifier()
Returns the notifier used to announce changes. |
|
Collection<?> |
getRepresentatives()
|
|
protected abstract Object |
id(Object o)
Returns the globally unique, logical id for the provided object, or null , if it has no id (yet), or ANONYMOUS is this
object is of value type. |
|
protected abstract boolean |
immutableValue(Object o)
Returns whether the given reference represents an immutable value, either because it really is a value ( null ) or because the referenced
object's identity is not accessed and its state is not modified. |
|
protected static List<AccessibleObject> |
instanceAccessibleObjects(Class<?> c)
Returns a list of all non-static AccessibleObjects (fields and methods, no constructors) of class c . |
|
protected static List<Field> |
instanceFields(Class<?> c)
Returns a list of all non-static fields of class c . |
|
boolean |
isRepresentative(Object object)
|
|
|
merge(T anchor,
T updated)
Updates the unique representative by duplicating the state in updated . |
|
protected
|
merge(T anchor,
T updated,
boolean isIdentical,
IdentityHashMap<Object,Object> reached,
List<Object> objectsToUpdate,
IdentityHashMap<Object,Object> hintMapping)
Deprecated. |
|
|
merge(T anchor,
T updated,
IdentityFixerMergePolicy policy)
Updates the set of unique representatives according to the IdentityFixerMergePolicy . |
|
protected
|
merge(T anchor,
T updated,
IdentityFixerMergePolicy policy,
boolean isIdentical,
IdentityHashMap<Object,Object> reached,
HashMap<Object,Object> locked)
Actually performs the merge. |
|
protected boolean |
needsAdditionalProcessing(Object o)
|
|
protected abstract Object |
prepareObject(Object o)
Returns the prepared Object, is called before checked for immutability to give the id fixer the chance to convert immutable values to usable ones. |
|
void |
removeRepresentative(Object object)
Remove an object from the representatives. |
|
List<Object> |
reverseMerge(List<Object> objects)
Prepare a list of objects to be passed to an identity-mangling source. |
|
Object |
reverseMerge(Object object,
boolean mergeRecursive)
Prepare an object to be passed to an identity-mangling source. |
|
protected Object |
reverseMerge(Object object,
IdentityHashMap<Object,Object> reached,
boolean mergeRecursive)
Prepare an object to be passed to an identity-mangling source. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final Object ANONYMOUS
Constructor Detail |
---|
public AbstractIdentityFixer()
public AbstractIdentityFixer(DaoChangeNotifier changeNotifier)
changeNotifier
- The notifier for broadcasting changes.Method Detail |
---|
public DaoChangeNotifier getChangeNotifier()
protected static List<Field> instanceFields(Class<?> c)
c
.
c
- The concerned class
protected static List<AccessibleObject> instanceAccessibleObjects(Class<?> c)
c
.
Also searches in superclasses.
c
- the concerned class
@Deprecated protected <T> T merge(T anchor, T updated, boolean isIdentical, IdentityHashMap<Object,Object> reached, List<Object> objectsToUpdate, IdentityHashMap<Object,Object> hintMapping)
anchor
- the (presumed) representative, or nullupdated
- the new version of the objectisIdentical
- whether anchor is known to be transitively identical with
updated.reached
- the set of objects in the updated object graph that have
been (or are being) merged. Used to avoid merging an
object more than once.objectsToUpdate
- A list of anchor objects that should updated, all other objects are not touched. If objectsToUpdate
is null
then all reachable objects get updated.hintMapping
- A map of [updated -> anchor] used to correctly merge collections. If no collections have to be
merged this parameter can be null
.
protected <T> T merge(T anchor, T updated, IdentityFixerMergePolicy policy, boolean isIdentical, IdentityHashMap<Object,Object> reached, HashMap<Object,Object> locked)
anchor
- the (presumed) representative, or nullupdated
- the new version of the objectpolicy
- the policy to use.isIdentical
- whether anchor is known to be transitively identical with
updated.reached
- the set of objects in the updated object graph that have
been (or are being) merged. Used to avoid merging an
object more than once.locked
- the set of id's that are locked for updating unless the new version
is the specified object. This map should be used to prevent updating a representative
multiple times which might result in a update to an old or non fully loaded object.
public <T> T merge(T anchor, T updated)
updated
. If no representative exists so far, one is created.
For every potentially modified entity, DaoChangeNotifier.NewEntityState
notification are sent using the configured change notifier.
anchor
- the representative known to be transitively identical
with updated
, or null, if the representative's
logical identity is already defined.updated
- The object holding the new state.
public <T> T merge(T anchor, T updated, IdentityFixerMergePolicy policy)
IdentityFixerMergePolicy
.
If no representative exists of an object contained by the graph of objects in updated
so far, one is created.
For every potentially modified entity, DaoChangeNotifier.NewEntityState
notification are sent using the configured change notifier.
anchor
- the representative known to be transitively identical
with updated
, or null, if the representative's
logical identity is already defined.updated
- The object holding the new state.policy
- The policy how to merge the representatives.
IdentityFixerMergePolicy
protected Object reverseMerge(Object object, IdentityHashMap<Object,Object> reached, boolean mergeRecursive)
object
- the object to be prepared.reached
- the set of objects that have
been (or are being) reverseMerged. Used to avoid reverseMerging an
object more than once.mergeRecursive
- if the graph of objects should be traversed recursively and prepare all objects.
public Object reverseMerge(Object object, boolean mergeRecursive)
object
- the object to be prepared.mergeRecursive
- if the graph of objects should be traversed recursively and prepare all objects.
public List<Object> reverseMerge(List<Object> objects)
objects
- the list of objects to be prepared.
public boolean isRepresentative(Object object)
object
- the object to test
true
if object is a representative.public Collection<?> getRepresentatives()
public void removeRepresentative(Object object)
object
- the object to removeprotected abstract Object id(Object o)
null
, if it has no id (yet), or ANONYMOUS
is this
object is of value type. o
may be null, point to an ordinary
object or to an array.
The ID objects returned by this method must be value-comparable using
equals
(which implies that hashCode must be overridden as well).
To permit garbage-collection, ids referring to the object they identify
should do so with weak references.
o
- The object for which a globally unique, logical id will be
returned
protected abstract boolean immutableValue(Object o)
null
) or because the referenced
object's identity is not accessed and its state is not modified.
o
may be null, point to an ordinary object or to an array.
o
- The concerned object
True
if the given object represents an immutable
value, false
otherwiseprotected abstract Object prepareObject(Object o)
o
- The concerned object
protected boolean needsAdditionalProcessing(Object o)
o
- The concerned object.
merge(T, T, boolean, java.util.IdentityHashMap, java.util.List, java.util.IdentityHashMap)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |