@CompileStatic trait GormRepo
A trait that turns a class into a Repository
Type | Name and description |
---|---|
Boolean |
enableEvents default to true. |
Class<D> |
entityClass The java class for the Gorm domain (persistence entity). will generally get set in constructor or using the generic as done in GormRepo.getEntityClass using the GenericTypeResolver |
MapBinder |
mapBinder |
RepoEventPublisher |
repoEventPublisher |
RepoExceptionSupport |
repoExceptionSupport |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
bind(Map args = [:], D entity, Map data, BindAction bindAction) binds by calling doBind and fires before and after events better to override doBind in implementing classes for custom binding logic. |
|
void |
bindAndSave(Map args, D entity, Map data, BindAction bindAction) short cut to call bind, setup args for events then calls doPersist |
|
void |
clear() cache clear on the datastore's currentSession. |
|
D |
create(Map args = [:], Map data) Transactional wrap for doCreate |
|
void |
doBind(Map args, D entity, Map data, BindAction bindAction) Main bind method that redirects call to the injected mapBinder. |
|
D |
doCreate(Map args, Map data) Creates entity using the data from params. calls the bind with bindMethod='Create' |
|
D |
doPersist(Map args = [:], D entity) saves a domain entity with the passed in args. |
|
void |
doRemove(Map args = [:], D entity) no trx wrapper. delete entity. |
|
D |
doUpdate(Map args, Map data) Updates entity using the data from params. calls the bind with bindMethod='Update' |
|
void |
flush() flush on the datastore's currentSession. |
|
D |
get(Serializable id, Long version) gets and verifies that the entity can be retrieved and version matches. |
|
D |
get(Map params) This default will redirect the call to get(Serializable id, Long version). |
|
Datastore |
getDatastore() gets the datastore for this Gorm domain instance |
|
Class<D> |
getEntityClass() The gorm domain class. uses the GenericTypeResolver is not set during contruction |
|
GormInstanceApi<D> |
getInstanceApi() |
|
GormStaticApi<D> |
getStaticApi() |
|
RuntimeException |
handleException(RuntimeException ex, D entity) |
|
D |
persist(Map args = [:], D entity) Transactional wrap for doPersist Saves a domain entity with the passed in args and rewraps ValidationException with EntityValidationException on error. |
|
void |
remove(Map args = [:], D entity) Transactional, Calls delete always with flush = true so we can intercept any DataIntegrityViolationExceptions. |
|
void |
removeById(Map args = [:], Serializable id) Remove by ID |
|
D |
update(Map args = [:], Map data) Transactional wrap for doUpdate |
<T> |
T |
withTrx(Closure<T> callable) Executes the closure within the context of a transaction, creating one if none is present or joining an existing transaction if one is already present. |
default to true. If false only method events are invoked on the implemented Repository.
The java class for the Gorm domain (persistence entity). will generally get set in constructor or using the generic as done in GormRepo.getEntityClass using the GenericTypeResolver
binds by calling doBind and fires before and after events better to override doBind in implementing classes for custom binding logic. Or even better implement the beforeBind|afterBind event methods
short cut to call bind, setup args for events then calls doPersist
cache clear on the datastore's currentSession. When possible use the transactionStatus. see WithTrx trait
Main bind method that redirects call to the injected mapBinder. override this one in implementing classes. can also call this if you do NOT want the before/after Bind events to fire
Creates entity using the data from params. calls the bind with bindMethod='Create'
data
- the data to bind onto the entitysaves a domain entity with the passed in args. Not wrapped in a transaction. If a ValidationException is caught it wraps and throws it with our DataValidationException.
entity
- the domain entity to call save onargs
- (optional) - the arguments to pass to save as well as the PersistEvents. can be any of the normal gorm save args
plus some others specific to here
- failOnError: (boolean) defaults to true
- flush: (boolean) flush the session
- bindType: (String) "Create" or "Update" when coming from those actions/methods
- data: (Map) if it was a Create or Update method called then this is the data and gets passed into eventsno trx wrapper. delete entity.
entity
- - the domain instance to deleteargs
- - args passed to deleteUpdates entity using the data from params. calls the bind with bindMethod='Update'
data
- the data to bind onto the entityflush on the datastore's currentSession. When possible use the transactionStatus.flush(). see WithTrx trait
gets and verifies that the entity can be retrieved and version matches.
id
- required, the id to getversion
- - can be null. if its passed in then it validates its that same as the version in the retrieved entity.This default will redirect the call to get(Serializable id, Long version). Implementing classes can override this and add custom finders using another unique lookup key other than id, such as customer number or invoice number. Unlike the normal get(id) This throws a EntityNotFoundException if nothing is found instead of returning a null.
params
- - expects a Map with an id key and optionally a version, implementation classes can customize to work with more.gets the datastore for this Gorm domain instance
The gorm domain class. uses the GenericTypeResolver is not set during contruction
Transactional wrap for doPersist Saves a domain entity with the passed in args and rewraps ValidationException with EntityValidationException on error.
entity
- the domain entity to call save onargs
- the arguments to pass to save. adds the following but see doPersist for more.
- tx: defaults to true. set to true to make sure this is wrapped in a transaction.Transactional, Calls delete always with flush = true so we can intercept any DataIntegrityViolationExceptions.
entity
- the domain entityRemove by ID
id
- - the id to deleteargs
- - the args to pass to delete. flush being the most commonExecutes the closure within the context of a transaction, creating one if none is present or joining an existing transaction if one is already present.
callable
- The closure to call