org.wamblee.persistence
Class AbstractDetachable<T,Ref>

java.lang.Object
  extended by org.wamblee.persistence.AbstractDetachable<T,Ref>
Type Parameters:
T - The type of the object to be attached/detached
Ref - The type of the reference to store when the object is detached.
All Implemented Interfaces:
Serializable, Detachable<T>
Direct Known Subclasses:
JpaDetachable

public abstract class AbstractDetachable<T,Ref>
extends Object
implements Detachable<T>

Detachable implementation that takes care of the basic logic for detachable objects. All that needs to be done is to implement #load().

See Also:
Serialized Form

Constructor Summary
protected AbstractDetachable(T aObject)
          Constructs the detachable.
 
Method Summary
 void detach()
          Detaches the object.
 T get()
          Gets the object, attaching it if needed.
protected abstract  Ref getReference(T aObject)
          Obtains the reference for a given object.
protected abstract  T load(Ref aReference)
          Loads the object based on a reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDetachable

protected AbstractDetachable(T aObject)
Constructs the detachable.

Parameters:
aObject - Object.
Throws:
IllegalArgumentException - When the object passed in is null.
Method Detail

detach

public void detach()
Description copied from interface: Detachable
Detaches the object.

Specified by:
detach in interface Detachable<T>

get

public T get()
Description copied from interface: Detachable
Gets the object, attaching it if needed.

Specified by:
get in interface Detachable<T>
Returns:

load

protected abstract T load(Ref aReference)
Loads the object based on a reference.

Parameters:
aReference - Reference.
Returns:
Object (may be null ).

getReference

protected abstract Ref getReference(T aObject)
Obtains the reference for a given object.

Parameters:
aObject - Object.
Returns:
Reference.


Copyright © 2011. All Rights Reserved.