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

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.DataTool
All Implemented Interfaces:
Serializable, EventListener, Poolable, Recyclable, ContextBindingListener

public class DataTool
extends BeanTool

A request context tool to create and access persistent objects.

Version:
$Id: DataTool.java,v 1.23 2010-04-27 10:22:00 cvsimp Exp $
Author:
Marketta Priha
See Also:
Serialized Form

Field Summary
protected  int isLocalized
          The localized flag.
 
Constructor Summary
DataTool()
          The default constructor.
 
Method Summary
 void abortTransaction()
          Aborts a transaction.
 boolean addValues(Object node, String name, List<Object> result)
          Adds nested attribute values in a tree to a list.
 void beginTransaction()
          Starts a transaction.
 DBQuery<?> buildQuery(DBCriteria<?> criteria, boolean distinct, Object... clazz)
          Builds a query by criteria.
 DBQuery<Object[]> buildQuery(DBCriteria<?> criteria, List<String> attributes, boolean distinct, Object... clazz)
          Builds a query by criteria with attributes.
 DBQuery<?> buildQuery(Object sample)
          Builds a query by sample.
 DBQuery<?> buildQuery(String className, String expr, String type)
          Builds a query by expression.
 void clearCache()
          Clears the object cache, if any.
protected  void closeInternalPersister()
          Closes the internal persister.
 void commitTransaction()
          Commits and closes a transaction.
 int count(DBCriteria<?> criteria, Object... clazz)
          Returns the result set size of objects matching the specified criteria.
 int count(Object query)
          Returns the result set size of objects specified by a query or class name.
protected  int count(Persister persister, Variable search, DBCriteria<?>... criteria)
          Returns a meta element result set size for the specified persister and search variable.
 int count(String className, String attribute, Object value, String condition)
          Returns the result set size of objects of the given class having the specified attribute.
 int count(Variable search, DBCriteria<?>... criteria)
          Returns the result set size for the specified search variable.
protected  Variable createVariable(String type)
          Creates a variable MBean instance.
 boolean delete(Object object)
          Deletes an object.
 boolean deleteAll(DBCriteria<?> criteria)
          Deletes objects matching the specified criteria.
 boolean deleteAll(Object query)
          Deletes objects.
 boolean deleteAll(String className, String attribute, Object value, String 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.
 boolean exists(Object object)
          Checks an object.
 Object get(Object object)
          Gets an object.
 List<Object> getChain(Object node, String rel)
          Gets a chain of referenced objects in a tree, the end node at the lowest index.
 List<Object> 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 getConnectionAlias()
          Gets the connection alias of the current connection.
 DBCriteria<?> getCriteria(String className)
          Gets an empty criteria for the named class.
protected  StepFlowContext getCurrentContext()
          Gets the current step flow context.
 Object getIdValue(Object node)
          Gets the identity value.
 Object[] getIdValues(Object node)
          Gets the identity values.
 VariableAttributeInfo getInfo(Variable variable, String name)
          Gets nested attribute info in a tree.
protected  Persister getInternalPersister()
          Gets the internal persister with the current connection settings.
 Map<Object,Object> getMap(Object node, String rel)
          Gets a map of referenced objects in a tree.
 Map<Object,Object> getMap(Object node, String rel, String name)
          Gets a map of attribute values of referenced objects in a tree.
 Variable getMetaDesktop()
          Gets the meta desktop of the current principal.
 Variable getMetaFolder()
          Gets the meta folder of the current principal.
 Persister getPersister()
          Gets the persister with the current connection settings.
 Object getReference(Object node, int index, String rel)
          Gets the indexed referenced node in a tree.
 Object getReference(Object node, String rel)
          Gets the referenced node in a tree.
 List<Object> getReferences(Object node, String rel)
          Gets the referenced nodes in a tree.
protected  BeanRepositoryFilter getRepositoryFilter()
          Gets the bean repository filter from the filter stack.
 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<Object> getValues(Object node, String name)
          Gets a list of nested attribute values in a tree.
 VarHandler getVarHandler()
          Gets a var exchange handler.
 VarWriter getVarWriter()
          Gets a var exchange writer.
 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 isLocalized()
          Checks whether variables are localized.
 boolean isRelated(Object node, String rel, Object pk)
          Checks whether a node in a tree is related to the specified key.
 QueryIterator<?> iterator(DBCriteria<?> criteria, Object... clazz)
          Returns an iterator to a collection of objects matching the specified criteria.
 QueryIterator<?> iterator(Object query)
          Returns an iterator to a collection of objects specified by a query or sample.
protected  QueryIterator<? extends Variable> iterator(Persister persister, Variable search, DBCriteria<?>... criteria)
          Returns a meta element query iterator for the specified persister and search variable.
 QueryIterator<?> iterator(String className, String attribute, Object value, String condition)
          Returns an iterator to a collection of objects of the given class having the specified attribute.
 QueryIterator<? extends Variable> iterator(Variable search, DBCriteria<?>... criteria)
          Returns a variable query iterator for the specified search variable.
 Object merge(Object object)
          Merges an object.
 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(DBCriteria<?> criteria, Object... clazz)
          Queries objects of the given class matching the specified criteria.
 Collection<?> queryAll(Object query)
          Queries a collection of objects specified by a query or sample.
 Collection<?> queryAll(String className, String attribute, Object value, String condition)
          Queries 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 setConnectionAlias(String alias)
          Sets the connection alias of the current connection.
 void setIdValue(Object node, Object value)
          Sets the identity value.
 void setIdValues(Object node, Object[] values)
          Sets the identity values.
 void setValue(Object node, String name, Object value)
          Sets a nested attribute value in a tree.
 void setValue(Variable variable, String name, Object value)
          Sets a nested attribute value in a tree.
 boolean store(Object object)
          Stores an object.
 boolean storeAll(Collection<?> c)
          Stores objects.
 Identity toIdentity(String type, Object... pks)
          Returns the identity of the specified primary keys 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, create, disposed, getCharacterEncoding, getContext, getContextToolFilter, getDefaultLocale, getDescription, getDetail, getDetail, getEncodingSize, getEnumeration, getEnumeration, getFilter, getFilterChain, getFilterKey, getGroup, getInvalidation, getKeyValue, getKMLWriter, getLOBLinkPattern, getMBeanServer, getPrincipal, getQualifier, getRequest, getResourceMap, getResponse, getValue, getVariableRegistry, isBound, isDisposed, isFilterChanged, length, recycle, recycled, removeValue, removeValue, setValue, toString, toString, toStrings, toStrings, valueBound, valueUnbound
 
Methods inherited from class org.norther.tammi.core.rt.Introspector
clearResourceCache, contains, containsTrait, containsTrait, cutValue, exportTo, exportTo, getComparator, getConverter, getException, getFormat, getInfo, getInfos, getLocale, getMax, getMessage, getMeta, getMin, getNodeValue, getNodeValue, getPattern, getResourceBundle, getResourceBundle, getResourceBundleName, getResourceBundleName, importFrom, importFrom, isArray, isEnumerated, isInvalid, isLOB, isReadable, isTrait, isTrait, isVisible, isWritable, resolve, resolve, setCharacterEncoding, setLOBLinkPattern, setLocale, setTrait, setTrait, toMediaFile, toSerializable, toSerializables
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isLocalized

protected transient int isLocalized
The localized flag.

Constructor Detail

DataTool

public DataTool()
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

getConnectionAlias

public String getConnectionAlias()
Gets the connection alias of the current connection.

Returns:
the connection alias or null if not set.

setConnectionAlias

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

Parameters:
alias - the connection 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(String className)
Gets an empty criteria for the named class.

Parameters:
className - the criteria type.
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,
                             String type)
Builds a query by expression.

Parameters:
className - the class name to query.
expr - the query expression.
type - the query type.
Returns:
the query or null if failed.

buildQuery

public DBQuery<?> buildQuery(DBCriteria<?> criteria,
                             boolean distinct,
                             Object... clazz)
Builds a query by criteria.

Parameters:
criteria - the criteria to apply.
distinct - true if distinct, false otherwise.
clazz - an optional query class or class name.
Returns:
the query or null if failed.

buildQuery

public DBQuery<Object[]> buildQuery(DBCriteria<?> criteria,
                                    List<String> attributes,
                                    boolean distinct,
                                    Object... clazz)
Builds a query by criteria with attributes.

Parameters:
attributes - a list of attribute names.
criteria - the criteria to apply.
distinct - true if distinct, false otherwise.
clazz - an optional query class or class name.
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 sample.

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

queryAll

public Collection<?> queryAll(DBCriteria<?> criteria,
                              Object... clazz)
Queries objects of the given class matching the specified criteria.

Parameters:
criteria - implementation specific criteria.
clazz - an optional query class or class name.
Returns:
a collection of objects found.

queryAll

public Collection<?> queryAll(String className,
                              String attribute,
                              Object value,
                              String 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.

iterator

public QueryIterator<?> iterator(Object query)
Returns an iterator to a collection of objects specified by a query or sample.

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

iterator

public QueryIterator<?> iterator(DBCriteria<?> criteria,
                                 Object... clazz)
Returns an iterator to a collection of objects matching the specified criteria.

Parameters:
criteria - implementation specific criteria.
clazz - an optional query class or class name.
Returns:
an iterator to the collection of objects found.

iterator

public QueryIterator<?> iterator(String className,
                                 String attribute,
                                 Object value,
                                 String 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:
an iterator to the collection of objects found or null on error.

count

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

Parameters:
query - the query or class name of objects to return.
Returns:
the result set size.

count

public int count(DBCriteria<?> criteria,
                 Object... clazz)
Returns the result set size of objects matching the specified criteria.

Parameters:
criteria - implementation specific criteria.
clazz - an optional query class or class name.
Returns:
the result set size.

count

public int count(String className,
                 String attribute,
                 Object value,
                 String condition)
Returns the result set size 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 result set size.

exists

public boolean exists(Object object)
Checks an object.

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

get

public Object get(Object object)
Gets an object.

Parameters:
object - an object to get.
Returns:
the object if successful, null otherwise.

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.

merge

public Object merge(Object object)
Merges an object.

Parameters:
object - an object to merge.
Returns:
the merged object if successful, null 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(DBCriteria<?> criteria)
Deletes objects matching the specified criteria.

Parameters:
criteria - implementation specific criteria.
Returns:
true if successful, false otherwise.

deleteAll

public boolean deleteAll(String className,
                         String attribute,
                         Object value,
                         String 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.

iterator

public QueryIterator<? extends Variable> iterator(Variable search,
                                                  DBCriteria<?>... criteria)
Returns a variable query iterator for the specified search variable.

Parameters:
search - the search variable.
criteria - the initial criteria.
Returns:
the query iterator.

count

public int count(Variable search,
                 DBCriteria<?>... criteria)
Returns the result set size for the specified search variable.

Parameters:
search - the search variable.
criteria - the initial criteria.
Returns:
the result set size or -1 on error.

beginTransaction

public void beginTransaction()
Starts a transaction.


commitTransaction

public void commitTransaction()
Commits and closes a transaction.


abortTransaction

public void abortTransaction()
Aborts a transaction.


getIdValue

public Object getIdValue(Object node)
Gets the identity value.

Parameters:
node - the node object.
Returns:
the identity value or null.

setIdValue

public void setIdValue(Object node,
                       Object value)
Sets the identity value.

Parameters:
node - the node object.
value - the identity value.

getIdValues

public Object[] getIdValues(Object node)
Gets the identity values.

Parameters:
node - the node object.
Returns:
the identity values or null.

setIdValues

public void setIdValues(Object node,
                        Object[] values)
Sets the identity values.

Parameters:
node - the node object.
values - the identity values.

getInfo

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

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.

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.

getValues

public List<Object> 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<Object> 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.

getReference

public Object getReference(Object node,
                           String rel)
Gets the referenced node in a tree.

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

getReference

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

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

getReferences

public List<Object> getReferences(Object node,
                                  String rel)
Gets the referenced nodes in a tree.

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

isRelated

public boolean isRelated(Object node,
                         String rel,
                         Object pk)
Checks whether a node in a tree is related to the specified key.

Parameters:
node - the node object.
rel - the relation attribute.
pk - the primary key value.
Returns:
true for next, false otherwize.

hasNext

public boolean hasNext(Object node,
                       String rel)
Checks whether a node in a tree has a reference to the next one.

Parameters:
node - the node object.
rel - the relation attribute.
Returns:
true for next, false otherwize.

depth

public int depth(Object node,
                 String rel)
Returns the reference depth of a node.

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

getChain

public List<Object> getChain(Object node,
                             String rel)
Gets a chain of referenced objects in a tree, the end node at the lowest index.

Parameters:
node - the node variable.
rel - the relation attribute.
Returns:
the variable chain or null.

getMap

public Map<Object,Object> getMap(Object node,
                                 String rel)
Gets a map of referenced objects in a tree.

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

getChain

public List<Object> 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.

Parameters:
node - the node variable.
rel - the relation attribute.
name - the attribute name.
Returns:
the variable chain or null.

getMap

public Map<Object,Object> getMap(Object node,
                                 String rel,
                                 String name)
Gets a map of attribute values of referenced objects in a tree.

Parameters:
node - the node variable.
rel - the relation attribute.
name - the attribute name.
Returns:
the variable chain or null.

toIdentity

public Identity toIdentity(String type,
                           Object... pks)
Returns the identity of the specified primary keys and variable type.

Parameters:
type - the variable type.
pks - the primary key values.
Returns:
the identity.

toIdentity

public Identity toIdentity(Variable var)
Returns the identity of the specified variable.

Parameters:
var - the variable.
Returns:
the identity.

getMetaDesktop

public Variable getMetaDesktop()
Gets the meta desktop of the current principal.

Returns:
the meta desktop or null.

getMetaFolder

public Variable getMetaFolder()
Gets the meta folder of the current principal.

Returns:
the meta folder or null.

isLocalized

public boolean isLocalized()
Description copied from class: Introspector
Checks whether variables are localized.

Overrides:
isLocalized in class BeanTool
Returns:
true if localized, false otherwise.

getVarWriter

public VarWriter getVarWriter()
Description copied from class: BeanTool
Gets a var exchange writer.

Overrides:
getVarWriter in class BeanTool
Returns:
the var writer.

getVarHandler

public VarHandler getVarHandler()
Description copied from class: BeanTool
Gets a var exchange handler.

Overrides:
getVarHandler in class BeanTool
Returns:
the var handler.

createVariable

protected Variable createVariable(String type)
                           throws ConstructionException
Description copied from class: Introspector
Creates a variable MBean instance.

Overrides:
createVariable in class Introspector
Parameters:
type - the variable type.
Returns:
the created variable.
Throws:
ConstructionException - if construction fails.

getCurrentContext

protected StepFlowContext getCurrentContext()
Gets the current step flow context.

Returns:
the step flow context.

getRepositoryFilter

protected BeanRepositoryFilter getRepositoryFilter()
Gets the bean repository filter from the filter stack.

Returns:
the bean repository filter.

iterator

protected QueryIterator<? extends Variable> iterator(Persister persister,
                                                     Variable search,
                                                     DBCriteria<?>... criteria)
                                              throws AttributeNotFoundException,
                                                     PersistenceException
Returns a meta element query iterator for the specified persister and search variable.

Parameters:
persister - the persister.
search - the search variable.
criteria - the initial criteria.
Returns:
the query iterator.
Throws:
AttributeNotFoundException - for missing attributes.
PersistenceException - for persister errors.

count

protected int count(Persister persister,
                    Variable search,
                    DBCriteria<?>... criteria)
             throws AttributeNotFoundException,
                    PersistenceException
Returns a meta element result set size for the specified persister and search variable.

Parameters:
persister - the persister.
search - the search variable.
criteria - the initial criteria.
Returns:
the result set size.
Throws:
AttributeNotFoundException - for missing attributes.
PersistenceException - for persister errors.

closeInternalPersister

protected void closeInternalPersister()
Closes the internal persister.


getInternalPersister

protected Persister getInternalPersister()
                                  throws ConstructionException
Gets the internal persister with the current connection settings.

Returns:
the current persister.
Throws:
ConstructionException - if construction fails.


Copyright © 2004 The Norther Organization. All rights reserved.