org.apache.tapestry5.util
Class DefaultPrimaryKeyEncoder<K extends java.io.Serializable,V>

java.lang.Object
  extended by org.apache.tapestry5.util.DefaultPrimaryKeyEncoder<K,V>
Type Parameters:
K - the key type (which must be serializable)
V - the value type
All Implemented Interfaces:
PrimaryKeyEncoder<K,V>

Deprecated. See deprecation notes for PrimaryKeyEncoder.

public class DefaultPrimaryKeyEncoder<K extends java.io.Serializable,V>
extends java.lang.Object
implements PrimaryKeyEncoder<K,V>

A default, extensible version of PrimaryKeyEncoder that is based on loading known values into an internal map. When there's a reasonable number (hundreds, perhaps thousands) of items to choose from, and those items are fast and cheap to read and instantiate, this implementation is a good bet. For very large result sets, you'll need to create your own implementation of PrimaryKeyEncoder.


Constructor Summary
DefaultPrimaryKeyEncoder()
          Deprecated. Compatibility with 5.0: new encoder, key type unknown.
DefaultPrimaryKeyEncoder(java.lang.Class<K> keyType)
          Deprecated.  
 
Method Summary
 void add(K key, V value)
          Deprecated. Adds a new key/value pair to the encoder.
 java.util.List<V> getAllValues()
          Deprecated.  
 java.lang.Class<K> getKeyType()
          Deprecated. Returns the type of key.
 java.util.List<V> getValues()
          Deprecated. Returns the values previously added to the encoder, in the order in which they were added.
protected  boolean inKeySet(java.util.Set<K> keySet)
          Deprecated. Returns true if the current key is in the provided set.
 boolean isDeleted()
          Deprecated.  
protected  java.util.Set<K> modifyKeySet(java.util.Set<K> keySet, boolean value)
          Deprecated. Modifies a keySet to add or remove the current key.
 void prepareForKeys(java.util.List<K> keys)
          Deprecated. Does nothing.
protected  V provideMissingObject(K key)
          Deprecated. Invoked by toValue(Serializable) whenever a key can not be converted to a value using the internal cache.
 void setDeleted(boolean value)
          Deprecated.  
 K toKey(V value)
          Deprecated. For a previously added key/value pair, returns the key corresponding to the given value.
 V toValue(K key)
          Deprecated. For a particular primary key, previously obtained via PrimaryKeyEncoder.toKey(Object), this method returns the same or equivalent object.
protected  java.util.List<V> valuesNotInKeySet(java.util.Set<K> keySet)
          Deprecated. Returns a list of all the values except those values whose keys are in the provided set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPrimaryKeyEncoder

public DefaultPrimaryKeyEncoder()
Deprecated. 
Compatibility with 5.0: new encoder, key type unknown. You will want to use the other constructor and specify the key type.


DefaultPrimaryKeyEncoder

public DefaultPrimaryKeyEncoder(java.lang.Class<K> keyType)
Deprecated. 
Since:
5.1.0.0
Method Detail

getKeyType

public java.lang.Class<K> getKeyType()
Deprecated. 
Description copied from interface: PrimaryKeyEncoder
Returns the type of key. This is primarily used when Tapestry must convert an existing PrimaryKeyConverter into a ValueEncoder.

Specified by:
getKeyType in interface PrimaryKeyEncoder<K extends java.io.Serializable,V>
Returns:
key type or null if not known

add

public final void add(K key,
                      V value)
Deprecated. 
Adds a new key/value pair to the encoder.


getValues

public final java.util.List<V> getValues()
Deprecated. 
Returns the values previously added to the encoder, in the order in which they were added. Values that are deleted are not returned.

Returns:
ordered list of values

valuesNotInKeySet

protected final java.util.List<V> valuesNotInKeySet(java.util.Set<K> keySet)
Deprecated. 
Returns a list of all the values except those values whose keys are in the provided set. The set may be null, in which case all values are returned.

Parameters:
keySet - set of keys identifying values to exclude, or null to exclude no values
Returns:
values (not in the set) in order origionally added

getAllValues

public final java.util.List<V> getAllValues()
Deprecated. 

toKey

public final K toKey(V value)
Deprecated. 
For a previously added key/value pair, returns the key corresponding to the given value.

Specified by:
toKey in interface PrimaryKeyEncoder<K extends java.io.Serializable,V>
Parameters:
value - whose primary key is needed
Returns:
the key for the value

toValue

public final V toValue(K key)
Deprecated. 
Description copied from interface: PrimaryKeyEncoder
For a particular primary key, previously obtained via PrimaryKeyEncoder.toKey(Object), this method returns the same or equivalent object.

Specified by:
toValue in interface PrimaryKeyEncoder<K extends java.io.Serializable,V>
Parameters:
key - used to identify the object
Returns:
the value object for the key

provideMissingObject

protected V provideMissingObject(K key)
Deprecated. 
Invoked by toValue(Serializable) whenever a key can not be converted to a value using the internal cache. This is an opportunity to record the fact that an error occured (they key was not valuable, possibly because it points to a deleted entity object) and provide a temporary object. This method may return null, but in a typical application, that will likely case NullPointerExceptions further down the processing chain.

This implementation returns null, and is intended to be overriden in subclasses.

Parameters:
key - key for which a value is required
Returns:
a substitute value, or null

isDeleted

public final boolean isDeleted()
Deprecated. 

setDeleted

public final void setDeleted(boolean value)
Deprecated. 

inKeySet

protected final boolean inKeySet(java.util.Set<K> keySet)
Deprecated. 
Returns true if the current key is in the provided set.

Parameters:
keySet - the set of keys to check, or null
Returns:
true if the key is in the set, false if it is missing (or if keySet is null)

modifyKeySet

protected final java.util.Set<K> modifyKeySet(java.util.Set<K> keySet,
                                              boolean value)
Deprecated. 
Modifies a keySet to add or remove the current key. If necessary, a new Set is created.

Useage: private Set myFlagKeys;

public boolean void setMyFlag(boolean value) { myFlagKeys = modifySet(myFlagKeys, value); }

Parameters:
keySet - the set of keys, or null
value - true to add the current key, false to remove
Returns:
the provided key set, or a new one

prepareForKeys

public void prepareForKeys(java.util.List<K> keys)
Deprecated. 
Does nothing. Subclasses may override as necessary.

Specified by:
prepareForKeys in interface PrimaryKeyEncoder<K extends java.io.Serializable,V>


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.