org.jdesktop.dataset.provider.sql
Class SQLCommand
java.lang.Object
org.jdesktop.dataset.DataCommand
org.jdesktop.dataset.provider.sql.AbstractSqlCommand
org.jdesktop.dataset.provider.sql.SQLCommand
- Direct Known Subclasses:
- TableCommand
public class SQLCommand
- extends AbstractSqlCommand
A fully customizeable DataCommand for use with a SQLDataProvider
. This
DataCommand requires the user to specify their select, insert, update and
delete sql statements manually using setSelectSQL(String)
,
setInsertSQL(String)
, setUpdateSQL(String)
,
setDeleteSQL(String)
.
The SQL for these statements can
contain named parameters. As a DataCommand, the SQLCommand can track values for named
parameters (DataCommand.setParameter(String, Object)
, so that when the
SQLDataProvider requests the PreparedStatement to execute, the parameters in the SQL
statement are assigned the values stored in the DataCommand. For example, suppose your
SQLCommand instance was only to work with a row in the Employee table for "Jones". You'd
do the following:
SQLCommand cmd = new SQLCommand();
cmd.setSelectSql("Select * from Employee where name = :emp-name");
cmd.setParameter("emp-name", "Jones");
The INSERT, UPDATE, and DELETE statements can access any of the parameters defined in this
DataCommand as well.
A subclass, TableCommand
allows you to specify a simplified set of criteria to base your query on. You may,
for instance, simply specify the name of the table and the select, insert, update and delete queries
will be automatically generated for you. You may override the delete, insert, select and
update SQL statements in the TableCommand.
- Author:
- rbair
Constructor Summary |
SQLCommand()
Creates a new instance of TableCommand |
Methods inherited from class org.jdesktop.dataset.DataCommand |
addPropertyChangeListener, addPropertyChangeListener, clearParameter, clearParameters, firePropertyChange, getParameter, getParameterValues, getShortDescription, removePropertyChangeListener, setParameter, setShortDescription |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SQLCommand
public SQLCommand()
- Creates a new instance of TableCommand
setSelectSQL
public void setSelectSQL(java.lang.String sql)
getSelectSQL
public java.lang.String getSelectSQL()
setUpdateSQL
public void setUpdateSQL(java.lang.String sql)
getUpdateSQL
public java.lang.String getUpdateSQL()
setInsertSQL
public void setInsertSQL(java.lang.String sql)
getInsertSQL
public java.lang.String getInsertSQL()
setDeleteSQL
public void setDeleteSQL(java.lang.String sql)
getDeleteSQL
public java.lang.String getDeleteSQL()
getParameterNames
public java.lang.String[] getParameterNames()
- Description copied from class:
DataCommand
- Returns an array containing all of the parameter names for this DataCommand
- Specified by:
getParameterNames
in class DataCommand
- Returns:
- an array of the parameter names for this DataCommand
createPreparedStatement
protected java.sql.PreparedStatement createPreparedStatement(java.lang.String parameterizedSql,
JDBCDataConnection conn)
throws java.lang.Exception
- Throws:
java.lang.Exception
getSelectStatement
protected java.sql.PreparedStatement getSelectStatement(JDBCDataConnection conn)
throws java.lang.Exception
- Specified by:
getSelectStatement
in class AbstractSqlCommand
- Parameters:
conn
- An active JDBCDataConnection to use to prepare the statement
- Returns:
- A PreparedStatement, ready to execute, for the SELECT SQL statement.
- Throws:
java.lang.Exception
getUpdateStatement
protected java.sql.PreparedStatement getUpdateStatement(JDBCDataConnection conn,
DataRow row)
throws java.lang.Exception
- Specified by:
getUpdateStatement
in class AbstractSqlCommand
- Parameters:
conn
- An active JDBCDataConnection to use to prepare the statementrow
- The DataRow
that will be updated
- Returns:
- A PreparedStatement, ready to execute, for the UPDATE SQL statement.
- Throws:
java.lang.Exception
getInsertStatement
protected java.sql.PreparedStatement getInsertStatement(JDBCDataConnection conn,
DataRow row)
throws java.lang.Exception
- Specified by:
getInsertStatement
in class AbstractSqlCommand
- Parameters:
conn
- An active JDBCDataConnection to use to prepare the statementrow
- The DataRow
that will be inserted
- Returns:
- A PreparedStatement, ready to execute, for the INSERT SQL statement.
- Throws:
java.lang.Exception
getDeleteStatement
protected java.sql.PreparedStatement getDeleteStatement(JDBCDataConnection conn,
DataRow row)
throws java.lang.Exception
- Specified by:
getDeleteStatement
in class AbstractSqlCommand
- Parameters:
conn
- An active JDBCDataConnection to use to prepare the statementrow
- The DataRow
that will be deleted
- Returns:
- A PreparedStatement, ready to execute, for the DELETE SQL statement.
- Throws:
java.lang.Exception
Copyright © 2005 Sun Microsystems All Rights Reserved.