com.syncsoft.plainsql
Class PSconnection

java.lang.Object
  extended by com.syncsoft.plainsql.PSconnection

public class PSconnection
extends java.lang.Object

Wrapper to the JDBC connection class. Provides simple methods for executing statements, and creating dedicated SQL or table objects. The connection is associated with a statement cache, which allows SQL to be executed directly by connection methods without causing excessive parse requests. Jan 13 GH


Field Summary
 java.sql.DatabaseMetaData dbMetaData
           
 
Constructor Summary
PSconnection(java.sql.Connection jdbcConnection)
          Create a conneciton object, supplying a JDBC connection.
 
Method Summary
 void close()
          Close the connection.
 void commit()
          Issue a COMMIT.
 PlainProc createProc(java.lang.String sql)
          Create a stored procedure object
 PSsequence createSequence(java.lang.String sequenceName)
          Returns an object that can be used to generate "portable" sequences
 PlainSql createSql(java.lang.String sql)
          Create a SQL object (wrapper to a preparedStatemetn).
 PlainSql createSql(java.lang.String fileName, java.lang.String sqlName)
           
 PlainTable createTable(java.lang.String tablename)
          Create a table object which is like a PlainSQL object for a SELECT * FROM table but also has some methods for easy DML
 PlainTable createTable(java.lang.String tablename, java.lang.String additionalSQL)
          Create a table object which is like a PlainSQL object for a SELECT * FROM table but also has some methods for easy DML
 PlainTableDDL createTableDDL(java.lang.String tablename)
          Create a table DDL object which is used to create table, indexes & such in a way that is a bit easier and portable than building up SQL text
 int doSql(java.lang.String sql, java.lang.Object... args)
          Execute a non-query with bind variables.
 ProcedureResult executeProc(java.lang.String procName, java.lang.Object... procArguments)
          Execute a stored procedure, returning a structure that contains the output parameters and the result sets
 RowSet fetchAll(java.lang.String sql, java.lang.Object... args)
          Execute the SQL, with bind variables as appropriate, and return a Rowset of data
 int getFetchahead()
           
 java.sql.Connection getJdbcConnection()
          Return the JDBC connection used by the PSconnection
 java.util.logging.Logger getLogger()
          Retrieves the Logger object associated with the connection
 java.lang.String getRdbmsName()
          Return the RDBMS product name as returned by DatabaseMetaData.getProductName()
 StmtCache getStmtcache()
          Get the statement cache object for this connection
 PlainTable getTable(java.lang.String tablename)
          Create a "table" DML object
 java.sql.Date javaSqlDateNow()
           
 void rollback()
           
 void setFetchahead(int fetchahead)
          Set the fetchahead value that will be applied to all statements created by this connection.
 void setLogLevel(java.util.logging.Level l)
          Set the logger level TODO: DOESN"T WORK!!!!!!!
 boolean tableExists(java.lang.String tablename)
          Check to see if there is a table that can be queried with the given name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbMetaData

public java.sql.DatabaseMetaData dbMetaData
Constructor Detail

PSconnection

public PSconnection(java.sql.Connection jdbcConnection)
             throws java.sql.SQLException
Create a conneciton object, supplying a JDBC connection.

Parameters:
jdbcConnection -
Throws:
java.sql.SQLException
Method Detail

javaSqlDateNow

public java.sql.Date javaSqlDateNow()

executeProc

public ProcedureResult executeProc(java.lang.String procName,
                                   java.lang.Object... procArguments)
                            throws java.sql.SQLException
Execute a stored procedure, returning a structure that contains the output parameters and the result sets

Parameters:
procName - - name of the procedure (Not including CALL)
procArguments - : Array of procedure arguments
Returns:
ProcResults object
Throws:
java.sql.SQLException

getRdbmsName

public java.lang.String getRdbmsName()
Return the RDBMS product name as returned by DatabaseMetaData.getProductName()

Returns:
the RDBMS name (Oracle, etc)

close

public void close()
           throws java.sql.SQLException
Close the connection.

Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Issue a COMMIT.

Throws:
java.sql.SQLException

createProc

public PlainProc createProc(java.lang.String sql)
                     throws java.sql.SQLException
Create a stored procedure object

Parameters:
sql - - eg "{CALL proc()}"
Returns:
PlainProc object
Throws:
java.sql.SQLException

createSequence

public PSsequence createSequence(java.lang.String sequenceName)
                          throws java.sql.SQLException
Returns an object that can be used to generate "portable" sequences

Parameters:
sequenceName -
Returns:
sequence object
Throws:
java.sql.SQLException

createSql

public PlainSql createSql(java.lang.String sql)
                   throws java.sql.SQLException
Create a SQL object (wrapper to a preparedStatemetn).

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

createSql

public PlainSql createSql(java.lang.String fileName,
                          java.lang.String sqlName)
                   throws java.sql.SQLException,
                          java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

createTable

public PlainTable createTable(java.lang.String tablename)
                       throws java.sql.SQLException
Create a table object which is like a PlainSQL object for a SELECT * FROM table but also has some methods for easy DML

Parameters:
conn - - PSconnection object
tablename -
Returns:
PlainTable object
Throws:
java.sql.SQLException

createTable

public PlainTable createTable(java.lang.String tablename,
                              java.lang.String additionalSQL)
                       throws java.sql.SQLException
Create a table object which is like a PlainSQL object for a SELECT * FROM table but also has some methods for easy DML

Parameters:
conn - - PSconnection object
tablename -
additionalSQL - Additional SQL clauses (usually a restricting where clause)
Returns:
PlainTable object
Throws:
java.sql.SQLException

createTableDDL

public PlainTableDDL createTableDDL(java.lang.String tablename)
                             throws java.sql.SQLException
Create a table DDL object which is used to create table, indexes & such in a way that is a bit easier and portable than building up SQL text

Parameters:
conn - - PSconnection object
tablename -
Returns:
PlainTable object
Throws:
java.sql.SQLException

doSql

public int doSql(java.lang.String sql,
                 java.lang.Object... args)
          throws java.sql.SQLException
Execute a non-query with bind variables. Since there are bind variables we assume possible re-use so create a prepared statement and possible re-use

Parameters:
sql -
args - array of bind variables
Returns:
number of rows affected
Throws:
java.sql.SQLException

fetchAll

public RowSet fetchAll(java.lang.String sql,
                       java.lang.Object... args)
                throws java.sql.SQLException
Execute the SQL, with bind variables as appropriate, and return a Rowset of data

Parameters:
sql - SQL to be executed
args - array of bind variables
Returns:
RowSet of data
Throws:
java.sql.SQLException

getFetchahead

public int getFetchahead()
Returns:
Fetchahead value for this connection

getJdbcConnection

public java.sql.Connection getJdbcConnection()
Return the JDBC connection used by the PSconnection

Returns:
JDBC connection

getLogger

public java.util.logging.Logger getLogger()
Retrieves the Logger object associated with the connection

Returns:
The Logger object

getStmtcache

public StmtCache getStmtcache()
Get the statement cache object for this connection

Returns:
Statement cache object

getTable

public PlainTable getTable(java.lang.String tablename)
                    throws java.sql.SQLException
Create a "table" DML object

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

rollback

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

setFetchahead

public void setFetchahead(int fetchahead)
Set the fetchahead value that will be applied to all statements created by this connection. This determines the number of rows pre-fetched in each database operation

Parameters:
fetchahead -

setLogLevel

public void setLogLevel(java.util.logging.Level l)
Set the logger level TODO: DOESN"T WORK!!!!!!!

Parameters:
l -

tableExists

public boolean tableExists(java.lang.String tablename)
Check to see if there is a table that can be queried with the given name.

Parameters:
tablename -
Returns: