org.jdesktop.dataset.provider.sql
Class TableCommand

java.lang.Object
  extended by org.jdesktop.dataset.DataCommand
      extended by org.jdesktop.dataset.provider.sql.AbstractSqlCommand
          extended by org.jdesktop.dataset.provider.sql.SQLCommand
              extended by org.jdesktop.dataset.provider.sql.TableCommand

public class TableCommand
extends SQLCommand

A simplified SQLCommand for use with an SQLDataProvider, which acts against all of the columns in a given RDBMS table. No joins are used. Because this is a simple table-based DataCommand, it can infer the INSERT, UPDATE, and DELETE SQL statements to use when working with the table.

If you desire custom SQL, you may supply it to any of the Select SQL methods. If you later want to revert to the autogenerated SQL statements, then simply pass null to the setXXX methods. For example, assuming can_delete is a column on the customer table:

     TableCommand cmd = new TableCommand("customer");
     //sets a custom delete SQL statement
     cmd.setDeleteSQL("delete from customer where id=:id and can_delete=true");
     //... later, reset the delete SQL statement to the autogenerated one
     cmd.setDeleteSQL(null);
 

Author:
rbair

Constructor Summary
TableCommand()
          Creates a new instance of TableCommand
TableCommand(java.lang.String tableName)
           
TableCommand(java.lang.String tableName, java.lang.String whereClause)
           
 
Method Summary
protected  java.sql.PreparedStatement getDeleteStatement(JDBCDataConnection conn, DataRow row)
           
protected  java.sql.PreparedStatement getInsertStatement(JDBCDataConnection conn, DataRow row)
           
 java.lang.String[] getParameterNames()
          Returns an array containing all of the parameter names for this DataCommand
protected  java.sql.PreparedStatement getSelectStatement(JDBCDataConnection conn)
           
protected  java.sql.PreparedStatement getUpdateStatement(JDBCDataConnection conn, DataRow row)
           
 void setHavingClause(java.lang.String clause)
           
 void setOrderByClause(java.lang.String clause)
           
 void setTableName(java.lang.String tableName)
          Sets the name of the table in the Database from which to load/save data
 void setWhereClause(java.lang.String clause)
          Sets the where clause to use in the query.
 
Methods inherited from class org.jdesktop.dataset.provider.sql.SQLCommand
createPreparedStatement, getDeleteSQL, getInsertSQL, getSelectSQL, getUpdateSQL, setDeleteSQL, setInsertSQL, setSelectSQL, setUpdateSQL
 
Methods inherited from class org.jdesktop.dataset.provider.sql.AbstractSqlCommand
constructSql, getParameterNames, prepareStatement
 
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
 

Constructor Detail

TableCommand

public TableCommand()
Creates a new instance of TableCommand


TableCommand

public TableCommand(java.lang.String tableName)

TableCommand

public TableCommand(java.lang.String tableName,
                    java.lang.String whereClause)
Method Detail

setTableName

public void setTableName(java.lang.String tableName)
Sets the name of the table in the Database from which to load/save data


setWhereClause

public void setWhereClause(java.lang.String clause)
Sets the where clause to use in the query. This clause *must* include the "where" keyword


setOrderByClause

public void setOrderByClause(java.lang.String clause)

setHavingClause

public void setHavingClause(java.lang.String clause)

getParameterNames

public java.lang.String[] getParameterNames()
Description copied from class: DataCommand
Returns an array containing all of the parameter names for this DataCommand

Overrides:
getParameterNames in class SQLCommand
Returns:
an array of the parameter names for this DataCommand

getSelectStatement

protected java.sql.PreparedStatement getSelectStatement(JDBCDataConnection conn)
                                                 throws java.lang.Exception
Overrides:
getSelectStatement in class SQLCommand
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
Overrides:
getUpdateStatement in class SQLCommand
Parameters:
conn - An active JDBCDataConnection to use to prepare the statement
row - 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
Overrides:
getInsertStatement in class SQLCommand
Parameters:
conn - An active JDBCDataConnection to use to prepare the statement
row - 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
Overrides:
getDeleteStatement in class SQLCommand
Parameters:
conn - An active JDBCDataConnection to use to prepare the statement
row - 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.