|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry.contrib.jdbc.StatementAssembly
public class StatementAssembly
Class for creating and executing JDBC statements. Allows statements to be assembled
incrementally (like a StringBuffer
), but also tracks parameters, shielding
the developer from the differences between constructing and
using a JDBC
Statement
and
a JDBC PreparedStatement
. This class is somewhat skewed towards
Oracle, which works more efficiently with prepared staments than
simple SQL.
In addition, implements toString()
in a useful way (you can see the
SQL and parameters), which is invaluable when debugging.
addParameter(int)
(and all overloaded versions of it for scalar types)
adds a "?" to the statement and records the parameter value.
addParameter(Integer)
(and all overloaded version of it for wrapper
types) does the same ... unless the value is null, in which case "NULL" is
inserted into the statement.
addParameterList(int[], String)
(and all overloaded versions of it)
simply invokes the appropriate addParameter(int)
, adding the
separator in between parameters.
Field Summary | |
---|---|
static String |
SEP
|
Constructor Summary | |
---|---|
StatementAssembly()
Default constructor; uses a maximum line length of 80 and an indent of 5. |
|
StatementAssembly(int maxLineLength,
int indent)
|
Method Summary | |
---|---|
void |
add(double value)
|
void |
add(float value)
|
void |
add(int value)
|
void |
add(long value)
|
void |
add(short value)
|
void |
add(String text)
Adds text to the current line, unless that would make the line too long, in which case a new line is started (and indented) before adding the text. |
void |
addList(String[] items,
String separator)
|
void |
addParameter(boolean value)
|
void |
addParameter(Boolean value)
|
void |
addParameter(Date date)
Adds a date value to a StatementAssembly converting
it to a Timestamp first. |
void |
addParameter(double value)
|
void |
addParameter(Double value)
|
void |
addParameter(float value)
|
void |
addParameter(Float value)
|
void |
addParameter(int value)
|
void |
addParameter(Integer value)
|
void |
addParameter(long value)
|
void |
addParameter(Long value)
|
void |
addParameter(Object value)
|
void |
addParameter(short value)
|
void |
addParameter(Short value)
|
void |
addParameter(String value)
|
void |
addParameter(Timestamp timestamp)
|
void |
addParameterList(double[] items,
String separator)
|
void |
addParameterList(int[] items,
String separator)
|
void |
addParameterList(Integer[] items,
String separator)
|
void |
addParameterList(long[] items,
String separator)
|
void |
addParameterList(Long[] items,
String separator)
|
void |
addParameterList(String[] items,
String separator)
|
void |
addSep(String text)
Adds a separator (usually a comma and a space) to the current line, regardless of line length. |
void |
clear()
Clears the assembly, preparing it for re-use. |
IStatement |
createStatement(Connection connection)
Creates and returns an IStatement based on the SQL and parameters
acquired. |
int |
getIndent()
Number of spaces to indent continuation lines by. |
int |
getMaxLineLength()
Maximum length of a line. |
void |
newLine()
Starts a new line, without indenting. |
void |
newLine(String text)
Starts a new line, then adds the given text. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String SEP
Constructor Detail |
---|
public StatementAssembly()
public StatementAssembly(int maxLineLength, int indent)
Method Detail |
---|
public void clear()
public int getMaxLineLength()
public int getIndent()
public void add(String text)
Text is added as-is, with no concept of quoting. To add arbitrary strings
(such as in a where clause), use addParameter(String)
.
public void add(short value)
public void add(int value)
public void add(long value)
public void add(float value)
public void add(double value)
public void addParameter(Date date)
StatementAssembly
converting
it to a Timestamp
first.
public void addSep(String text)
public void newLine()
public void newLine(String text)
public void addList(String[] items, String separator)
public void addParameterList(int[] items, String separator)
public void addParameterList(Integer[] items, String separator)
public void addParameterList(long[] items, String separator)
public void addParameterList(Long[] items, String separator)
public void addParameterList(String[] items, String separator)
public void addParameterList(double[] items, String separator)
public void addParameter(Object value)
public void addParameter(Timestamp timestamp)
public void addParameter(String value)
public void addParameter(int value)
public void addParameter(Integer value)
public void addParameter(long value)
public void addParameter(Long value)
public void addParameter(float value)
public void addParameter(Float value)
public void addParameter(double value)
public void addParameter(Double value)
public void addParameter(short value)
public void addParameter(Short value)
public void addParameter(boolean value)
public void addParameter(Boolean value)
public IStatement createStatement(Connection connection) throws SQLException
IStatement
based on the SQL and parameters
acquired.
SQLException
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |