@groovy.transform.CompileStatic trait GormEntity
A trait that turns any class into a GORM entity
Type Params | Return Type | Name and description |
---|---|---|
|
D |
addTo(java.lang.String associationName, java.lang.Object arg) Adds the given value to given association ensuring both sides are correctly associated |
|
D |
attach() Attaches an instance to an existing session. |
|
static java.lang.Integer |
count() Counts the number of persisted entities |
|
static D |
create() Creates an instance of this class |
|
static BuildableCriteria |
createCriteria() Creates a criteria builder instance |
|
void |
delete() Deletes an instance from the datastore |
|
void |
delete(java.util.Map params) Deletes an instance from the datastore |
|
static void |
deleteAll(java.lang.Object... objectsToDelete) Deletes a list of objects in one go |
|
static void |
deleteAll(java.lang.Iterable objectToDelete) Deletes a list of objects in one go |
|
void |
discard() Discards any pending changes. |
|
static java.util.List |
executeQuery(java.lang.CharSequence query) Executes a query for the given String |
|
static java.util.List |
executeQuery(java.lang.CharSequence query, java.util.Map args) Executes a query for the given String |
|
static java.util.List |
executeQuery(java.lang.CharSequence query, java.util.Map params, java.util.Map args) Executes a query for the given String |
|
static java.util.List |
executeQuery(java.lang.CharSequence query, java.util.Collection params) Executes a query for the given String |
|
static java.util.List |
executeQuery(java.lang.CharSequence query, java.lang.Object... params) Executes a query for the given String |
|
static java.util.List |
executeQuery(java.lang.CharSequence query, java.util.Collection params, java.util.Map args) Executes a query for the given String |
|
static java.lang.Integer |
executeUpdate(java.lang.CharSequence query) Executes an update for the given String |
|
static java.lang.Integer |
executeUpdate(java.lang.CharSequence query, java.util.Map args) Executes an update for the given String |
|
static java.lang.Integer |
executeUpdate(java.lang.CharSequence query, java.util.Map params, java.util.Map args) Executes an update for the given String |
|
static java.lang.Integer |
executeUpdate(java.lang.CharSequence query, java.util.Collection params) Executes an update for the given String |
|
static java.lang.Integer |
executeUpdate(java.lang.CharSequence query, java.lang.Object... params) Executes an update for the given String |
|
static java.lang.Integer |
executeUpdate(java.lang.CharSequence query, java.util.Collection params, java.util.Map args) Executes an update for the given String |
|
static boolean |
exists(java.io.Serializable id) Checks whether an entity exists |
|
static D |
find(groovy.lang.Closure callable) Uses detached criteria to build a query and then execute it returning a list |
|
static D |
find(D example) Finds an object by example |
|
static D |
find(D example, java.util.Map args) Finds an object by example using the given arguments for pagination |
|
static D |
find(java.lang.CharSequence query) Finds an object for the given string-based query |
|
static D |
find(java.lang.CharSequence query, java.util.Map params) Finds an object for the given string-based query and named parameters |
|
static D |
find(java.lang.CharSequence query, java.util.Map params, java.util.Map args) Finds an object for the given string-based query, named parameters and arguments |
|
static D |
find(java.lang.CharSequence query, java.util.Collection params) Finds an object for the given string-based query and positional parameters |
|
static D |
find(java.lang.CharSequence query, java.lang.Object[] params) Finds an object for the given string-based query and positional parameters |
|
static D |
find(java.lang.CharSequence query, java.util.Collection params, java.util.Map args) Finds an object for the given string-based query, positional parameters and arguments |
|
static java.util.List<D> |
findAll(groovy.lang.Closure callable) Uses detached criteria to build a query and then execute it returning a list |
|
static java.util.List<D> |
findAll(java.util.Map args, groovy.lang.Closure callable) Uses detached criteria to build a query and then execute it returning a list |
|
static java.util.List<D> |
findAll(java.util.Map params = Collections.emptyMap() The same as list() |
|
static java.util.List<D> |
findAll(D example) Finds an object by example |
|
static java.util.List<D> |
findAll(D example, java.util.Map args) Finds an object by example using the given arguments for pagination |
|
static java.util.List<D> |
findAll(java.lang.CharSequence query) Finds all objects for the given string-based query |
|
static java.util.List<D> |
findAll(java.lang.CharSequence query, java.util.Map params) Finds all objects for the given string-based query and named parameters |
|
static java.util.List<D> |
findAll(java.lang.CharSequence query, java.util.Map params, java.util.Map args) Finds all objects for the given string-based query, named parameters and arguments |
|
static java.util.List<D> |
findAll(java.lang.CharSequence query, java.util.Collection params) Finds all objects for the given string-based query and positional parameters |
|
static java.util.List<D> |
findAll(java.lang.CharSequence query, java.lang.Object[] params) Finds all objects for the given string-based query and positional parameters |
|
static java.util.List<D> |
findAll(java.lang.CharSequence query, java.util.Collection params, java.util.Map args) Finds all objects for the given string-based query, positional parameters and arguments |
|
static java.util.List<D> |
findAllWhere(java.util.Map queryMap) Finds all results matching all of the given conditions. |
|
static java.util.List<D> |
findAllWhere(java.util.Map queryMap, java.util.Map args) Finds all results matching all of the given conditions. |
|
static D |
findOrCreateWhere(java.util.Map queryMap) Finds a single result matching all of the given conditions. |
|
static D |
findOrSaveWhere(java.util.Map queryMap) Finds a single result matching all of the given conditions. |
|
static D |
findWhere(java.util.Map queryMap) Finds a single result matching all of the given conditions. |
|
static D |
findWhere(java.util.Map queryMap, java.util.Map args) Finds a single result matching all of the given conditions. |
|
static D |
first() Finds the first object using the natural sort order |
|
static D |
first(java.lang.String propertyName) Finds the first object sorted by propertyName |
|
static D |
first(java.util.Map queryParams) Finds the first object. |
|
static D |
get(java.io.Serializable id) Retrieves and object from the datastore. eg. |
|
static java.util.List<D> |
getAll(java.lang.Iterable<java.io.Serializable> ids) Retrieve all the objects for the given identifiers |
|
static java.util.List<D> |
getAll(java.io.Serializable... ids) Retrieve all the objects for the given identifiers |
|
static java.util.List<D> |
getAll() @return Synonym for list() |
|
java.io.Serializable |
getAssociationId(java.lang.String associationName) Obtains the id of an association without initialising the association |
|
static java.lang.Integer |
getCount() Same as count() but allows property-style syntax (Foo.count) |
|
java.util.List |
getDirtyPropertyNames() Obtains a list of property names that are dirty |
|
static java.util.List<FinderMethod> |
getGormDynamicFinders() |
|
static PersistentEntity |
getGormPersistentEntity() @return The PersistentEntity for this class |
|
static GormQueryOperations<D> |
getNamedQuery(java.lang.String queryName) Looks up a named query |
|
java.lang.Object |
getPersistentValue(java.lang.String fieldName) Gets the original persisted value of a field. |
|
java.io.Serializable |
ident() Returns the objects identifier |
|
D |
insert() Forces an insert of an object to the datastore |
|
D |
insert(java.util.Map params) Forces an insert of an object to the datastore |
|
boolean |
instanceOf(java.lang.Class cls) Proxy aware instanceOf implementation. |
|
boolean |
isAttached() No concept of session-based model so defaults to true |
|
boolean |
isDirty(java.lang.String fieldName) Checks whether a field is dirty |
|
boolean |
isDirty() Checks whether an entity is dirty |
|
static D |
last() Finds the last object using the natural sort order |
|
static D |
last(java.lang.String propertyName) Finds the last object sorted by propertyName |
|
static D |
last(java.util.Map queryParams) Finds the last object. |
|
static java.util.List<D> |
list(java.util.Map params) Lists objects in the datastore. eg. |
|
static java.util.List<D> |
list() List all entities |
|
static D |
load(java.io.Serializable id) Retrieves and object from the datastore as a proxy. eg. |
|
D |
lock() Upgrades an existing persistence instance to a write lock |
|
static D |
lock(java.io.Serializable id) Locks an instance for an update |
|
D |
merge() Saves an object the datastore |
|
D |
merge(java.util.Map params) Saves an object the datastore |
|
static D |
merge(D d) Merges an instance with the current session |
|
java.lang.Object |
mutex(groovy.lang.Closure callable) Locks the instance for updates for the scope of the passed closure |
|
java.lang.Object |
propertyMissing(java.lang.String name) Allow access to datasource by name |
|
static D |
proxy(java.io.Serializable id) Retrieves and object from the datastore as a proxy. eg. |
|
static D |
read(java.io.Serializable id) Retrieves and object from the datastore. eg. |
|
D |
refresh() Refreshes the state of the current instance |
|
D |
removeFrom(java.lang.String associationName, java.lang.Object arg) Removes the given value to given association ensuring both sides are correctly disassociated |
|
D |
save() Saves an object the datastore |
|
D |
save(boolean validate) Save method that takes a boolean which indicates whether to perform validation or not |
|
D |
save(java.util.Map params) Saves an object with the given parameters |
|
static java.util.List<java.io.Serializable> |
saveAll(java.lang.Object... objectsToSave) Saves a list of objects in one go |
|
static java.util.List<java.io.Serializable> |
saveAll(java.lang.Iterable<?> objectsToSave) Saves a list of objects in one go |
|
static java.lang.Object |
staticMethodMissing(java.lang.String methodName, java.lang.Object arg) Handles static method missing for dynamic finders |
|
static java.lang.Object |
staticPropertyMissing(java.lang.String property) Handles property missing, does nothing by default, sub traits to override |
|
static void |
staticPropertyMissing(java.lang.String property, java.lang.Object value) Handles property missing, does nothing by default, sub traits to override |
|
static DetachedCriteria<D> |
where(groovy.lang.Closure callable) @param callable Callable closure containing detached criteria definition |
|
static DetachedCriteria<D> |
whereAny(groovy.lang.Closure callable) @param callable Callable closure containing detached criteria definition |
|
static DetachedCriteria<D> |
whereLazy(groovy.lang.Closure callable) @param callable Callable closure containing detached criteria definition |
|
static java.lang.Object |
withCriteria(groovy.lang.Closure callable) Creates a criteria builder instance |
|
static java.lang.Object |
withCriteria(java.util.Map builderArgs, groovy.lang.Closure callable) Creates a criteria builder instance |
<T> |
static T |
withDatastoreSession(groovy.lang.Closure<T> callable) Same as withSession, but present for the case where withSession is overridden to use the Hibernate session |
<T> |
static T |
withNewSession(groovy.lang.Closure<T> callable) Creates and binds a new session for the scope of the given closure |
<T> |
static T |
withNewTransaction(groovy.lang.Closure<T> callable) Executes the closure within the context of a new transaction |
<T> |
static T |
withNewTransaction(java.util.Map transactionProperties, groovy.lang.Closure<T> callable) Executes the closure within the context of a new transaction which is configured with the properties contained in transactionProperties. |
<T> |
static T |
withSession(groovy.lang.Closure<T> callable) Execute a closure whose first argument is a reference to the current session. |
<T> |
static T |
withStatelessSession(groovy.lang.Closure<T> callable) Creates and binds a new session for the scope of the given closure |
<T> |
static T |
withTransaction(groovy.lang.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. |
<T> |
static T |
withTransaction(java.util.Map transactionProperties, groovy.lang.Closure<T> callable) Executes the closure within the context of a transaction which is configured with the properties contained in transactionProperties. |
<T> |
static T |
withTransaction(org.springframework.transaction.TransactionDefinition definition, groovy.lang.Closure<T> callable) Executes the closure within the context of a transaction for the given org.springframework.transaction.TransactionDefinition |
Adds the given value to given association ensuring both sides are correctly associated
associationName
- The association namearg
- The valueAttaches an instance to an existing session. Requries a session-based model
Counts the number of persisted entities
Creates an instance of this class
Creates a criteria builder instance
Deletes an instance from the datastore
Deletes an instance from the datastore
Deletes a list of objects in one go
objectsToDelete
- The objects to deleteDeletes a list of objects in one go
objectsToDelete
- Collection of objects to deleteDiscards any pending changes. Requires a session-based model.
Executes a query for the given String
query
- The query represented by the given stringExecutes a query for the given String
query
- The query represented by the given stringargs
- The arguments to the queryExecutes a query for the given String
query
- The query represented by the given stringparams
- The named parameters to the queryargs
- The arguments to the queryExecutes a query for the given String
query
- The query represented by the given stringparams
- The positional parameters to the queryExecutes a query for the given String
query
- The query represented by the given stringparams
- The positional parameters to the queryExecutes a query for the given String
query
- The query represented by the given stringparams
- The positional parameters to the queryargs
- The arguments to the queryExecutes an update for the given String
query
- The query represented by the given stringExecutes an update for the given String
query
- The query represented by the given stringparams
- The parameters to the queryExecutes an update for the given String
query
- The query represented by the given stringparams
- The parameters to the queryargs
- The arguments to the queryExecutes an update for the given String
query
- The query represented by the given stringparams
- The positional parameters to the queryExecutes an update for the given String
query
- The query represented by the given stringparams
- The positional parameters to the queryExecutes an update for the given String
query
- The query represented by the given stringparams
- The positional parameters to the queryargs
- The arguments to the queryChecks whether an entity exists
Uses detached criteria to build a query and then execute it returning a list
callable
- The callableFinds an object by example
example
- The exampleFinds an object by example using the given arguments for pagination
example
- The exampleargs
- The argumentsFinds an object for the given string-based query
query
- The queryFinds an object for the given string-based query and named parameters
query
- The queryparams
- The parametersFinds an object for the given string-based query, named parameters and arguments
query
- The queryparams
- The parametersFinds an object for the given string-based query and positional parameters
query
- The queryparams
- The parametersFinds an object for the given string-based query and positional parameters
query
- The queryparams
- The parametersFinds an object for the given string-based query, positional parameters and arguments
query
- The queryparams
- The parametersUses detached criteria to build a query and then execute it returning a list
callable
- The callableUses detached criteria to build a query and then execute it returning a list
args
- pagination parameterscallable
- The callableThe same as list()
Finds an object by example
example
- The exampleFinds an object by example using the given arguments for pagination
example
- The exampleargs
- The argumentsFinds all objects for the given string-based query
query
- The queryFinds all objects for the given string-based query and named parameters
query
- The queryparams
- The parametersFinds all objects for the given string-based query, named parameters and arguments
query
- The queryparams
- The parametersFinds all objects for the given string-based query and positional parameters
query
- The queryparams
- The parametersFinds all objects for the given string-based query and positional parameters
query
- The queryparams
- The parametersFinds all objects for the given string-based query, positional parameters and arguments
query
- The queryparams
- The parametersFinds all results matching all of the given conditions. Eg. Book.findAllWhere(author:"Stephen King", title:"The Stand")
queryMap
- The map of conditionsFinds all results matching all of the given conditions. Eg. Book.findAllWhere(author:"Stephen King", title:"The Stand")
queryMap
- The map of conditionsargs
- The Query argumentsFinds a single result matching all of the given conditions. Eg. Book.findWhere(author:"Stephen King", title:"The Stand"). If a matching persistent entity is not found a new entity is created and returned.
queryMap
- The map of conditionsFinds a single result matching all of the given conditions. Eg. Book.findWhere(author:"Stephen King", title:"The Stand"). If a matching persistent entity is not found a new entity is created, saved and returned.
queryMap
- The map of conditionsFinds a single result matching all of the given conditions. Eg. Book.findWhere(author:"Stephen King", title:"The Stand")
queryMap
- The map of conditionsFinds a single result matching all of the given conditions. Eg. Book.findWhere(author:"Stephen King", title:"The Stand")
queryMap
- The map of conditionsargs
- The Query argumentsFinds the first object using the natural sort order
Finds the first object sorted by propertyName
propertyName
- the name of the property to sort byFinds the first object. If queryParams includes 'sort', that will dictate the sort order, otherwise natural sort order will be used. queryParams may include any of the same parameters that might be passed to the list(Map) method. This method will ignore 'order' and 'max' as those are always 'asc' and 1, respectively.
Retrieves and object from the datastore. eg. Book.get(1)
Retrieve all the objects for the given identifiers
ids
- The identifiers to operate againstRetrieve all the objects for the given identifiers
ids
- The identifiers to operate against
Obtains the id of an association without initialising the association
associationName
- The association nameSame as count() but allows property-style syntax (Foo.count)
Obtains a list of property names that are dirty
instance
- The instance
Looks up a named query
queryName
- The name of the queryGets the original persisted value of a field.
fieldName
- The field nameReturns the objects identifier
Forces an insert of an object to the datastore
Forces an insert of an object to the datastore
Proxy aware instanceOf implementation.
No concept of session-based model so defaults to true
Checks whether a field is dirty
instance
- The instancefieldName
- The name of the fieldChecks whether an entity is dirty
instance
- The instanceFinds the last object using the natural sort order
Finds the last object sorted by propertyName
propertyName
- the name of the property to sort byFinds the last object. If queryParams includes 'sort', that will dictate the sort order, otherwise natural sort order will be used. queryParams may include any of the same parameters that might be passed to the list(Map) method. This method will ignore 'order' and 'max' as those are always 'asc' and 1, respectively.
Lists objects in the datastore. eg. Book.list(max:10)
params
- Any parameters such as offset, max etc.List all entities
Retrieves and object from the datastore as a proxy. eg. Book.load(1)
Upgrades an existing persistence instance to a write lock
Locks an instance for an update
id
- The identifierSaves an object the datastore
Saves an object the datastore
Merges an instance with the current session
d
- The object to mergeLocks the instance for updates for the scope of the passed closure
callable
- The closureAllow access to datasource by name
instance
- The instancename
- The property nameRetrieves and object from the datastore as a proxy. eg. Book.proxy(1)
Retrieves and object from the datastore. eg. Book.read(1) Since the datastore abstraction doesn't support dirty checking yet this just delegates to get(Serializable)
Refreshes the state of the current instance
Removes the given value to given association ensuring both sides are correctly disassociated
associationName
- The association namearg
- The valueSaves an object the datastore
Save method that takes a boolean which indicates whether to perform validation or not
validate
- Whether to perform validationSaves an object with the given parameters
instance
- The instanceparams
- The parametersSaves a list of objects in one go
objectsToSave
- The objects to saveSaves a list of objects in one go
objectToSave
- Collection of objects to saveHandles static method missing for dynamic finders
methodName
- The name of the methodarg
- the argument to the methodHandles property missing, does nothing by default, sub traits to override
property
- The propertyHandles property missing, does nothing by default, sub traits to override
property
- The propertyvalue
- The value of the property
callable
- Callable closure containing detached criteria definition
callable
- Callable closure containing detached criteria definition
callable
- Callable closure containing detached criteria definitionCreates a criteria builder instance
Creates a criteria builder instance
Same as withSession, but present for the case where withSession is overridden to use the Hibernate session
callable
- the closureCreates and binds a new session for the scope of the given closure
Executes the closure within the context of a new transaction
callable
- The closure to callExecutes the closure within the context of a new transaction which is configured with the properties contained in transactionProperties. transactionProperties may contain any properties supported by org.springframework.transaction.support.DefaultTransactionDefinition. Note that if transactionProperties includes entries for propagationBehavior or propagationName, those values will be ignored. This method always sets the propagation level to TransactionDefinition.REQUIRES_NEW.
SomeEntity.withNewTransaction([isolationLevel: TransactionDefinition.ISOLATION_REPEATABLE_READ]) { // ... }
transactionProperties
- properties to configure the transaction propertiescallable
- The closure to callExecute a closure whose first argument is a reference to the current session.
callable
- the closureCreates and binds a new session for the scope of the given closure
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.
callable
- The closure to callExecutes the closure within the context of a transaction which is configured with the properties contained in transactionProperties. transactionProperties may contain any properties supported by org.springframework.transaction.support.DefaultTransactionDefinition.
SomeEntity.withTransaction([propagationBehavior: TransactionDefinition.PROPAGATION_REQUIRES_NEW, isolationLevel: TransactionDefinition.ISOLATION_REPEATABLE_READ]) { // ... }
transactionProperties
- properties to configure the transaction propertiescallable
- The closure to callExecutes the closure within the context of a transaction for the given org.springframework.transaction.TransactionDefinition
callable
- The closure to call