org.codehaus.groovy.grails.scaffolding
Class DefaultScaffoldDomain

java.lang.Object
  extended by org.codehaus.groovy.grails.scaffolding.DefaultScaffoldDomain
All Implemented Interfaces:
ScaffoldDomain
Direct Known Subclasses:
GrailsScaffoldDomain

public class DefaultScaffoldDomain
extends Object
implements ScaffoldDomain

The default implementation of a Scaffolding application that uses Hibernate as the persistence mechanism. Provides simple CRUD facilities onto a Hibernate domain model.

Since:
0.1 Created 30 Nov 2005
Author:
Graeme Rocher

Constructor Summary
DefaultScaffoldDomain(Class persistentClass, org.hibernate.SessionFactory sessionFactory)
           
 
Method Summary
 Object delete(Serializable id)
           
 List find(String[] by, Object[] q)
          Finds all the persistent instances for the specified properties and query values
 List find(String[] by, Object[] q, int max)
           
 List find(String[] by, Object[] q, int max, int offset)
           
 List find(String by, Object q)
          Finds all persistent instances for the specified property name and value
 List find(String by, Object q, int max)
           
 List find(String by, Object q, int max, int offset)
           
 Object get(Serializable id)
          Retrieves an persistent class instance for the specified id
 String getIdentityPropertyName()
           
 String getName()
           
 Class getPersistentClass()
          Retrieves the scaffolded persistent class
 String getPluralName()
          Returns the plural name of the domain
 String getSingularName()
          Returns the singular name of the domain
 List list()
           
 List list(int max)
           
 List list(int max, int offset)
           
 List list(int max, int offset, String sort)
           
 List list(int max, int offset, String sort, String order)
           
 Object newInstance()
           
 boolean save(Object domainObject, ScaffoldCallback callback)
          Saves an instance of the persistent class using the specified properties
 void setIdentityPropertyName(String identityPropertyName)
          Sets the name of the identity property so that type conversion can be performed
 void setPersistentClass(Class persistentClass)
          Sets the persistent class used by the scaffold domain
 void setSessionFactory(Object sessionFactory)
          Sets the session factory used by the persistent implementation
protected  void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
           
 void setValidator(Validator validator)
          Sets the validator to use
 boolean update(Object domainObject, ScaffoldCallback callback)
          Updates an existing instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultScaffoldDomain

public DefaultScaffoldDomain(Class persistentClass,
                             org.hibernate.SessionFactory sessionFactory)
Method Detail

setValidator

public void setValidator(Validator validator)
Description copied from interface: ScaffoldDomain
Sets the validator to use

Specified by:
setValidator in interface ScaffoldDomain
Parameters:
validator - The validator to set.

setIdentityPropertyName

public void setIdentityPropertyName(String identityPropertyName)
Description copied from interface: ScaffoldDomain
Sets the name of the identity property so that type conversion can be performed

Specified by:
setIdentityPropertyName in interface ScaffoldDomain

setSessionFactory

protected void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Parameters:
sessionFactory - The sessionFactory to set.

list

public List list()
Specified by:
list in interface ScaffoldDomain
Returns:
All persistent instances of the scaffolded class

list

public List list(int max)
Specified by:
list in interface ScaffoldDomain
Parameters:
max - The maximum number of instances to return
Returns:
All persistent instances up to the maximum specified value

list

public List list(int max,
                 int offset)
Specified by:
list in interface ScaffoldDomain
Parameters:
max - The maximum number to return
offset - The offset position
Returns:
All persistent instances up to the maximum, offset by the specified value

list

public List list(int max,
                 int offset,
                 String sort)
Specified by:
list in interface ScaffoldDomain
Parameters:
max - The maximum number to return (Set to -1 for no maximum)
offset - The offset position (Set to -1 for no offset)
sort - The property name to sort by
Returns:
All persistent instances up to the maximum, offset by the specified value

list

public List list(int max,
                 int offset,
                 String sort,
                 String order)
Specified by:
list in interface ScaffoldDomain
Parameters:
max - The maximum number to return (Set to -1 for no maximum)
offset - The offset position (Set to -1 for no offset)
sort - The property name to sort by
order - either "ASC" for ascending or "DESC" for descending
Returns:
All persistent instances up to the maximum, offset by the specified value

find

public List find(String by,
                 Object q)
Description copied from interface: ScaffoldDomain
Finds all persistent instances for the specified property name and value

Specified by:
find in interface ScaffoldDomain
Parameters:
by - The property to find by
q - The query criteria
Returns:
A list of found persistent instances

find

public List find(String by,
                 Object q,
                 int max)
Specified by:
find in interface ScaffoldDomain
max - The maximum number of results to return
See Also:
for description

find

public List find(String by,
                 Object q,
                 int max,
                 int offset)
Specified by:
find in interface ScaffoldDomain
max - The maximum number of results to return
offset - The offset position
See Also:
for description

find

public List find(String[] by,
                 Object[] q)
Description copied from interface: ScaffoldDomain
Finds all the persistent instances for the specified properties and query values

Specified by:
find in interface ScaffoldDomain
Parameters:
by - The properties to find by
q - The query values
Returns:
A list of persistent instances

find

public List find(String[] by,
                 Object[] q,
                 int max)
Specified by:
find in interface ScaffoldDomain
max - The maximum number of results to return
See Also:
for description

find

public List find(String[] by,
                 Object[] q,
                 int max,
                 int offset)
Specified by:
find in interface ScaffoldDomain
max - The maximum number of results to return
offset - The offset position
See Also:
for description

save

public boolean save(Object domainObject,
                    ScaffoldCallback callback)
Description copied from interface: ScaffoldDomain
Saves an instance of the persistent class using the specified properties

Specified by:
save in interface ScaffoldDomain
Parameters:
domainObject - The domain object to save
callback - Any validation errors that may have occured during saving
Returns:
The saved instance or null if save was unsuccessful

update

public boolean update(Object domainObject,
                      ScaffoldCallback callback)
Description copied from interface: ScaffoldDomain
Updates an existing instance

Specified by:
update in interface ScaffoldDomain
Returns:
The updated instance

delete

public Object delete(Serializable id)
Specified by:
delete in interface ScaffoldDomain
Returns:
The instance identified by id, if it existed

setPersistentClass

public void setPersistentClass(Class persistentClass)
Description copied from interface: ScaffoldDomain
Sets the persistent class used by the scaffold domain

Specified by:
setPersistentClass in interface ScaffoldDomain
Parameters:
persistentClass - The persistent class

get

public Object get(Serializable id)
Description copied from interface: ScaffoldDomain
Retrieves an persistent class instance for the specified id

Specified by:
get in interface ScaffoldDomain
Returns:
The instance identified by id, if it exists

getPluralName

public String getPluralName()
Description copied from interface: ScaffoldDomain
Returns the plural name of the domain

Specified by:
getPluralName in interface ScaffoldDomain
Returns:
The non-null plural name of the domain

getPersistentClass

public Class getPersistentClass()
Description copied from interface: ScaffoldDomain
Retrieves the scaffolded persistent class

Specified by:
getPersistentClass in interface ScaffoldDomain

getSingularName

public String getSingularName()
Description copied from interface: ScaffoldDomain
Returns the singular name of the domain

Specified by:
getSingularName in interface ScaffoldDomain
Returns:
The non-null singular name of the domain

getIdentityPropertyName

public String getIdentityPropertyName()
Specified by:
getIdentityPropertyName in interface ScaffoldDomain
Returns:
The identity property name

getName

public String getName()
Specified by:
getName in interface ScaffoldDomain
Returns:
The full name of the domain class

newInstance

public Object newInstance()
Specified by:
newInstance in interface ScaffoldDomain
Returns:
A new instance of the domain class

setSessionFactory

public void setSessionFactory(Object sessionFactory)
Description copied from interface: ScaffoldDomain
Sets the session factory used by the persistent implementation

Specified by:
setSessionFactory in interface ScaffoldDomain
Parameters:
sessionFactory - The session factory to use


Copyright (c) 2005-2006 The Grails project