|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.brains2b.data.cursor.Cursor
org.brains2b.data.sql.cursor.SqlCursor
public class SqlCursor
Implementation of the Cursor object for Sql queries and add functionality for having queries with parameters.
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
Field Summary | |
---|---|
protected java.sql.Connection |
m_con
|
protected java.sql.PreparedStatement |
m_prep
|
protected org.brains2b.sql.meta.SelectDescriptor |
m_select
|
Fields inherited from class org.brains2b.data.cursor.Cursor |
---|
m_prototype |
Constructor Summary | |
---|---|
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 |
Method Summary | |
---|---|
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()
|
protected CursorData |
getObject(CursorData prototype,
java.sql.ResultSet rs)
get a CursorData object filled from the current position in the ResultSet. |
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()
|
int |
insert(CursorData cdata)
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 |
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 |
Methods inherited from class org.brains2b.data.cursor.Cursor |
---|
getName, getNewCursorData |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected org.brains2b.sql.meta.SelectDescriptor m_select
protected java.sql.PreparedStatement m_prep
protected java.sql.Connection m_con
Constructor Detail |
---|
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 cursorMethod Detail |
---|
public CursorData retrieve(Condition con) throws DataException
Cursor
Object
o which match the supplied
condition.
retrieve
in class Cursor
con
- Condition the condition which should be met by the retrieved objects
DataException
DataController.retrieve(Object, Condition)
,
Condition
protected CursorData getObject(CursorData prototype, java.sql.ResultSet rs) throws java.sql.SQLException
Cursor
getObject
in class Cursor
prototype
- CursorData, object which functions as a prototype, will be
cloned to function as return type.rs
- ResultSet, a resultset with a valid position
java.sql.SQLException
public CursorData getProtoType() throws DataException
Cursor
getProtoType
in class Cursor
CursorData
DataException
public java.util.List retrieveList() throws DataException
Cursor
Object
retrieveList
in class Cursor
DataException
public java.util.List retrieveList(Condition condition) throws DataException
Cursor
Object
o which match the supplied
condition.
retrieveList
in class Cursor
condition
- Condition the condition which should be met by the retrieved objects
DataException
DataController.retrieveList(Object, Condition)
,
Condition
public int update(CursorData cdata) throws DataException
Cursor
update
in class Cursor
cdata
- CursorData, the object to update
DataException
DataController.update(Object)
public int delete(CursorData cdata) throws DataException
Cursor
delete
in class Cursor
cdata
- CursorData, the object to delete
DataException
DataController.delete(Object)
public int insert(CursorData cdata) throws DataException
insert
in class Cursor
cdata
- CursorData, data to insert
java.lang.Exception
DataException
DataController.insert(Object)
public 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.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.SQLException
Connection
,
PreparedStatement
public void setConnection(java.sql.Connection con)
java.sql.Connection
to use for this Cursor
con
- Connection
protected CursorData getProtoType(java.sql.ResultSetMetaData rsMd) throws java.sql.SQLException
rsMd
- java.sql.ResultSetMetaData, created on the basis of this cursor SQL-statement
SQLException,
- thrown if the database delivers an SQLException.
java.sql.SQLException
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public java.sql.Connection getConnection()
public org.brains2b.sql.meta.SelectDescriptor getSelect()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |