|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdesktop.dataset.DataCommand
org.jdesktop.dataset.provider.sql.AbstractSqlCommand
public abstract class AbstractSqlCommand
An AbstractSqlCommand is a DataCommand
meant to
be used with a SQLDataProvider
by defining
methods to generate a SELECT, INSERT, UPDATE or DELETE statement. How these
SQL statements are built is up to the concrete implementation of an
AbstractSqlCommand.
The methods for retrieving the SQL statements (as PreparedStatements) are all protected, meaning they can be accessed by subclasses as well as classes within this package. Thus, within the package, the AbstractSqlCommand defines an interface for preparing a PreparedStatement for consumers of the command.
An AbstractSqlCommand also defines methods to normalize SQL statements to make them easier to process using JDBC--namely, to convert between named- parameter style statements and index-based parameterized statements.
AbstractSqlCommand is useful in defining the structure of a concrete SQLCommand or TableCommand, and is not meant to be used on its own.
Constructor Summary | |
---|---|
AbstractSqlCommand()
|
Method Summary | |
---|---|
protected java.lang.String |
constructSql(java.lang.String sql,
java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> indexes)
Generates a new String for a SQL statement, replacing named parameters with ? symbols, as required by the Connection.prepareStatement(String) method. |
protected abstract java.sql.PreparedStatement |
getDeleteStatement(JDBCDataConnection conn,
DataRow row)
|
protected abstract java.sql.PreparedStatement |
getInsertStatement(JDBCDataConnection conn,
DataRow row)
|
java.lang.String[] |
getParameterNames(java.lang.String[] statements)
Searches the statements for param names, and returns the unique set of param names. |
protected abstract java.sql.PreparedStatement |
getSelectStatement(JDBCDataConnection conn)
|
protected abstract java.sql.PreparedStatement |
getUpdateStatement(JDBCDataConnection conn,
DataRow row)
|
protected java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.util.Map<java.lang.String,java.lang.Object> values,
JDBCDataConnection conn)
Creates a PreparedStatement from a SQL statement, setting parameter values using the supplied Map of parameter names to values. |
Methods inherited from class org.jdesktop.dataset.DataCommand |
---|
addPropertyChangeListener, addPropertyChangeListener, clearParameter, clearParameters, firePropertyChange, getParameter, getParameterNames, getParameterValues, getShortDescription, removePropertyChangeListener, setParameter, setShortDescription |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractSqlCommand()
Method Detail |
---|
protected abstract java.sql.PreparedStatement getSelectStatement(JDBCDataConnection conn) throws java.lang.Exception
conn
- An active JDBCDataConnection to use to prepare the statement
java.lang.Exception
protected abstract java.sql.PreparedStatement getInsertStatement(JDBCDataConnection conn, DataRow row) throws java.lang.Exception
conn
- An active JDBCDataConnection to use to prepare the statementrow
- The DataRow
that will be inserted
java.lang.Exception
protected abstract java.sql.PreparedStatement getUpdateStatement(JDBCDataConnection conn, DataRow row) throws java.lang.Exception
conn
- An active JDBCDataConnection to use to prepare the statementrow
- The DataRow
that will be updated
java.lang.Exception
protected abstract java.sql.PreparedStatement getDeleteStatement(JDBCDataConnection conn, DataRow row) throws java.lang.Exception
conn
- An active JDBCDataConnection to use to prepare the statementrow
- The DataRow
that will be deleted
java.lang.Exception
protected java.lang.String constructSql(java.lang.String sql, java.util.Map<java.lang.String,java.util.List<java.lang.Integer>> indexes)
Connection.prepareStatement(String)
method. The Map
parameter is populated with parameter names, mapped to a List
of indexes numbering that parameter within the SQL statement. Thus, as each
named parameter is replaced, we get a list of the position that parameter
had within the statement; the List of indexes can then be used on a call to
PreparedStatement.setObject(int, Object)
, using the index in the list
as the index parameter in setObject().
sql
- A SQL statement with 1 or more named parameters.indexes
- An empty Map which will be populated with a list of parameter
names, and the number of that parameter within the SQL statement.
protected java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.util.Map<java.lang.String,java.lang.Object> values, JDBCDataConnection conn) throws java.lang.Exception
sql
- A SQL statement, including named parameters if desired.values
- A Map of parameter names to Object values for the parameter--
the values used for each parameter when this statement is executed.conn
- An valid JDBCDataConnection.
java.lang.Exception
- if any error occurs during execution.public java.lang.String[] getParameterNames(java.lang.String[] statements)
statements
- An array of SQL statements, optionally with named
parameters embedded, in the form ":
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |