net.sf.xaj.jdbc
Class JdbcXmlDb

java.lang.Object
  extended by net.sf.xaj.core.AbstractDiscoverableXmlDb
      extended by net.sf.xaj.jdbc.JdbcXmlDb
All Implemented Interfaces:
DiscoverableXmlDb, XmlDb

public class JdbcXmlDb
extends AbstractDiscoverableXmlDb

Implementation of XmlDb for exectuing queries against a database via JDBC.

This implementation supports only the executeXQuery(net.sf.xaj.XmlDb.XQuerySearchCriteria) method. All others throw a UnsupportedOperationException.

The configurable properties of this class are:

jdbcTemplate
The JdbcTemplate from which to obtain JDBC connections from.
preparedStatementCreatorResolver
A PreparedStatementCreatorResolver implementation to resolve a PreparedStatementCreator from based on the passed in XmlDb.XQuerySearchCriteria.
createXmlResults
If true treat result rows as non XML results, and turn each result row into an XML element named after the xmlResultsRowElementName property. Otherwise, each row is assumed to return a single XML column.
xmlResultsRowElementName
When createXmlResults is true then use this value as the name of the XML element to create for each result row. Defaults to DEFAULT_XML_RESULTS_ROW_ELEMENT_NAME. Can be set on a per-query basis by providing a query variable on the key CRITERIA_XML_RESULTS_ELEMENT_NAME_KEY, in which case the results will not be treated as XML (even if createXmlResults is false) and each element will be named the value of this variable.

Version:
$Revision: 72 $ $Date: 2008-04-08 20:07:30 +1200 (Tue, 08 Apr 2008) $
Author:
matt

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.xaj.XmlDb
XmlDb.BatchTaskResult, XmlDb.SearchResultsMetadata, XmlDb.State, XmlDb.XQuerySearchCriteria, XmlDb.XQuerySearchResults
 
Field Summary
static java.lang.String CRITERIA_XML_RESULTS_ELEMENT_NAME_KEY
          A query criteria variable that should be used to dynamically assign a xmlResultsRowElementName value for the query.
static java.lang.String DEFAULT_XML_RESULTS_ROW_ELEMENT_NAME
          The default value for the xmlResultsRowElementName property.
 
Fields inherited from class net.sf.xaj.core.AbstractDiscoverableXmlDb
DEFAULT_SHUTDOWN_EXECUTOR_WAIT_SECS, log
 
Constructor Summary
JdbcXmlDb()
           
 
Method Summary
 boolean delete(java.io.Serializable id)
           
 java.lang.Integer deleteByXQuery(XmlDb.XQuerySearchCriteria criteria)
           
 XmlDb.XQuerySearchResults executeXQuery(XmlDb.XQuerySearchCriteria criteria)
           
 XmlResource get(java.io.Serializable id)
           
 org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
           
protected  org.springframework.jdbc.core.PreparedStatementCreator getPreparedStatementCreator(XmlDb.XQuerySearchCriteria searchCriteria)
          Get a PreparedStatementCreator instance to generate the SQL query to execute for the report.
 PreparedStatementCreatorResolver getPreparedStatementCreatorResolver()
           
protected  BasicBatchTransactionHolder getTransactionHolder()
           
protected  java.lang.Object getTransactionHolderKey()
           
 java.lang.String getXmlResultsRowElementName()
           
 boolean isCreateXmlResults()
           
 void setCreateXmlResults(boolean createXmlResults)
           
 void setJdbcTemplate(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
           
 void setPreparedStatementCreatorResolver(PreparedStatementCreatorResolver preparedStatementCreatorResolver)
           
 void setXmlResultsRowElementName(java.lang.String xmlResultsRowElementName)
           
 java.io.Serializable storeXml(XmlResource resource)
           
 
Methods inherited from class net.sf.xaj.core.AbstractDiscoverableXmlDb
close, doClose, doInit, getExecutor, getServiceKey, getShutdownExecutorWaitSecs, getState, getTransactionTemplate, getXmlDb, init, isShutdownExecutorServiceOnClose, processBatch, setExecutor, setServiceKey, setShutdownExecutorServiceOnClose, setShutdownExecutorWaitSecs, setTransactionTemplate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_XML_RESULTS_ROW_ELEMENT_NAME

public static final java.lang.String DEFAULT_XML_RESULTS_ROW_ELEMENT_NAME
The default value for the xmlResultsRowElementName property.

See Also:
Constant Field Values

CRITERIA_XML_RESULTS_ELEMENT_NAME_KEY

public static final java.lang.String CRITERIA_XML_RESULTS_ELEMENT_NAME_KEY
A query criteria variable that should be used to dynamically assign a xmlResultsRowElementName value for the query.

See Also:
Constant Field Values
Constructor Detail

JdbcXmlDb

public JdbcXmlDb()
Method Detail

executeXQuery

public XmlDb.XQuerySearchResults executeXQuery(XmlDb.XQuerySearchCriteria criteria)

getPreparedStatementCreator

protected org.springframework.jdbc.core.PreparedStatementCreator getPreparedStatementCreator(XmlDb.XQuerySearchCriteria searchCriteria)
Get a PreparedStatementCreator instance to generate the SQL query to execute for the report.

This default implementation simply calls PreparedStatementCreatorResolver#resolvePreparedStatementCreator() and returns the results.

Parameters:
searchCriteria - the search criteria
Returns:
the PreparedStatementCreator

getTransactionHolder

protected BasicBatchTransactionHolder getTransactionHolder()
Specified by:
getTransactionHolder in class AbstractDiscoverableXmlDb

getTransactionHolderKey

protected java.lang.Object getTransactionHolderKey()
Specified by:
getTransactionHolderKey in class AbstractDiscoverableXmlDb

delete

public boolean delete(java.io.Serializable id)

deleteByXQuery

public java.lang.Integer deleteByXQuery(XmlDb.XQuerySearchCriteria criteria)

get

public XmlResource get(java.io.Serializable id)

storeXml

public java.io.Serializable storeXml(XmlResource resource)

getJdbcTemplate

public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate()
Returns:
the jdbcTemplate

setJdbcTemplate

public void setJdbcTemplate(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
Parameters:
jdbcTemplate - the jdbcTemplate to set

getPreparedStatementCreatorResolver

public PreparedStatementCreatorResolver getPreparedStatementCreatorResolver()
Returns:
the preparedStatementCreatorResolver

setPreparedStatementCreatorResolver

public void setPreparedStatementCreatorResolver(PreparedStatementCreatorResolver preparedStatementCreatorResolver)
Parameters:
preparedStatementCreatorResolver - the preparedStatementCreatorResolver to set

isCreateXmlResults

public boolean isCreateXmlResults()
Returns:
the createXmlResults

setCreateXmlResults

public void setCreateXmlResults(boolean createXmlResults)
Parameters:
createXmlResults - the createXmlResults to set

getXmlResultsRowElementName

public java.lang.String getXmlResultsRowElementName()
Returns:
the xmlResultsRowElementName

setXmlResultsRowElementName

public void setXmlResultsRowElementName(java.lang.String xmlResultsRowElementName)
Parameters:
xmlResultsRowElementName - the xmlResultsRowElementName to set