public interface ModelController<T extends Model>
Modifier and Type | Method and Description |
---|---|
List<T> |
all()
Return a list of all objects.
|
default FilterChain<T> |
anyOf(List<String>... filters)
Short-cut for filterChain().andAnyOf(["someField", "value"], ["otherField", "anotherValue"]);
Finds all items that match any of the criteria
|
default FilterChain<T> |
anyOf(Or... ors)
Short-cut for filterChain().andAnyOf(Or("someField", "someValue"), Or("someField", "someValue"));
Finds all items that match any of the criteria.
|
int |
countForKey(String keyName,
Object value)
Counts the items for a indexed/keyed field.
|
T |
detach(T obj)
Gets a cloned version of an object, so that you can work with the object with out affecting
the live, in memory version
|
FilterChain<T> |
filter(String name,
Object value)
Create a new FilterChain and set an initial filter whereby
the field @name is equal to @value
|
FilterChain<T> |
filter(String name,
Object value,
String op)
Create a new FilterChain and initialize with an initial filter.
|
FilterChain<T> |
filterBy(String name,
Object value,
FilterOperator op)
Create a new FilterChain and initialize with an initial filter.
|
FilterChain<T> |
filterByKey(String keyName,
Object value)
Instantiate a filter chain and start by filtering on an index/keyed field.
|
FilterChain<T> |
filterChain()
Create a new FilterChain instance for this controller.
|
default FilterChain<T> |
find(Map<String,Object> where)
Short-cut for applying filter(name, value) for every key-value pair in the dictionary.
|
T |
forId(Long id)
Loads an object by primary id.
|
default T |
forIdOrNotFound(Long id)
Calls forId() to load an object by id, raises a NotFoundException if it does not exist
|
T |
forIdWithDeleted(Long id)
Get the object by id.
|
T |
forUniqueKey(String keyName,
Object value)
Look up an object by a unique key.
|
default T |
forUniqueKeyOrNotFound(String keyName,
Object value)
Finds the item by key and value, raises a NotFoundException if it does not exist
|
String |
getBucket()
A name by which this controller gets accessed when it is accessed via a template,
or via DalRegistry.instance().get("bucketName").
|
Set<String> |
getKeyFields()
Get all model field names that were marked as indexed/keyed using the @Key
annotation on the getter
|
Class<T> |
getModelClass()
The Model class this controller manages.
|
Persister<T> |
getPersister()
The instance of the Perister class
|
ReadOnlyWrapper<T> |
getReadonlyWrapper()
Gets a controller implementation that wraps this controller, while stubbing out
all the write methods.
|
Stash<T> |
getStash()
The instance of the Stash class.
|
Set<String> |
getUniqueFields()
Get all model field names that were marked as a unique key using the @UniqueKey
annotation on the getter.
|
void |
hardDelete(T obj)
Actually removes the item from the underlying data store
|
void |
init(DataAccessRegistration registration,
Persister<T> persister,
Stash<T> stash)
Initialize the controller, loading all the key fields, setting defaults,
initializing key variables, etc.
|
Boolean |
isWritable()
True if this controller can create or update objects, false if this
controller is read-only.
|
List<T> |
listForKey(String keyName,
Object value)
Get all items for a indexed/keyed field.
|
void |
onPostCreate(T obj)
Override this to perform some action after the object is created.
|
void |
onPostLoadItem(T obj)
Override this to perform some action after an item is loaded from the datastore
|
void |
onPostSave(T obj)
Override this to perform some action after the object is saved
|
default void |
onPostSaveAuditTrailLog(T obj)
Override this to save to the audit trail log after a save
|
void |
onPreCreatePrepare(T obj)
Override this to prepare the object with any default values before it is
saved to the datastore for the first time.
|
void |
onPreCreateValidate(T obj)
Override this to prepare the validate the object before it is saved to the datastore
for the very first time.
|
void |
onPreRead() |
void |
onPreSavePrepare(T obj)
Override this to perform an action every time before the object is saved.
|
void |
onPreSaveValidate(T obj)
Override this to validate the object before it is saved.
|
T |
originalForId(Long id)
Load an object by id, without detaching it.
|
T |
originalForId(T id)
Load an object by id, without detaching it.
|
void |
reset()
If the datastore has been synced to memory, reset() will resync everything.
|
void |
save(T obj)
Saves "obj" to the persistence layer, creating it if it does not exist.
|
default FilterChain<T> |
search(String value,
String... fields)
Searches for @value in all @fields, using a case-insensitive
string contains search.
|
void |
softDelete(T obj)
Calls obj.setDeleted(true) then saves the object.
|
default void |
update(T obj,
String field,
Object value)
Update
|
default void |
updateValues(T obj,
Map<String,Object> values)
Update
|
void init(DataAccessRegistration registration, Persister<T> persister, Stash<T> stash)
registration
- persister
- stash
- String getBucket()
Persister<T> getPersister()
Class<T> getModelClass()
Boolean isWritable()
ReadOnlyWrapper<T> getReadonlyWrapper()
T detach(T obj)
obj
- void save(T obj)
obj
- default void updateValues(T obj, Map<String,Object> values)
void softDelete(T obj)
obj
- void hardDelete(T obj)
obj
- void onPreRead()
void onPreSavePrepare(T obj)
obj
- void onPreSaveValidate(T obj)
obj
- void onPreCreatePrepare(T obj)
obj
- void onPreCreateValidate(T obj)
obj
- void onPostSave(T obj)
obj
- default void onPostSaveAuditTrailLog(T obj)
obj
- void onPostCreate(T obj)
obj
- void onPostLoadItem(T obj)
obj
- FilterChain<T> filterChain()
FilterChain<T> filter(String name, Object value)
name
- value
- default FilterChain<T> search(String value, String... fields)
value
- value
- FilterChain<T> filter(String name, Object value, String op)
name
- value
- op
- FilterChain<T> filterBy(String name, Object value, FilterOperator op)
name
- value
- op
- default FilterChain<T> find(Map<String,Object> where)
where
- - a map of key value pairs to find matching objets ofdefault FilterChain<T> anyOf(Or... ors)
default FilterChain<T> anyOf(List<String>... filters)
FilterChain<T> filterByKey(String keyName, Object value)
keyName
- value
- T forIdWithDeleted(Long id)
id
- T originalForId(T id)
id
- T forId(Long id)
id
- default T forIdOrNotFound(Long id)
id
- T originalForId(Long id)
id
- T forUniqueKey(String keyName, Object value)
keyName
- value
- default T forUniqueKeyOrNotFound(String keyName, Object value)
keyName
- value
- List<T> listForKey(String keyName, Object value)
keyName
- value
- int countForKey(String keyName, Object value)
keyName
- value
- Set<String> getKeyFields()
Set<String> getUniqueFields()
void reset()
Copyright © 2016. All rights reserved.