2004.04.29


com.jdc.rdb.sql
Class SQLHelper

java.lang.Object
  |
  +--com.jdc.lang.Object
        |
        +--com.jdc.rdb.sql.SQLHelper
All Implemented Interfaces:
Serializable

public class SQLHelper
extends Object
implements Serializable

SQLHelper is a utility class that provides Structured Query Language (SQL) helper methods to simplify the creation of Table command statements.  The following methods are available:

Version:
1.0
Author:
Jay Damon
See Also:
SQLClauseHelper, Serialized Form

Field Summary
static String COMMA
          The SQL statement comma character.
static String EQUALS
          The SQL statement equals character.
protected static String LEFT_PARENTHESIS
          The SQL statement left parenthesis character.
static String NULL
          The SQL statement null keyword.
protected static String RIGHT_PARENTHESIS
          The SQL statement right parenthesis character.
static String SPACE
          The SQL statement space character.
protected static String SUBSTITUTION_VALUE
          The SQL statement substitution value character.
 
Fields inherited from class com.jdc.lang.Object
string
 
Constructor Summary
SQLHelper()
          Constructs a new SQLHelper object.
 
Method Summary
 String addCommas(String[] sqlClauseItems)
          Adds commas to SQL list items and return a comma-delimited SQL clause.
 String addDoubleQuotes(String sqlString)
          Adds double quotes to the SQL string, if the SQL string is not already contained in double quotes.
 String addParentheses(String sqlString)
          Adds parentheses to an SQL clause, if the SQL clause is not already contained in parentheses.
 String addSingleQuotes(String sqlString)
          Adds single quotes to the SQL string, if the SQL string is not already contained in single quotes.
 String createNameValues(String[] columnNames, String[] columnValues)
          Sets the SET clause for the UPDATE command.
 Object formatValue(Column column, Object value)
           
 String formatValue(String columnName, String columnValue)
          Returns a formatted table column value of appropriate type for a database Insert or Update statement.
 String getQualifiedAlias(Table table)
          Returns a fully-qualified database Table alias.
 Table getTable()
          Returns the database table to execute the SQL command upon.
 boolean isPreparedStatement()
          Returns true if creating an prepared, i.e.
 boolean isStatement()
          Returns true if creating a static SQL statement.
 void logNoRequiredClause(String command, String objectName, String clauseKeyword)
          Logs an error message for required SQL (DML) statement clause.
static void main(String[] args)
          Executes unit tests for the SQLHelper class.
 String removeDoubleQuotes(String sqlString)
          Removes double quotes from SQL string, if present.
 void setPreparedStatement(boolean preparedStatement)
          Sets the prepared SQL statement flag.
 void setTable(Table table)
          Sets the database table to execute the SQL command upon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMA

public static final String COMMA
The SQL statement comma character.

See Also:
Constant Field Values

EQUALS

public static final String EQUALS
The SQL statement equals character.

See Also:
Constant Field Values

LEFT_PARENTHESIS

protected static final String LEFT_PARENTHESIS
The SQL statement left parenthesis character.

See Also:
Constant Field Values

NULL

public static final String NULL
The SQL statement null keyword.

See Also:
Constant Field Values

RIGHT_PARENTHESIS

protected static final String RIGHT_PARENTHESIS
The SQL statement right parenthesis character.

See Also:
Constant Field Values

SPACE

public static final String SPACE
The SQL statement space character.

See Also:
Constant Field Values

SUBSTITUTION_VALUE

protected static final String SUBSTITUTION_VALUE
The SQL statement substitution value character.

See Also:
Constant Field Values
Constructor Detail

SQLHelper

public SQLHelper()
Constructs a new SQLHelper object.

Method Detail

formatValue

public Object formatValue(Column column,
                          Object value)

getQualifiedAlias

public String getQualifiedAlias(Table table)
Returns a fully-qualified database Table alias.

Returns:
A fully-qualified database Table alias.
See Also:
Into

addCommas

public String addCommas(String[] sqlClauseItems)
Adds commas to SQL list items and return a comma-delimited SQL clause.

Returns:
String The comma-delimited SQL clause.

addDoubleQuotes

public String addDoubleQuotes(String sqlString)
Adds double quotes to the SQL string, if the SQL string is not already contained in double quotes.

Returns:
String The SQL string with double quotes.

removeDoubleQuotes

public String removeDoubleQuotes(String sqlString)
Removes double quotes from SQL string, if present.

Returns:
String The SQL string without double quotes.

addParentheses

public String addParentheses(String sqlString)
Adds parentheses to an SQL clause, if the SQL clause is not already contained in parentheses.

Returns:
String The SQL clause with parentheses.

addSingleQuotes

public String addSingleQuotes(String sqlString)
Adds single quotes to the SQL string, if the SQL string is not already contained in single quotes.

Returns:
String The SQL string with single quotes.

createNameValues

public String createNameValues(String[] columnNames,
                               String[] columnValues)
Sets the SET clause for the UPDATE command. A VALUES clause specifies the table column values for each table column.

Returns:
Update This Update statement object.

formatValue

public String formatValue(String columnName,
                          String columnValue)
Returns a formatted table column value of appropriate type for a database Insert or Update statement.

Returns:
String The insert/update table column value.

getTable

public Table getTable()
Returns the database table to execute the SQL command upon.

Returns:
Table The database table.

isPreparedStatement

public boolean isPreparedStatement()
Returns true if creating an prepared, i.e. precompiled, SQL statement.

Returns:
boolean

isStatement

public boolean isStatement()
Returns true if creating a static SQL statement.

Returns:
boolean

logNoRequiredClause

public void logNoRequiredClause(String command,
                                String objectName,
                                String clauseKeyword)
Logs an error message for required SQL (DML) statement clause.


setPreparedStatement

public void setPreparedStatement(boolean preparedStatement)
Sets the prepared SQL statement flag.


setTable

public void setTable(Table table)
Sets the database table to execute the SQL command upon.


main

public static void main(String[] args)
Executes unit tests for the SQLHelper class.


2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.