public interface Storage<S extends Storable>
Storable
from a Repository
.
Storage instances are mutable, but they are thread-safe.
Modifier and Type | Method and Description |
---|---|
boolean |
addTrigger(Trigger<? super S> trigger)
Register a trigger which will be called for overridden methods in the given
trigger implementation.
|
java.lang.Class<S> |
getStorableType()
Returns the specific type of Storable managed by this object.
|
S |
prepare()
Prepares a new object for loading, inserting, updating, or deleting.
|
Query<S> |
query()
Query for all Storable instances in this Storage.
|
Query<S> |
query(Filter<S> filter)
Query for Storable instances against an explicitly constructed filter
object.
|
Query<S> |
query(java.lang.String filter)
Query for Storable instances against a filter expression.
|
boolean |
removeTrigger(Trigger<? super S> trigger)
Remove a trigger which was registered earlier.
|
void |
truncate()
Attempts to quickly delete all Storables instances in this
Storage.
|
java.lang.Class<S> getStorableType()
S prepare()
Query<S> query() throws FetchException
FetchException
- if storage layer throws an exceptionquery(String)
Query<S> query(java.lang.String filter) throws FetchException
"ID = ?"
. Filters can also contain several kinds of relational
operators, boolean logic operators, sub-properties, and parentheses. A
more complex example might be "income < ? | (name = ? & address.zipCode != ?)"
.
When querying for a single Storable instance by its primary key, it is
generally more efficient to call prepare()
, set primary key
properties, and then call Storable.load()
. For example, consider
an object with a primary key consisting only of the property "ID". It
can be queried as:
Storage<UserInfo> users; UserInfo user = users.query("ID = ?").with(123456).loadOne();The above code will likely open a Cursor in order to verify that just one object was loaded. Instead, do this:
Storage<UserInfo> users; UserInfo user = users.prepare(); user.setID(123456); user.load();The complete syntax for query filters follows. Note that:
Filter = OrFilter OrFilter = AndFilter { "|" AndFilter } AndFilter = NotFilter { "&" NotFilter } NotFilter = [ "!" ] EntityFilter EntityFilter = PropertyFilter | ChainedFilter | "(" Filter ")" PropertyFilter = ChainedProperty RelOp "?" RelOp = "=" | "!=" | "<" | ">=" | ">" | "<=" ChainedFilter = ChainedProperty "(" [ Filter ] ")" ChainedProperty = Identifier | InnerJoin "." ChainedProperty | OuterJoin "." ChainedProperty InnerJoin = Identifier OuterJoin = "(" Identifier ")"
filter
- query filter expressionFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if filter is nullMalformedFilterException
- if expression is malformedjava.lang.UnsupportedOperationException
- if given filter is unsupported by repositoryQuery<S> query(Filter<S> filter) throws FetchException
filter
- query filterFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if filter is nulljava.lang.UnsupportedOperationException
- if given filter is unsupported by repositoryvoid truncate() throws PersistException
If this Storage has any registered triggers which act on deletes, all
Storables are deleted via query().deleteAll()
instead to ensure
these triggers get run.
PersistException
boolean addTrigger(Trigger<? super S> trigger)
java.lang.IllegalArgumentException
- if trigger is nullCopyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.