com.syncsoft.plainsql
Class PlainSql

java.lang.Object
  extended by com.syncsoft.plainsql.PlainSql
Direct Known Subclasses:
PlainProc, PlainTable

public class PlainSql
extends java.lang.Object

This class supports SQL statement objects. The underlying object is a JDBC PreparedStatement. The PSConnection class and other classes in this package rely on PoSQL for mostactivities.


Constructor Summary
PlainSql(PSconnection conn, java.lang.String sql)
          Constructor to create a SQL statement object from a SQL string
 
Method Summary
 int bindArgs(java.lang.Object... args)
          Bind the provided array of arguments to the statement
 void close()
          Closes the statement and releases the cursor and resources This _might_ not totally close the statement if statement caching is enabled (eg, might just move the statement to the cache)
 int colcount()
          Number of columns in the current result set
 boolean execute()
          Execute the current SQL statement.
 boolean execute(java.lang.Object... args)
          Execute a result set, accepting bind variables as arguments
 void executeBatch()
          Call the JDBC executeBatch() call to apply a batch of data
 int executeUpdate()
          Call executeUpdate() to execute a SQL with no results
 int executeUpdate(java.lang.Object[] args)
          Same as executeUpdate(), but accepts a list of bind variables
 RowSet fetchAll(java.lang.Object... args)
          Returns all the result sets for a query as an ArrayList of Maps.
 Row fetchOne()
          Return the current row from the current result set as a Row object
 java.util.List getColNames()
          Returns a List of column names for the current result set.
 int getFetchahead()
          Get the fetchahead value associated with this statement
 java.sql.Connection getJdbcConnection()
          Get the JDBC connection associated with this statement
 java.sql.PreparedStatement getJdbcStatement()
          Get the PreparedStatement object associated with this statement.
 PSconnection getPsConnection()
          Get the PlainSQL connection associated with this statement.
 java.sql.ResultSet getResult()
          Get the JDBC ResultSet object associated with this statement
 java.sql.ResultSetMetaData getRsMetaData()
          Get the ResultSetMetaData object associated with this statement
 java.lang.String getSql()
          Get the SQL text associated with this statement
 Row makeRow(java.sql.ResultSet rs)
          Return a row object for the current row in a result set
 boolean nextRow()
          Move to next row in the result set
 void setFetchAhead(int fetchahead)
          Set the fetchahead (pre-fetch) value for this statement
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainSql

public PlainSql(PSconnection conn,
                java.lang.String sql)
         throws java.sql.SQLException
Constructor to create a SQL statement object from a SQL string

Parameters:
conn - : JDBC Connection object
sql - : SQL for the statement
Throws:
java.sql.SQLException
Method Detail

bindArgs

public int bindArgs(java.lang.Object... args)
             throws java.sql.SQLException
Bind the provided array of arguments to the statement

Parameters:
args -
Returns:
number of args
Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Closes the statement and releases the cursor and resources This _might_ not totally close the statement if statement caching is enabled (eg, might just move the statement to the cache)

Throws:
java.sql.SQLException

colcount

public int colcount()
             throws java.sql.SQLException
Number of columns in the current result set

Returns:
Number of columns
Throws:
java.sql.SQLException

execute

public boolean execute()
                throws java.sql.SQLException
Execute the current SQL statement. This version of execute accepts no bind variables.

Returns:
true if there is a result set, false otherwise
Throws:
java.sql.SQLException

execute

public boolean execute(java.lang.Object... args)
                throws java.sql.SQLException
Execute a result set, accepting bind variables as arguments

Parameters:
args - array of arguments
Returns:
true if there is a result set, false otherwise
Throws:
java.sql.SQLException

executeBatch

public void executeBatch()
                  throws java.sql.SQLException
Call the JDBC executeBatch() call to apply a batch of data

Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate()
                  throws java.sql.SQLException
Call executeUpdate() to execute a SQL with no results

Returns:
number of rows affected by the statement
Throws:
java.sql.SQLException

executeUpdate

public int executeUpdate(java.lang.Object[] args)
                  throws java.sql.SQLException
Same as executeUpdate(), but accepts a list of bind variables

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

fetchAll

public RowSet fetchAll(java.lang.Object... args)
                throws java.sql.SQLException
Returns all the result sets for a query as an ArrayList of Maps. If the result set is really big you could create a memory/response time issue; for non-trivial result sets use fetchone(). This version allows you to provide an array of bind variables AND therefore the SQL has to be re-executed

Returns:
An ArrayList (rows) of Map objects (columns)
Throws:
java.sql.SQLException

fetchOne

public Row fetchOne()
             throws java.sql.SQLException
Return the current row from the current result set as a Row object

Returns:
HashMap containing the current row
Throws:
java.sql.SQLException

makeRow

public Row makeRow(java.sql.ResultSet rs)
            throws java.sql.SQLException
Return a row object for the current row in a result set

Parameters:
rs - : A result set
Returns:
: A row object for the current row of the result set
Throws:
java.sql.SQLException

getColNames

public java.util.List getColNames()
                           throws java.sql.SQLException
Returns a List of column names for the current result set.

Returns:
List of column names
Throws:
java.sql.SQLException

getFetchahead

public int getFetchahead()
Get the fetchahead value associated with this statement

Returns:
fetchahead value

getJdbcConnection

public java.sql.Connection getJdbcConnection()
Get the JDBC connection associated with this statement

Returns:
The JDBC connection

getJdbcStatement

public java.sql.PreparedStatement getJdbcStatement()
Get the PreparedStatement object associated with this statement.

Returns:
JDBC PreparedStatement object

getPsConnection

public PSconnection getPsConnection()
Get the PlainSQL connection associated with this statement.

Returns:
PS Connection

getResult

public java.sql.ResultSet getResult()
Get the JDBC ResultSet object associated with this statement

Returns:
JDBC ResultSet object

getRsMetaData

public java.sql.ResultSetMetaData getRsMetaData()
Get the ResultSetMetaData object associated with this statement

Returns:
ResultSetMetaData object

getSql

public java.lang.String getSql()
Get the SQL text associated with this statement

Returns:
SQL text

nextRow

public boolean nextRow()
                throws java.sql.SQLException
Move to next row in the result set

Returns:
true if there is another row, false otherwise
Throws:
java.sql.SQLException

setFetchAhead

public void setFetchAhead(int fetchahead)
                   throws java.sql.SQLException
Set the fetchahead (pre-fetch) value for this statement

Parameters:
fetchahead -
Throws:
java.sql.SQLException