ch.elca.el4j.services.persistence.hibernate
Class HibernateProxyAwareIdentityFixer

java.lang.Object
  extended by ch.elca.el4j.services.persistence.generic.dao.AbstractIdentityFixer
      extended by ch.elca.el4j.services.persistence.hibernate.HibernateProxyAwareIdentityFixer
Direct Known Subclasses:
HibernatePrimaryKeyObjectIdentityFixer

public class HibernateProxyAwareIdentityFixer
extends AbstractIdentityFixer

An identity fixer for objects loaded by hibernate.

Fully materialized hibernate-persisted objects (hereafter called representatives) bear the logical identity corresponding to their identity in the database; the identity fixer therefore ensures that all requests passing through this proxy yielding a representative for a given persisted object always yield the same representative.

This class considers all non-collection, non-entity types to be immutable value types. Note that lazy loading proxies are not guaranteed a unique identity by this class. This is not possible, as they are not guaranteed the proper dynamic type by hibernate.

This class assumes that entities are annotated with Entity, and hibernate identities are stored in exactly one property annotated with Id. Moreover, identity objects are required to override equals and hashcode to provide a value comparison and must not be identical to the object they identify.

This class needs ReflectPermission "suppressAccessChecks" if a security manager is present and an object requiring fixing keeps its id in a non-public field.

Author:
Adrian Moos (AMS)
File-location:
HibernateProxyAwareIdentityFixer
Last check-in date:
2009-08-04 14:35:53 +0200 (Di, 04. Aug 2009) by swismer for revision 3875

Nested Class Summary
 
Nested classes/interfaces inherited from class ch.elca.el4j.services.persistence.generic.dao.AbstractIdentityFixer
AbstractIdentityFixer.GenericInterceptor
 
Field Summary
 
Fields inherited from class ch.elca.el4j.services.persistence.generic.dao.AbstractIdentityFixer
ANONYMOUS
 
Constructor Summary
HibernateProxyAwareIdentityFixer()
           
 
Method Summary
protected  Object id(Object o)
          Returns the globally unique, logical id for the provided object, or null, if it has no id (yet), or AbstractIdentityFixer.ANONYMOUS is this object is of value type.
protected  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  boolean needsAdditionalProcessing(Object o)
          
protected  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.
 
Methods inherited from class ch.elca.el4j.services.persistence.generic.dao.AbstractIdentityFixer
getChangeNotifier, getRepresentatives, instanceAccessibleObjects, instanceFields, isRepresentative, merge, merge, merge, merge, removeRepresentative, reverseMerge, reverseMerge, reverseMerge
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateProxyAwareIdentityFixer

public HibernateProxyAwareIdentityFixer()
Method Detail

id

protected Object id(Object o)
Returns the globally unique, logical id for the provided object, or null, if it has no id (yet), or AbstractIdentityFixer.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.

Specified by:
id in class AbstractIdentityFixer
Parameters:
o - The object for which a globally unique, logical id will be returned
Returns:
A globally unique, logical ID object for the given object

immutableValue

protected 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. o may be null, point to an ordinary object or to an array.

Specified by:
immutableValue in class AbstractIdentityFixer
Parameters:
o - The concerned object
Returns:
True if the given object represents an immutable value, false otherwise

prepareObject

protected 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.

Specified by:
prepareObject in class AbstractIdentityFixer
Parameters:
o - The concerned object
Returns:
The prepared object.

needsAdditionalProcessing

protected boolean needsAdditionalProcessing(Object o)

Overrides:
needsAdditionalProcessing in class AbstractIdentityFixer
Parameters:
o - The concerned object.
Returns:
if the object needs additional processing during a AbstractIdentityFixer.merge(T, T, boolean, java.util.IdentityHashMap, java.util.List, java.util.IdentityHashMap).


Copyright © 2005-2011 ELCA. All Rights Reserved.