org.norther.tammi.spray.db.tool
Class RepositoryTool

java.lang.Object
  extended by org.norther.tammi.core.rt.Introspector
      extended by org.norther.tammi.spray.engine.tool.BeanTool
          extended by org.norther.tammi.spray.db.tool.RepositoryTool
All Implemented Interfaces:
Serializable, EventListener, Poolable, Recyclable, ContextBindingListener

public class RepositoryTool
extends BeanTool

A request context tool to create and access persistent objects.

Author:
Marketta Priha
See Also:
Serialized Form

Constructor Summary
RepositoryTool()
          The default constructor.
 
Method Summary
 void abortTransaction()
          Aborts a transaction.
 boolean addValues(Object node, String name, List result)
          Adds nested attribute values in a tree to a list.
 void beginTransaction()
          Starts a transaction.
 DBQuery buildQuery(Object sample)
          Builds a query by sample.
 DBQuery buildQuery(String className, DBCriteria criteria, boolean distinct)
          Builds a query by criteria.
 DBQuery buildQuery(String className, List columns, DBCriteria criteria, boolean distinct)
          Builds a query by criteria with a column array.
 DBQuery buildQuery(String className, String expr, boolean sql)
          Builds a query by expression.
 void clearCache()
          Clears the object cache, if any.
 void commitTransaction()
          Commits and closes a transaction.
 int count(Object query)
          Returns the count of objects specified by a query or class name.
 int count(String className, DBCriteria criteria)
          Returns the count of objects of the given class matching the specified criteria.
 int count(String className, String attribute, Object value, int condition)
          Returns the count of objects of the given class having the specified attribute.
protected  Variable createVariable(String type)
          Creates a variable MBean instance.
 boolean delete(Object object)
          Deletes an object.
 boolean deleteAll(Object query)
          Deletes objects.
 boolean deleteAll(String className, DBCriteria criteria)
          Deletes objects of the given class matching the specified criteria.
 boolean deleteAll(String className, String attribute, Object value, int condition)
          Deletes objects of the given class having the specified attribute.
 int depth(Object node, String rel)
          Returns the reference depth of a node.
 void dispose()
          Disposes the object after use.
 int distinctCount(String className, DBCriteria criteria)
          Returns the count of distinct objects of the given class matching the specified criteria.
 int distinctCount(String className, String attribute, Object value, int condition)
          Returns the count of distinct objects of the given class having the specified attribute.
 QueryIterator distinctIterator(String className, DBCriteria criteria)
          Returns an iterator to a collection of distinct objects of the given class matching the specified criteria.
 QueryIterator distinctIterator(String className, String attribute, Object value, int condition)
          Returns an iterator to a collection of distinct objects of the given class having the specified attribute.
 Object getAdaptee()
          Gets the persister adaptee, if any.
protected  BeanRepositoryFilter getBeanRepositoryFilter()
          Gets the bean repository filter from the filter stack.
 List getChain(Object node, String rel)
          Gets a chain of referenced objects in a tree, the end node at the lowest index.
 List getChain(Object node, String rel, String name)
          Gets a chain of attribute values of referenced objects in a tree, the attribute of the end node at the lowest index.
 String getConnectionKey()
          Gets the connection key of the current connection.
 DBCriteria getCriteria()
          Gets an empty criteria.
 Object getEnd(Object node, String rel)
          Gets the end node in a tree.
 VariableAttributeInfo getInfo(Variable variable, String name)
          Gets nested attribute info in a tree.
 List getList(Object node, String rel)
          Gets the next nodes in a tree.
 Map getMap(Object node, String rel)
          Gets a map of referenced objects in a tree.
 Map getMap(Object node, String rel, String name)
          Gets a map of attribute values of referenced objects in a tree.
 Object getNext(Object node, int index, String rel)
          Gets the indexed node in a tree.
 Object getNext(Object node, String rel)
          Gets the next node in a tree.
 Persister getPersister()
          Gets the persister with the current connection settings.
 Object getPKValue(Object node)
          Gets the primary key value.
 Object[] getPKValues(Object node)
          Gets the primary key values.
protected  RepositoryFilter getRepositoryFilter()
          Gets the repository filter from the filter stack.
 Object getRoot(Object node, String rel)
          Gets the root node in a tree.
 Object getValue(Object node, String name)
          Gets a nested attribute value in a tree.
 Object getValue(Variable variable, String name)
          Gets a nested attribute value in a tree.
 List getValues(Object node, String name)
          Gets a list of nested attribute values in a tree.
 boolean hasNext(Object node, String rel)
          Checks whether a node in a tree has a reference to the next one.
 boolean insert(Object object)
          Inserts an object.
 boolean insertAll(Collection c)
          Inserts objects.
 boolean isLocalizedVariables()
          Checks whether variables are localized.
 boolean isNullPK(Object pk)
          Checks whether the specified primary key value is a null key.
 boolean isRelated(Object node, String rel, Object pk)
          Checks whether a node in a tree is related to the specified key.
 boolean isRootPK(Object pk)
          Checks whether the specified primary key value is a root key.
 QueryIterator iterator(Object query)
          Returns an iterator to a collection of objects specified by a query or class name.
 QueryIterator iterator(String className, DBCriteria criteria)
          Returns an iterator to a collection of objects of the given class matching the specified criteria.
 QueryIterator iterator(String className, String attribute, Object value, int condition)
          Returns an iterator to a collection of objects of the given class having the specified attribute.
 Object query(Object sample)
          Queries a named MBean or an object matching the given sample regarding its fields.
 Object query(String className, Object value)
          Queries an object of the given class.
 Object query(String className, String attribute, Object value)
          Queries an object of the given class having the specified attribute.
 Collection queryAll(Object query)
          Queries a collection of objects specified by a query or class name.
 Collection queryAll(String className, DBCriteria criteria)
          Queries objects of the given class matching the specified criteria.
 Collection queryAll(String className, String attribute, Object value, int condition)
          Queries objects of the given class having the specified attribute.
 Collection queryDistinct(String className, DBCriteria criteria)
          Queries distinct objects of the given class matching the specified criteria.
 Collection queryDistinct(String className, String attribute, Object value, int condition)
          Queries distinct objects of the given class having the specified attribute.
 void refresh(Object object)
          Refreshes references.
 void refresh(Object object, String name)
          Retrieves a named reference.
 void remove(Object object)
          Removes an object from the cache.
 void setConnectionKey()
          Sets the connection key of the current connection to the default connection.
 void setConnectionKey(String key)
          Sets the connection key of the current connection.
 void setPKValue(Object node, Object value)
          Sets the primary key value.
 void setPKValues(Object node, Object[] values)
          Sets the primary key values.
 void setValue(Object node, String name, Object value)
          Sets a nested attribute value in a tree.
 void setValue(Object node, String name, Object value, boolean forced)
          Sets a nested attribute value in a tree with a forced option.
 void setValue(Variable variable, String name, Object value)
          Sets a nested attribute value in a tree.
 void setValue(Variable variable, String name, Object value, boolean forced)
          Sets a nested attribute value in a tree with a forced option.
 boolean store(Object object)
          Stores an object.
 boolean storeAll(Collection c)
          Stores objects.
 Identity toIdentity(Object[] pks, String type)
          Returns the identity of the specified primary keys and variable type.
 Identity toIdentity(Object pk, String type)
          Returns the identity of the specified primary key and variable type.
 Identity toIdentity(Variable var)
          Returns the identity of the specified variable.
 boolean update(Object object)
          Updates an object.
 boolean updateAll(Collection c)
          Updates objects.
 
Methods inherited from class org.norther.tammi.spray.engine.tool.BeanTool
addValue, addValue, create, create, create, create, disposed, getContext, getContextToolFilter, getDefaultLocale, getDescription, getDetail, getEnumeration, getFilter, getFilterChain, getFilterKey, getGroup, getKeyValue, getMBeanServer, getName, getPrincipal, getRequest, getResourceMap, getResponse, getValue, getVariableRegistry, isBound, isDisposed, isFilterChanged, length, recycle, recycled, removeValue, removeValue, setValue, toString, toStrings, valueBound, valueUnbound
 
Methods inherited from class org.norther.tammi.core.rt.Introspector
clearResourceCache, contains, exportTo, exportTo, getComparator, getConverter, getInfo, getList, getList, getLocale, getMax, getMin, getPattern, getResource, getResourceBundle, getResourceBundle, getResourceBundleName, getResourceBundleName, hasConverter, importFrom, importFrom, isArray, isBlankAccepted, isCloneable, isCorrelative, isDisabled, isEmptyAccepted, isEnumerated, isInteractive, isLocal, isLocalized, isMandatory, isOrdered, isReadable, isSerialized, isSorted, isTraceable, isTransient, isTrimmed, isVisible, isWritable, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepositoryTool

public RepositoryTool()
The default constructor.

Method Detail

dispose

public void dispose()
Description copied from interface: Recyclable
Disposes the object after use. The method is called when the object is returned to its pool. The dispose method must call its super.

Specified by:
dispose in interface Recyclable
Overrides:
dispose in class BeanTool

getConnectionKey

public String getConnectionKey()
Gets the connection key of the current connection.

Returns:
the connection key or null if not set.

setConnectionKey

public void setConnectionKey()
Sets the connection key of the current connection to the default connection.


setConnectionKey

public void setConnectionKey(String key)
Sets the connection key of the current connection. Connection specific username and password are applied when authenticating the connection.

Parameters:
key - the connection key or alias.

getPersister

public Persister getPersister()
Gets the persister with the current connection settings.

Returns:
the persister or null if not available.

clearCache

public void clearCache()
Clears the object cache, if any.


remove

public void remove(Object object)
Removes an object from the cache.

Parameters:
object - the object.

refresh

public void refresh(Object object)
Refreshes references.

Parameters:
object - the object.

refresh

public void refresh(Object object,
                    String name)
Retrieves a named reference.

Parameters:
object - the object.
name - the name of the reference.

getCriteria

public DBCriteria getCriteria()
Gets an empty criteria.

Returns:
the criteria or null if failed.

buildQuery

public DBQuery buildQuery(Object sample)
Builds a query by sample.

Parameters:
sample - the sample object.
Returns:
the query or null if failed.

buildQuery

public DBQuery buildQuery(String className,
                          String expr,
                          boolean sql)
Builds a query by expression.

Parameters:
className - the class name to query.
expr - the query expression.
sql - an SQL option.
Returns:
the query or null if failed.

buildQuery

public DBQuery buildQuery(String className,
                          DBCriteria criteria,
                          boolean distinct)
Builds a query by criteria.

Parameters:
className - the class name to query.
criteria - the criteria to apply.
distinct - true for a distinct query, false otherwise.
Returns:
the query or null if failed.

buildQuery

public DBQuery buildQuery(String className,
                          List columns,
                          DBCriteria criteria,
                          boolean distinct)
Builds a query by criteria with a column array.

Parameters:
className - the class name to query.
columns - a list of column names.
criteria - the criteria to apply.
distinct - true for a distinct query, false otherwise.
Returns:
the query or null if failed.

query

public Object query(Object sample)
Queries a named MBean or an object matching the given sample regarding its fields.

Parameters:
sample - the sample object to match to.
Returns:
an object in the repository matching the sample object or null.

query

public Object query(String className,
                    Object value)
Queries an object of the given class.

Parameters:
className - the class name of objects to return.
value - the primary key value of the object.
Returns:
the found object or null.

query

public Object query(String className,
                    String attribute,
                    Object value)
Queries an object of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
Returns:
the found object or null.

queryAll

public Collection queryAll(Object query)
Queries a collection of objects specified by a query or class name.

Parameters:
query - the query or class name of objects to return.
Returns:
a collection of objects found or null on error.

queryAll

public Collection queryAll(String className,
                           DBCriteria criteria)
Queries objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to return.
criteria - implementation specific criteria.
Returns:
a collection of objects found or null on error.

queryAll

public Collection queryAll(String className,
                           String attribute,
                           Object value,
                           int condition)
Queries objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
a collection of objects found or null on error.

iterator

public QueryIterator iterator(Object query)
Returns an iterator to a collection of objects specified by a query or class name.

Parameters:
query - the query or class name of objects to return.
Returns:
an iterator to the collection of objects found or null on error.

iterator

public QueryIterator iterator(String className,
                              DBCriteria criteria)
Returns an iterator to a collection of objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to return.
criteria - implementation specific criteria.
Returns:
an iterator to the collection of objects found or null on error.

iterator

public QueryIterator iterator(String className,
                              String attribute,
                              Object value,
                              int condition)
Returns an iterator to a collection of objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
the count of objects or -1 on error.

count

public int count(Object query)
Returns the count of objects specified by a query or class name.

Parameters:
query - the query or class name of objects to return.
Returns:
the count of objects or -1 on error.

count

public int count(String className,
                 DBCriteria criteria)
Returns the count of objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to count.
criteria - implementation specific criteria.
Returns:
the count of objects or -1 on error.

count

public int count(String className,
                 String attribute,
                 Object value,
                 int condition)
Returns the count of objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
the count of objects or -1 on error.

queryDistinct

public Collection queryDistinct(String className,
                                DBCriteria criteria)
Queries distinct objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to return.
criteria - implementation specific criteria.
Returns:
a collection of objects found or null on error.

queryDistinct

public Collection queryDistinct(String className,
                                String attribute,
                                Object value,
                                int condition)
Queries distinct objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
a collection of objects found or null on error.

distinctIterator

public QueryIterator distinctIterator(String className,
                                      DBCriteria criteria)
Returns an iterator to a collection of distinct objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to return.
criteria - implementation specific criteria.
Returns:
an iterator to the collection of objects found or null on error.

distinctIterator

public QueryIterator distinctIterator(String className,
                                      String attribute,
                                      Object value,
                                      int condition)
Returns an iterator to a collection of distinct objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
the count of objects or -1 on error.

distinctCount

public int distinctCount(String className,
                         DBCriteria criteria)
Returns the count of distinct objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to count.
criteria - implementation specific criteria.
Returns:
the count of objects or -1 on error.

distinctCount

public int distinctCount(String className,
                         String attribute,
                         Object value,
                         int condition)
Returns the count of distinct objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
the count of objects or -1 on error.

store

public boolean store(Object object)
Stores an object.

Parameters:
object - an object to store.
Returns:
true if successful, false otherwise.

storeAll

public boolean storeAll(Collection c)
Stores objects.

Parameters:
c - a collection to store.
Returns:
true if successful, false otherwise.

insert

public boolean insert(Object object)
Inserts an object.

Parameters:
object - an object to insert.
Returns:
true if successful, false otherwise.

insertAll

public boolean insertAll(Collection c)
Inserts objects.

Parameters:
c - a collection to insert.
Returns:
true if successful, false otherwise.

update

public boolean update(Object object)
Updates an object.

Parameters:
object - an object to update.
Returns:
true if successful, false otherwise.

updateAll

public boolean updateAll(Collection c)
Updates objects.

Parameters:
c - a collection to update.
Returns:
true if successful, false otherwise.

delete

public boolean delete(Object object)
Deletes an object.

Parameters:
object - an object to delete.
Returns:
true if successful, false otherwise.

deleteAll

public boolean deleteAll(Object query)
Deletes objects.

Parameters:
query - a query, class name or collection of objects to delete.
Returns:
true if successful, false otherwise.

deleteAll

public boolean deleteAll(String className,
                         DBCriteria criteria)
Deletes objects of the given class matching the specified criteria.

Parameters:
className - the class name of objects to return.
criteria - implementation specific criteria.
Returns:
true if successful, false otherwise.

deleteAll

public boolean deleteAll(String className,
                         String attribute,
                         Object value,
                         int condition)
Deletes objects of the given class having the specified attribute.

Parameters:
className - the class name of objects to return.
attribute - the name of the attribute.
value - the value of the attribute.
condition - the condition for the criteria.
Returns:
true if successful, false otherwise.

beginTransaction

public void beginTransaction()
Starts a transaction.


commitTransaction

public void commitTransaction()
Commits and closes a transaction.


abortTransaction

public void abortTransaction()
Aborts a transaction.


isNullPK

public boolean isNullPK(Object pk)
Checks whether the specified primary key value is a null key.

Parameters:
pk - the pk to check.
Returns:
true for a null key, false otherwise.

isRootPK

public boolean isRootPK(Object pk)
Checks whether the specified primary key value is a root key.

Parameters:
pk - the pk to check.
Returns:
true for a root key, false otherwise.

getPKValue

public Object getPKValue(Object node)
Gets the primary key value.

Parameters:
node - the node object.
Returns:
the primary key value or null.

setPKValue

public void setPKValue(Object node,
                       Object value)
Sets the primary key value.

Parameters:
node - the node object.
value - the primary key value.

getPKValues

public Object[] getPKValues(Object node)
Gets the primary key values.

Parameters:
node - the node object.
Returns:
the primary key values or null.

setPKValues

public void setPKValues(Object node,
                        Object[] values)
Sets the primary key values.

Parameters:
node - the node object.
values - the primary key values.

getInfo

public VariableAttributeInfo getInfo(Variable variable,
                                     String name)
Gets nested attribute info in a tree.

Overrides:
getInfo in class Introspector
Parameters:
variable - the variable.
name - the attribute name(s).
Returns:
the named attribute or null.

getValue

public Object getValue(Variable variable,
                       String name)
Gets a nested attribute value in a tree.

This method is required to override an inherited method.

Overrides:
getValue in class BeanTool
Parameters:
variable - the variable.
name - the attribute name(s).
Returns:
the attribute value or null.

setValue

public void setValue(Variable variable,
                     String name,
                     Object value)
Sets a nested attribute value in a tree.

This method is required to override an inherited method.

Overrides:
setValue in class BeanTool
Parameters:
variable - the variable.
name - the attribute name(s).
value - the attribute value.

setValue

public void setValue(Variable variable,
                     String name,
                     Object value,
                     boolean forced)
Sets a nested attribute value in a tree with a forced option.

This method is required to override an inherited method.

Overrides:
setValue in class BeanTool
Parameters:
variable - the variable.
name - the attribute name(s).
value - the attribute value.
forced - if true, forces the setting.

getValue

public Object getValue(Object node,
                       String name)
Gets a nested attribute value in a tree.

Parameters:
node - the node object.
name - the attribute name(s).
Returns:
the attribute value or null.

setValue

public void setValue(Object node,
                     String name,
                     Object value)
Sets a nested attribute value in a tree.

Parameters:
node - the node object.
name - the attribute name(s).
value - the attribute value.

setValue

public void setValue(Object node,
                     String name,
                     Object value,
                     boolean forced)
Sets a nested attribute value in a tree with a forced option.

Parameters:
node - the node object.
name - the attribute name(s).
value - the attribute value.
forced - if true, forces the setting.

getValues

public List getValues(Object node,
                      String name)
Gets a list of nested attribute values in a tree.

Parameters:
node - the node object.
name - the attribute name(s).
Returns:
the attribute list or null.

addValues

public boolean addValues(Object node,
                         String name,
                         List result)
Adds nested attribute values in a tree to a list.

Parameters:
node - the node object.
name - the attribute name(s).
result - the attribute list.
Returns:
true if added, false otherwise.

getEnd

public Object getEnd(Object node,
                     String rel)
Gets the end node in a tree.

Parameters:
node - the node object.
rel - the relation attribute.
Returns:
the end node.

getRoot

public Object getRoot(Object node,
                      String rel)
Gets the root node in a tree.

Parameters:
node - the node object.
rel - the relation attribute.
Returns:
the root node.

getNext

public Object getNext(Object node,
                      String rel)
Gets the next node in a tree.

Parameters:
node - the node object.
rel - the relation attribute.
Returns:
the next node or null.

getNext

public Object getNext(Object node,
                      int index,
                      String rel)
Gets the indexed node in a tree.

Parameters:
node - the node object.
index - the variable index.
rel - the relation attribute.
Returns:
the next node or null.

getList

public List getList(Object node,
                    String rel)
Gets the next nodes in a tree.

Parameters:
node - the node object.
rel - the relation attribute.
Returns:
the node list or null.

isRelated

public boolean isRelated(Object node,
                         String rel,