org.brains2b.data.cursor
Class Cursor

java.lang.Object
  |
  +--org.brains2b.data.cursor.Cursor
Direct Known Subclasses:
OracleCursor

public class Cursor
extends java.lang.Object

Cursor is the Control class for a valid SQL select statement to be be used as a data class for which we can manipulate the data.

This includes inserting, deleting or selecting data, a bit like an Oracle Cursor.

Usage: Create a new Cursor object with a valid SQL connection and a String containing a valid SQL statement. Cursor c=new Cursor({Valid Connection},"A distinquising name", "SELECT NAME, DEPARTMENT FROM EMP,DEP WHERE NAME.DEP_ID=DEPARTMENT.ID"); After this a Select statement will return a CursorData object. See the javadoc for this object for more information. To get a new CursorData object use c.getNewCursorData()

Limitation: Updating and inserting will only proceed if the underlying database allows this particular operation for the particular query. Usually this only happens when all reference are explicit, all primary keys are set and all non-null values are filled. Cursor will pass the Exception thrown by the database through when there is a problem with mutating data.

Version:
0.2.1 [06-01-2004]
Author:
dennis@brains2b.nl
See Also:
CursorData

Field Summary
protected  java.sql.Connection m_con
           
protected  java.lang.String m_condition
           
protected  java.lang.String m_from
           
protected  java.lang.String m_groupBy
           
protected  java.sql.PreparedStatement m_prep
           
protected  java.lang.String m_select
           
 
Constructor Summary
Cursor()
          Deprecated. not used, use Cursor(Connection,String,String)
Cursor(java.sql.Connection con, java.lang.String name, java.lang.String sql)
          Default Constructor for Cursor
 
Method Summary
 int delete(CursorData cdata)
          Delete the data represented by the CursorData object from the database.
 CursorData getNewCursorData()
          Get an new CursorData object for this cursor, which has all the fields for this Cursor defined.
protected  CursorData getObject(CursorData prototype, java.sql.ResultSet rs)
          get a CursorData object filled from the current position in the ResultSet.
protected  CursorData getProtoType(java.sql.ResultSetMetaData rsMd)
          get a prototype on the basis of the SQL-statement for this Cursor, which is defined in the ResultSetMetaData.
 java.util.Vector select()
          Perform a select on the basis of the sql statement defined by this Cursor
 java.util.Vector select(Condition con)
          Deprecated. use select()
 java.util.Vector select(Condition con, boolean fieldsOnly)
          Deprecated. use select()
 java.lang.String toString()
          Overwritten to return the SQL statement that defines the Cursor
 int update(CursorData cdata)
          Update the data represented by the CursorData object from the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_condition

protected java.lang.String m_condition

m_groupBy

protected java.lang.String m_groupBy

m_from

protected java.lang.String m_from

m_select

protected java.lang.String m_select

m_prep

protected java.sql.PreparedStatement m_prep

m_con

protected java.sql.Connection m_con
Constructor Detail

Cursor

public Cursor()
Deprecated. not used, use Cursor(Connection,String,String)

Constructor for Cursor.


Cursor

public Cursor(java.sql.Connection con,
              java.lang.String name,
              java.lang.String sql)
Default Constructor for Cursor

Parameters:
con - java.sql.Connection, a valid non-closed Connection
name - String, a distinct name for this Cursor
sql - String, a valid ANSI Sql string
Method Detail

delete

public int delete(CursorData cdata)
           throws java.lang.Exception
Delete the data represented by the CursorData object from the database.

Parameters:
cdata - CursorData, an object containing the results for the cursor
Returns:
int, the number of records affected by this delete command, should always be 1
Throws:
Exception, - thrown if the database delivers an Exception.
java.lang.Exception

select

public java.util.Vector select(Condition con)
                        throws java.lang.Exception
Deprecated. use select()

Perform a select on the basis of the sql statement defined by this Cursor

Parameters:
con - org.brains2b.sql.Condition, does not do anything.
Returns:
a Vector containing CursorData returned by the select statement
Throws:
java.lang.Exception - thrown if the database delivers an Exception

select

public java.util.Vector select(Condition con,
                               boolean fieldsOnly)
                        throws java.lang.Exception
Deprecated. use select()

Perform a select on the basis of the sql statement defined by this Cursor

Parameters:
con - org.brains2b.sql.Condition, does not do anything.
fieldsOnly - boolean, ignore the conditions to return all fields
Returns:
java.util.Vector containing CursorData returned by the select statement
Throws:
java.lang.Exception - thrown if the database delivers an Exception

select

public java.util.Vector select()
                        throws java.lang.Exception
Perform a select on the basis of the sql statement defined by this Cursor

Returns:
java.util.Vector containing CursorData returned by the select statement
Throws:
java.lang.Exception - thrown if the database delivers an Exception

update

public int update(CursorData cdata)
           throws java.lang.Exception
Update the data represented by the CursorData object from the database.

Parameters:
cdata - CursorData, an object containing the results for the cursor
Returns:
int, the number of records affected by this update command, should always be 1
Throws:
Exception, - thrown if the database delivers an Exception.
java.lang.Exception

toString

public java.lang.String toString()
Overwritten to return the SQL statement that defines the Cursor

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getNewCursorData

public CursorData getNewCursorData()
Get an new CursorData object for this cursor, which has all the fields for this Cursor defined.

Returns:
CursorData, a new CursorData object which is basically a prototype retrieved from the database. Will return null if the underlying prototype cannot be returned, or if the database throws an Exception.

getProtoType

protected CursorData getProtoType(java.sql.ResultSetMetaData rsMd)
                           throws java.sql.SQLException
get a prototype on the basis of the SQL-statement for this Cursor, which is defined in the ResultSetMetaData.

Parameters:
rsMd - java.sql.ResultSetMetaData, created on the basis of this cursor SQL-statement
Returns:
CursorData, with all the fields defined but no values.
Throws:
SQLException, - thrown if the database delivers an SQLException.
java.sql.SQLException

getObject

protected CursorData getObject(CursorData prototype,
                               java.sql.ResultSet rs)
                        throws java.sql.SQLException
get a CursorData object filled from the current position in the ResultSet.

Parameters:
prototype - CursorData, object which functions as a prototype, will be cloned to function as return type.
rs - ResultSet, a resultset with a valid position
Returns:
CursorData, an object with all fields and values set.
Throws:
SQLException, - thrown if the resultset has no current position, or if the database delivers an SQLException
java.sql.SQLException