org.dellroad.stuff.schema
Class SQLCommand

java.lang.Object
  extended by org.dellroad.stuff.schema.SQLCommand
All Implemented Interfaces:
DatabaseAction<Connection>

public class SQLCommand
extends Object
implements DatabaseAction<Connection>

An SQL DatabaseAction that executes a single SQL statement.


Field Summary
protected  Logger log
           
 
Constructor Summary
SQLCommand(String sql)
          Constructor.
 
Method Summary
 void apply(Connection c)
          Execute the SQL statement.
 String getSQL()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Logger log
Constructor Detail

SQLCommand

public SQLCommand(String sql)
Constructor.

Parameters:
sql - the SQL to execute; must be a single statement
Throws:
IllegalArgumentException - if sql is null or contains only whitespace
Method Detail

getSQL

public String getSQL()

apply

public void apply(Connection c)
           throws SQLException
Execute the SQL statement.

The implementation in SQLCommand creates a Statement and then executes the configured SQL command via Statement.execute(java.lang.String). Subclasses may wish to override.

Specified by:
apply in interface DatabaseAction<Connection>
Parameters:
c - open transaction
Throws:
SQLException - if an error occurs while accessing the database