|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tapestry.util.DefaultPrimaryKeyConverter
public class DefaultPrimaryKeyConverter
Companion to the For component
, this class is an
implementation of IPrimaryKeyConverter
that performs some
additional handling, such as tracking value sets..
Value sets are sets of value objects maintained by the converter; the converter will provide a
synthetic read/write boolean property that indicates if the last value
is
or is not in the set.
A single built-in value set, isDeleted()
has a special purpose; it controls whether or
not values are returned from getValues()
. Subclasses may add additional synthetic
boolean properties and additional sets.
Why not just store a boolean property in the object itself? Well, deleted is a good example of a property that is meaningful in the context of an operation, but isn't stored ... once an object is deleted (from secondary storage, such as a database) there's no place to store such a flag. The DefaultPrimaryKey converter is used in this context to store transient, operation data ... such as which values are to be deleted.
This class can be thought of as a successor to ListEditMap
.
Constructor Summary | |
---|---|
DefaultPrimaryKeyConverter()
|
Method Summary | |
---|---|
void |
add(Object key,
Object value)
|
protected boolean |
checkValueSetForLastValue(Set valueSet)
Checks the set to see if it contains the last value . |
void |
clear()
Clears all properties of the converter, returning it to a pristine state. |
protected Set |
createUnmodifiableSet(Set valueSet)
Converts a value set into a returnable value; null is converted to the empty set, and non-null is wrapped as unmodifiable. |
List |
getAllValues()
Returns a unmodifiable list of values stored into the converter, in the order in which they were stored. |
Set |
getDeletedValues()
Returns an unmodifiable set of all values marked as deleted. |
Object |
getLastValue()
Returns the last active value; this is the value passed to getPrimaryKey(Object) or
the value for the key passed to getValue(Object) . |
Object |
getPrimaryKey(Object value)
Gets the primary key of an object previously stored in this converter. |
Object |
getValue(Object primaryKey)
Given a primary key, locates the corresponding object. |
List |
getValues()
Returns a list of all values stored into the converter, with deleted values removed. |
boolean |
isDeleted()
Checks to see if the last value is, or is not, in the set of deleted
values. |
protected Object |
provideMissingValue(Object key)
Invoked by getValue(Object) when the key is not found in the converter's map. |
void |
removeDeletedValues()
Iterates over the keys and values, removing any values (and corresponding keys) that that are in the deleted set. |
void |
setDeleted(boolean deleted)
Adds or removes the last value from the
deleted values set . |
protected Set |
updateValueSetForLastValue(Set set,
boolean inSet)
Updates a value set to add or remove the last value to the set. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultPrimaryKeyConverter()
Method Detail |
---|
public void clear()
public final void add(Object key, Object value)
public final List getAllValues()
add(Object, Object)
public final List getValues()
public final boolean isDeleted()
last value
is, or is not, in the set of deleted
values.
protected final boolean checkValueSetForLastValue(Set valueSet)
last value
.
valueSet
- the set to check, which may be null
public final void setDeleted(boolean deleted)
last value
from the
deleted values set
.
deleted
- protected final Set updateValueSetForLastValue(Set set, boolean inSet)
last value
to the set. The
logic here will create and return a new Set instance if necessary (that is, if inSet is true
and set is null). The point is to defer the creation of the set until its actually needed.
set
- the set to update, which may be nullinSet
- if true, the last value will be added to the set (creating the set as necessary);
if false, the last value will be removed
public final Object getLastValue()
getPrimaryKey(Object)
or
the value for the key passed to getValue(Object)
.
Maintaining value sets involves adding or removing the active value from a set.
public final Set getDeletedValues()
protected final Set createUnmodifiableSet(Set valueSet)
valueSet
- the set to convert and return
public final void removeDeletedValues()
getAllValues()
will be the same as
getValues()
.
public final Object getPrimaryKey(Object value)
getPrimaryKey
in interface IPrimaryKeyConverter
value
- an object previously stored in the converter
org.apache.hivemind.ApplicationRuntimeException
- if the value was not previously storedadd(Object, Object)
public final Object getValue(Object primaryKey)
provideMissingValue(Object)
if no such key has been stored into the converter.
getValue
in interface IPrimaryKeyConverter
add(Object, Object)
protected Object provideMissingValue(Object key)
getValue(Object)
when the key is not found in the converter's map.
Subclasses may override this method to either obtain the corresponding object from secondary
storage, to throw an exception, or to provide a new object instance. This implementation
returns null.
key
- the key for which an object was requested
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |