org.persvr.datasource
Class DatabaseDataSource

java.lang.Object
  extended by org.persvr.datasource.BaseDataSource
      extended by org.persvr.datasource.DatabaseDataSource
All Implemented Interfaces:
DataSource
Direct Known Subclasses:
DatabaseTableDataSource, DynaObjectDBSource, DynaObjectDBSource

public abstract class DatabaseDataSource
extends BaseDataSource

Author:
Kris Zyp This provides a default starting implementation for JDBC database sources

Nested Class Summary
static interface DatabaseDataSource.DatabaseAction
           
 class DatabaseDataSource.QueryIterator
          This is a lazy loading iterator that will load results from a result set as needed.
static class DatabaseDataSource.ThreadSpecificConnectionObject
           
 
Field Summary
protected  java.lang.String connectionString
           
 
Fields inherited from class org.persvr.datasource.BaseDataSource
BINARY_HEADER, BOOLEAN_FALSE, BOOLEAN_TRUE, DATE_HEADER, DECIMAL_HEADER, DOUBLE_HEADER, FUNCTION_HEADER, INTEGER_HEADER, LINK_HEADER, LONG_HEADER, OBJECT_HEADER, REQUIRED_PREFIX, STRING_HEADER, UNDEFINED
 
Constructor Summary
DatabaseDataSource()
           
 
Method Summary
 void abortTransaction()
           
protected  java.lang.String addConditionToQuery(Node condition)
          Converts a JSONPath/JavaScript AST condition to SQL
 void commitTransaction()
           
protected  java.lang.String comparison(Node expression, Node valueNode, int conditionType)
           
protected  java.sql.Connection createConnection()
           
 long executeAndGetGeneratedKey(java.sql.PreparedStatement statement, java.lang.String tableName)
           
protected  DatabaseDataSource.ThreadSpecificConnectionObject getConnectionObject()
          This will return a thread specific connection object.
protected abstract  java.lang.Object getValueFromRs(java.sql.ResultSet rs)
          This gets the value/object for the current result set row
 void initParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)
          This is called on initialization and provides access to the data source configuration parameters
protected abstract  java.lang.String nameInQuery(java.lang.String name)
           
protected  java.lang.String numberComparisonInQuery(double number, java.lang.String operator)
           
protected  void runStarterStatements()
           
 void startTransaction()
           
protected  java.lang.String stringComparisonInQuery(java.lang.String str)
           
 void testLocks()
           
 java.lang.Object tryExecution(DatabaseDataSource.DatabaseAction action)
          This will attempt to perform the given action.
 
Methods inherited from class org.persvr.datasource.BaseDataSource
convertObjectToString, convertStringToObject, getId, hiddenId, idForString, initializeFromMap, setId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.persvr.datasource.DataSource
getFieldValue, mapObject, mapQuery
 

Field Detail

connectionString

protected java.lang.String connectionString
Constructor Detail

DatabaseDataSource

public DatabaseDataSource()
Method Detail

runStarterStatements

protected void runStarterStatements()
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

initParameters

public void initParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)
                    throws java.lang.Exception
Description copied from interface: DataSource
This is called on initialization and provides access to the data source configuration parameters

Throws:
java.lang.Exception

getConnectionObject

protected DatabaseDataSource.ThreadSpecificConnectionObject getConnectionObject()
This will return a thread specific connection object. It will create a new one if necessary

Returns:
Throws:
java.sql.SQLException

createConnection

protected java.sql.Connection createConnection()
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

tryExecution

public java.lang.Object tryExecution(DatabaseDataSource.DatabaseAction action)
                              throws java.sql.SQLException
This will attempt to perform the given action. If it fails, it will try to create a new connection and try again.

Parameters:
action -
Throws:
java.sql.SQLException

testLocks

public void testLocks()

executeAndGetGeneratedKey

public long executeAndGetGeneratedKey(java.sql.PreparedStatement statement,
                                      java.lang.String tableName)
                               throws java.sql.SQLException
Throws:
java.sql.SQLException

commitTransaction

public void commitTransaction()
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

startTransaction

public void startTransaction()
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

abortTransaction

public void abortTransaction()
                      throws java.sql.SQLException
Throws:
java.sql.SQLException

comparison

protected java.lang.String comparison(Node expression,
                                      Node valueNode,
                                      int conditionType)

nameInQuery

protected abstract java.lang.String nameInQuery(java.lang.String name)

numberComparisonInQuery

protected java.lang.String numberComparisonInQuery(double number,
                                                   java.lang.String operator)

stringComparisonInQuery

protected java.lang.String stringComparisonInQuery(java.lang.String str)

addConditionToQuery

protected java.lang.String addConditionToQuery(Node condition)
                                        throws java.sql.SQLException
Converts a JSONPath/JavaScript AST condition to SQL

Parameters:
condition -
Returns:
Throws:
java.sql.SQLException

getValueFromRs

protected abstract java.lang.Object getValueFromRs(java.sql.ResultSet rs)
                                            throws java.lang.Exception
This gets the value/object for the current result set row

Parameters:
rs -
Returns:
Throws:
java.lang.Exception