com.appenginefan.toolkit.persistence
Interface Persistence<T>

All Known Implementing Classes:
DatastorePersistence, LongPersistence, MapBasedPersistence, MarshallingPersistence, ObjectPersistence, ProtocolBufferPersistence, StringPersistence

public interface Persistence<T>

Represents a simple way of persisting a particular object type. For more background, check out this blog post


Method Summary
 T get(String key)
          Gets an entry from the store.
 List<String> keyScan(String start, String end, int max)
          Finds zero or more entries that are within a given range.
 List<String> keyScanReverse(String start, String end, int max)
          Finds zero or more entries that are within a given range, but orders in the opposite direction.
 T mutate(String key, Function<? super T,? extends T> mutator)
          Modifies an entry in the store.
 List<Map.Entry<String,T>> scan(String start, String end, int max)
          Finds zero or more entries that are within a given range
 List<Map.Entry<String,T>> scanReverse(String start, String end, int max)
          Finds zero or more entries that are within a given range, but orders in the opposite direction.
 

Method Detail

mutate

T mutate(String key,
         Function<? super T,? extends T> mutator)
Modifies an entry in the store.

Parameters:
key - the key to modify
mutator - a function that applies a change to the data and stores the new result. If the data does not exist in the store yet, null will be passed in. If the data should be deleted from the store, the function will return null.
Returns:
the data that was stored
Throws:
NullPointerException - if either of the arguments is null
StoreException - if something went wrong while storing data

get

T get(String key)
Gets an entry from the store.

Parameters:
key - the key to look up the data from
Returns:
the data or null, if the store does not contain data
Throws:
NullPointerException - if either of the arguments is null
StoreException - if something went wrong while loading data

scan

List<Map.Entry<String,T>> scan(String start,
                               String end,
                               int max)
Finds zero or more entries that are within a given range

Parameters:
start - a lower bound of the range of keys to look in (inclusive)
end - an upper bound of the range of keys to look in (exclusive)
max - a maximum amount of elements to return. The implementation of the store may choose to return less (for example, if a store can only fetch 10 elements per query, then setting a max of 1000 will still only return 10), but never more.
Returns:
a list of up to max key/value pairs, ordered by key

scanReverse

List<Map.Entry<String,T>> scanReverse(String start,
                                      String end,
                                      int max)
Finds zero or more entries that are within a given range, but orders in the opposite direction. Useful for pagination to jump to the end of a range and get the "last ten" entries

Parameters:
start - a lower bound of the range of keys to look in (inclusive)
end - an upper bound of the range of keys to look in (exclusive)
max - a maximum amount of elements to return. The implementation of the store may choose to return less (for example, if a store can only fetch 10 elements per query, then setting a max of 1000 will still only return 10), but never more.
Returns:
a list of up to max key/value pairs, ordered by key in descending order

keyScan

List<String> keyScan(String start,
                     String end,
                     int max)
Finds zero or more entries that are within a given range. Only returns the keys.

Parameters:
start - a lower bound of the range of keys to look in (inclusive)
end - an upper bound of the range of keys to look in (exclusive)
max - a maximum amount of elements to return. The implementation of the store may choose to return less (for example, if a store can only fetch 10 elements per query, then setting a max of 1000 will still only return 10), but never more.
Returns:
a list of up to max key/value pairs, ordered by key

keyScanReverse

List<String> keyScanReverse(String start,
                            String end,
                            int max)
Finds zero or more entries that are within a given range, but orders in the opposite direction. Only returns the keys.

Parameters:
start - a lower bound of the range of keys to look in (inclusive)
end - an upper bound of the range of keys to look in (exclusive)
max - a maximum amount of elements to return. The implementation of the store may choose to return less (for example, if a store can only fetch 10 elements per query, then setting a max of 1000 will still only return 10), but never more.
Returns:
a list of up to max key/value pairs, ordered by key in descending order