public class SqlCursor extends Cursor
The sql statement can contain placeholder characters ? signifying a
parameter which can be set at runtime by calling addParameter(index, value). The index
corresponds with the count of the placeholder character in the SQL statement starting at 1
| Modifier and Type | Field and Description |
|---|---|
protected java.sql.Connection |
m_con |
protected Condition |
m_last |
protected java.sql.PreparedStatement |
m_prep |
protected org.brains2b.sql.meta.SelectDescriptor |
m_select |
m_prototype| Constructor and Description |
|---|
SqlCursor(java.sql.Connection con,
java.lang.String name,
java.lang.String sql)
Constructor for SqlCursor.
|
SqlCursor(java.lang.String name,
java.lang.String sql)
Constructor for SqlCursor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addParameter(int idx,
double d) |
void |
addParameter(int idx,
int i)
adds a integer value for the given placeholder position in the
prepared statement.
|
void |
addParameter(int idx,
long l) |
void |
addParameter(int idx,
java.lang.Object o)
adds a value for the given placeholder position in the
prepared statement.
|
int |
delete(CursorData cdata)
delete an object of type o from the datastore
|
java.sql.Connection |
getConnection()
return the
Connection used |
protected CursorData |
getObject(CursorData prototype,
java.sql.ResultSet rs)
get a CursorData object filled from the current position in the ResultSet.
|
java.util.ArrayList |
getParameters()
get a List of the parameter values which were added.
|
java.sql.PreparedStatement |
getPreparedStatement(java.sql.Connection con,
java.lang.String select)
returns a prepared statement build from
the prepared query set, the parameters added,
the conditions set and the order by supplied.
|
CursorData |
getProtoType()
get a prototype for this cursor, which is basically a defintion
of the columns and types, but without the values
|
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.
|
org.brains2b.sql.meta.SelectDescriptor |
getSelect()
return the
SelectDescriptor describing the select statement used for this Cursor |
int |
insert(CursorData cdata)
insert an object of type o to the datastore
|
int |
insert(CursorData cdata,
boolean skipNull)
insert the cursor data in the table for this cursor
|
void |
reset()
reset this Cursor by removing all previously set parameter values
|
CursorData |
retrieve(Condition con)
select an Object of the type of the
Object o which match the supplied
condition. |
java.util.List |
retrieveList()
retrieve a list of Objects of the type of the
Object |
java.util.List |
retrieveList(Condition condition)
retrieve a list of Objects of the type of the
Object o which match the supplied
condition. |
void |
setConnection(java.sql.Connection con)
set the
java.sql.Connection to use for this Cursor |
void |
setPageable(boolean b)
set the cursor to be pageable or not
|
java.lang.String |
toString()
Overwritten to return the SQL statement that defines the Cursor
|
int |
update(CursorData cdata)
update an object of type o to the datastore
|
getName, getNewCursorDataprotected org.brains2b.sql.meta.SelectDescriptor m_select
protected java.sql.PreparedStatement m_prep
protected java.sql.Connection m_con
protected Condition m_last
public SqlCursor(java.lang.String name,
java.lang.String sql)
name - String, the name of the cursorsql - String, the SQL-statement to use for this cursorpublic SqlCursor(java.sql.Connection con,
java.lang.String name,
java.lang.String sql)
Usually the Connection does not have to be set at initialization, you can use setConnection(Connection)
con - java.sql.Connection, the JDBC connection to use for this Cursorname - String, the name of the cursorsql - String, the SQL-statement to use for this cursorpublic CursorData retrieve(Condition con) throws DataException
CursorObject o which match the supplied
condition.retrieve in class Cursorcon - Condition the condition which should be met by the retrieved objectsDataException - exception thrown from the specific data store controls, such
as a JDBC driver are wrapped within this ExceptionDataController.retrieve(Object, Condition),
Conditionprotected CursorData getObject(CursorData prototype, java.sql.ResultSet rs) throws java.sql.SQLException
CursorgetObject in class Cursorprototype - CursorData, object which functions as a prototype, will be
cloned to function as return type.rs - ResultSet, a resultset with a valid positionjava.sql.SQLException - thrown if the resultset has no current position, or
if the database delivers an SQLExceptionpublic CursorData getProtoType() throws DataException
CursorgetProtoType in class CursorCursorDataDataExceptionpublic java.util.List retrieveList()
throws DataException
CursorObjectretrieveList in class CursorDataException - exception thrown from the specific data store controls, such
as a JDBC driver are wrapped within this Exceptionpublic java.util.List retrieveList(Condition condition) throws DataException
CursorObject o which match the supplied
condition.retrieveList in class Cursorcondition - Condition the condition which should be met by the retrieved objectsDataException - exception thrown from the specific data store controls, such
as a JDBC driver are wrapped within this ExceptionDataController.retrieveList(Object, Condition),
Conditionpublic int update(CursorData cdata) throws DataException
Cursorupdate in class Cursorcdata - CursorData, the object to updateDataException - exception thrown from the specific data store controls, such
as a JDBC driver are wrapped within this ExceptionDataController.update(Object)public int delete(CursorData cdata) throws DataException
Cursordelete in class Cursorcdata - CursorData, the object to deleteDataException - exception thrown from the specific data store controls, such
as a JDBC driver are wrapped within this ExceptionDataController.delete(Object)public int insert(CursorData cdata) throws DataException
Cursorinsert in class Cursorcdata - CursorData, the object to insertDataException - exception thrown from the specific data store controls, such
as a JDBC driver are wrapped within this ExceptionDataController.insert(Object)public int insert(CursorData cdata, boolean skipNull) throws DataException
cdata - CursorData, data to insertskipNull - Set to true to not attempt inserting null valuesDataExceptionpublic void addParameter(int idx,
int i)
idx - int, the placeholder positioni - int, The value to set in the prepared statementpublic void addParameter(int idx,
long l)
public void addParameter(int idx,
double d)
public void addParameter(int idx,
java.lang.Object o)
idx - int, the placeholder positiono - Object, the value to set in the prepared statement.public void reset()
addParameter(int, int),
addParameter(int, Object)public java.util.ArrayList getParameters()
throws java.sql.SQLException
The index of the list -1 corresponds to the index of the parameter added
java.sql.SQLExceptionaddParameter(int, int),
addParameter(int, Object)public java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con,
java.lang.String select)
throws java.sql.SQLException
If a prepared query has placeholders, the addParameters must be called for every placeholder supplied.
con - Connection, the connection for which to prepare the queryselect - String, the select containing the fields to retrieve and the table
This should be a valid ANSI-SQL `SELECT` statement without any conditions.
SQLException, - throws the Exception if generated by the prepareStatement
command in java.sql.Connection()java.sql.SQLExceptionConnection,
PreparedStatementpublic void setConnection(java.sql.Connection con)
java.sql.Connection to use for this Cursorcon - Connectionprotected CursorData getProtoType(java.sql.ResultSetMetaData rsMd) throws java.sql.SQLException
rsMd - java.sql.ResultSetMetaData, created on the basis of this cursor SQL-statementjava.sql.SQLException - thrown if the database delivers an SQLException.public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public java.sql.Connection getConnection()
Connection usedpublic org.brains2b.sql.meta.SelectDescriptor getSelect()
SelectDescriptor describing the select statement used for this Cursorpublic void setPageable(boolean b)
b -