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

Method Detail

D addTo(java.lang.String associationName, java.lang.Object arg)

Adds the given value to given association ensuring both sides are correctly associated

Returns:

This domain instance

Parameters:

associationName - The association name

arg - The value

D attach()

Attaches an instance to an existing session. Requries a session-based model

Finds all results matching all of the given conditions. Eg. Book.findAllWhere(author:"Stephen King", title:"The Stand")

Returns:

A list of results

Parameters:

queryMap - The map of conditions

args - The Query arguments

static D findOrCreateWhere(java.util.Map queryMap)

Finds 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.

Returns:

A single result

Parameters:

queryMap - The map of conditions

static D findOrSaveWhere(java.util.Map queryMap)

Finds 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.

Returns:

A single result

Parameters:

queryMap - The map of conditions

static D findWhere(java.util.Map queryMap)

Finds a single result matching all of the given conditions. Eg. Book.findWhere(author:"Stephen King", title:"The Stand")

Returns:

A single result

Parameters:

queryMap - The map of conditions

static D findWhere(java.util.Map queryMap, java.util.Map args)

Finds a single result matching all of the given conditions. Eg. Book.findWhere(author:"Stephen King", title:"The Stand")

Returns:

A single result

Parameters:

queryMap - The map of conditions

args - The Query arguments

static D first()

Finds the first object using the natural sort order

Returns:

the first object in the datastore, null if none exist

static D first(java.lang.String propertyName)

Finds the first object sorted by propertyName

Returns:

the first object in the datastore sorted by propertyName, null if none exist

Parameters:

propertyName - the name of the property to sort by

static D first(java.util.Map queryParams)

Finds 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.

static java.lang.Integer getCount()

@javax.persistence.Transient
java.util.List getDirtyPropertyNames()

Obtains a list of property names that are dirty. Note that unlike listDirtyPropertyNames() this method will inspect the
persistence context (session) which may or may not contain a more accurate reflection of the initial loaded state
depending on the underlying GORM implementation.

java.lang.Object getPersistentValue(java.lang.String fieldName)

Gets the original persisted value of a field. Note that unlike getOriginalValue(java.lang.String) this method will inspect the
persistence context (session) which may or may not contain a more accurate reflection of the initial loaded state
depending on the underlying GORM implementation.

Returns:

The original persisted value

Parameters:

fieldName - The field name

java.io.Serializable ident()

Returns the objects identifier

D insert()

Forces an insert of an object to the datastore

Returns:

Returns the instance

D insert(java.util.Map params)

Forces an insert of an object to the datastore

Returns:

Returns the instance

boolean instanceOf(java.lang.Class cls)

Proxy aware instanceOf implementation.

@javax.persistence.Transient
boolean isAttached()

No concept of session-based model so defaults to true

boolean isDirty(java.lang.String fieldName)

Checks whether a field is dirty. Note that unlike hasChanged() this method will inspect the
persistence context (session) which may or may not contain a more accurate reflection of the initial loaded state
depending on the underlying GORM implementation.

Returns:

true if the field is dirty

Parameters:

instance - The instance

fieldName - The name of the field

@javax.persistence.Transient
boolean isDirty()

Checks whether an entity is dirty. Note that unlike hasChanged() this method will inspect the
persistence context (session) which may or may not contain a more accurate reflection of the initial loaded state
depending on the underlying GORM implementation.

Returns:

true if it is dirty

Parameters:

instance - The instance

static D last()

Finds the last object using the natural sort order

Returns:

the last object in the datastore, null if none exist

static D last(java.lang.String propertyName)

Finds the last object sorted by propertyName

Returns:

the last object in the datastore sorted by propertyName, null if none exist

Parameters:

propertyName - the name of the property to sort by

static D last(java.util.Map queryParams)

Finds 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.

Returns:

the last object in the datastore, null if none exist

static java.util.List<D> list(java.util.Map params)

Lists objects in the datastore. eg. Book.list(max:10)

Returns:

A list of results

Parameters:

params - Any parameters such as offset, max etc.

static java.util.List<D> list()

List all entities

Returns:

The list of all entities

static D load(java.io.Serializable id)

Retrieves and object from the datastore as a proxy. eg. Book.load(1)

D lock()

Upgrades an existing persistence instance to a write lock

Returns:

The instance

static D lock(java.io.Serializable id)

Locks an instance for an update

Returns:

The instance

Parameters:

id - The identifier

D merge()

Saves an object the datastore

Returns:

Returns the instance

D merge(java.util.Map params)

Saves an object the datastore

Returns:

Returns the instance

static D merge(D d)

Merges an instance with the current session

Returns:

The instance

Parameters:

d - The object to merge

java.lang.Object mutex(groovy.lang.Closure callable)

Locks the instance for updates for the scope of the passed closure

Returns:

The result of the closure

Parameters:

callable - The closure

java.lang.Object propertyMissing(java.lang.String name)

Allow access to datasource by name

Returns:

The property value

Parameters:

instance - The instance

name - The property name

static D proxy(java.io.Serializable id)

Retrieves and object from the datastore as a proxy. eg. Book.proxy(1)

static D read(java.io.Serializable id)

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)

D refresh()

Refreshes the state of the current instance

Returns:

The instance

D removeFrom(java.lang.String associationName, java.lang.Object arg)

Removes the given value to given association ensuring both sides are correctly disassociated

Returns:

This domain instance

Parameters:

associationName - The association name

arg - The value

D save()

Saves an object the datastore

Returns:

Returns the instance

D save(boolean validate)

Save method that takes a boolean which indicates whether to perform validation or not

Executes 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.

Executes 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.