org.apache.commons.betwixt.strategy
Class IdStoringStrategy

java.lang.Object
  extended by org.apache.commons.betwixt.strategy.IdStoringStrategy
Direct Known Subclasses:
DefaultIdStoringStrategy

public abstract class IdStoringStrategy
extends java.lang.Object

Pluggable strategy for id storage management. It is possible to use this strategy for innovative active storage storage strategies as well as passive ones. For example, it is possible to have some beans map to references without ever being fully mapped.

Since:
0.7
Author:
Christian Aust

Field Summary
static IdStoringStrategy DEFAULT
          Deprecated. do not use this singleton since it creates a static Map of all objects ever written. Use createDefault() instead
 
Constructor Summary
IdStoringStrategy()
           
 
Method Summary
static IdStoringStrategy createDefault()
          Factory method creates the default Betwixt implementation.
abstract  java.lang.Object getReferenced(Context context, java.lang.String id)
          Gets an object matching the given reference.
abstract  java.lang.String getReferenceFor(Context context, java.lang.Object bean)
          Retrieves a reference for the given instance.
abstract  void reset()
          Reset to the initial state.
abstract  void setReference(Context context, java.lang.Object bean, java.lang.String id)
          Stores an instance reference for later retrieval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static IdStoringStrategy DEFAULT
Deprecated. do not use this singleton since it creates a static Map of all objects ever written. Use createDefault() instead
Default storage strategy

Constructor Detail

IdStoringStrategy

public IdStoringStrategy()
Method Detail

createDefault

public static IdStoringStrategy createDefault()
Factory method creates the default Betwixt implementation. The implementation created may vary if the default implementation changes.

Returns:
IdStoringStrategy used as default
Since:
0.8

getReferenceFor

public abstract java.lang.String getReferenceFor(Context context,
                                                 java.lang.Object bean)
Retrieves a reference for the given instance. If a not null value is returned from this method, then the bean content will not be written. Use IDGenerator strategy to vary the values written for a bean.

Parameters:
context - current context, not null
bean - the instance, not null
Returns:
id as String when this bean has already been reference, or null to indicate that this bean is not yet reference

setReference

public abstract void setReference(Context context,
                                  java.lang.Object bean,
                                  java.lang.String id)
Stores an instance reference for later retrieval. This method is shared by writing and reading.

Parameters:
context - current context, not null
bean - the instance, not null
id - the id to use

getReferenced

public abstract java.lang.Object getReferenced(Context context,
                                               java.lang.String id)
Gets an object matching the given reference.

Parameters:
context - Context, not null
id - the reference id
Returns:
an bean matching the given reference, or null if there is no bean matching the given reference

reset

public abstract void reset()
Reset to the initial state.



Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.