planetj.database
Class SQLGenerator

java.lang.Object
  extended byplanetj.database.SQLGenerator

public class SQLGenerator
extends java.lang.Object

A Helper class for generating SQL statements from objects.


Field Summary
static java.lang.String AVERAGE
           
static java.lang.String className
           
static java.lang.String COUNT
           
static java.lang.String MAX
           
static java.lang.String MIN
           
static java.lang.String SUM
           
 
Constructor Summary
SQLGenerator()
           
 
Method Summary
static java.lang.StringBuffer appendFromClause(java.util.List tables, java.lang.StringBuffer sql)
          Appends a FROM clause to the given StringBuffer.
static java.lang.StringBuffer appendFromClause(java.lang.String library, java.lang.String table, java.lang.StringBuffer sql)
          Appends a FROM clause to the given StringBuffer.
static java.lang.StringBuffer appendInsertStatement(Row row, ExecutingContext ec, java.lang.StringBuffer sql)
           
static java.lang.StringBuffer appendInsertStatements(RowCollection rc, ExecutingContext ec, java.lang.StringBuffer sql)
           
static java.lang.StringBuffer appendSelectClause(java.util.List columnNames, java.lang.StringBuffer sql)
          Appends a SELECT clause with the given column names to the given StringBuffer.
static java.lang.StringBuffer appendTableName(Table table, java.lang.StringBuffer sb)
          Appends the fully qualified table name to the StringBuffer.
static java.lang.StringBuffer appendTableNames(java.util.List tables, java.lang.StringBuffer sb)
          Appends the fully qualified table names to a StringBuffer.
static java.lang.StringBuffer appendWhereAssociationClause(java.util.Map targetFDSandSourceFlds, java.lang.StringBuffer sb)
          Appends the WHERE clause for an SQL association statement, based on a Map of FieldDescriptor objects and Fields, to a StringBuffer.
static java.lang.StringBuffer appendWhereClause(java.util.Collection flds, boolean originalValues, java.lang.StringBuffer sb)
          Appends the WHERE clause for an SQL statement, based on a Collection of field objects, to a StringBuffer.
static java.lang.StringBuffer appendWhereClause(java.util.Collection flds, java.lang.StringBuffer sb)
          Appends the WHERE clause for an SQL statement, based on a Collection of field objects, to a StringBuffer.
static java.lang.StringBuffer appendWhereClause(java.util.Map flds, boolean originalValues, java.lang.StringBuffer sb)
          Appends the WHERE clause for an SQL statement, based on a Map of field objects, to a StringBuffer.
static java.lang.StringBuffer appendWhereClause(java.util.Map flds, java.lang.StringBuffer sb)
          Appends the WHERE clause for an SQL statement, based on a Map of field objects, to a StringBuffer.
static java.lang.String generateCreateTableStatementFromFDs(Table pTable)
          Generates a CREATE TABLE Statement that constructs a table based on the specified Table
static java.lang.String generateCreateTableStatementFromRowCollection(Table pTable, RowCollection rc)
          Generates a CREATE TABLE Statement that constructs a table based on the specified Table
static java.lang.String generateFieldSQLValues(java.util.List flds)
           
static java.lang.String generateSelectAssociationStatement(Table pTable, java.lang.String pSelectFields, java.util.Map pFldMap)
          Generates a SQL select statement for retreiving Row associations Examples:
static java.lang.String generateSelectAssociationStatementForRowCollection(Table pTable, java.lang.String pSelectFields, java.util.Map pTargetFDSandSourceFlds)
          Generates a SQL select statement for retreiving RowCollection associations Examples:
static java.lang.String generateSelectOperationStatement(Table pTable, java.lang.String pSelectOperation, java.lang.String pColumnName, java.lang.String pWhereClause)
          Generates a SQL select statement for the givin pSelectOperation with an optional pColumnName Examples: COUNT -> generateSelectOperationStatement(, SQLGenerator.COUNT, null, ) MIN -> generateSelectOperationStatement(, SQLGenerator.MIN, , ) MAX -> generateSelectOperationStatement(, SQLGenerator.MAX, , ) AVERAGE -> generateSelectOperationStatement(, SQLGenerator.AVERAGE, , ) TOTAL -> generateSelectOperationStatement(, SQLGenerator.SUM, , )
static java.lang.String generateSelectSQL(Table tbl, java.util.Map fdAndValues)
          Generate the SQL based on the Table and a Map of FieldDescriptors and Values Creation date: (1/16/2002 3:14:14 PM)
static java.lang.String getInsertValues(java.util.Map flds)
          Returns a String that contains column names and values for an insert SQL statment
static java.lang.String getSetValues(java.util.Collection clct)
           
static java.lang.String getSetValues(java.util.Map flds)
           
static java.lang.String getTableName(Table table)
          Gets fully qualified name of a Table object.
static java.lang.String getTableNames(java.util.List tables)
          Gets the fully qualified table names from a List of Table objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

className

public static final java.lang.String className

COUNT

public static final java.lang.String COUNT
See Also:
Constant Field Values

MIN

public static final java.lang.String MIN
See Also:
Constant Field Values

MAX

public static final java.lang.String MAX
See Also:
Constant Field Values

AVERAGE

public static final java.lang.String AVERAGE
See Also:
Constant Field Values

SUM

public static final java.lang.String SUM
See Also:
Constant Field Values
Constructor Detail

SQLGenerator

public SQLGenerator()
Method Detail

appendFromClause

public static java.lang.StringBuffer appendFromClause(java.lang.String library,
                                                      java.lang.String table,
                                                      java.lang.StringBuffer sql)
Appends a FROM clause to the given StringBuffer.

Parameters:
sql - StringBuffer to which to append from clause
library - Library name
table - Table name
Returns:
StringBuffer

appendFromClause

public static java.lang.StringBuffer appendFromClause(java.util.List tables,
                                                      java.lang.StringBuffer sql)
Appends a FROM clause to the given StringBuffer.

Parameters:
sql - StringBuffer to which to append from clause
Returns:
StringBuffer

appendSelectClause

public static java.lang.StringBuffer appendSelectClause(java.util.List columnNames,
                                                        java.lang.StringBuffer sql)
Appends a SELECT clause with the given column names to the given StringBuffer.

Parameters:
columnNames - names of the columns to select
sql - StringBuffer to which to append the select clause
Returns:
StringBuffer

appendTableName

public static java.lang.StringBuffer appendTableName(Table table,
                                                     java.lang.StringBuffer sb)
Appends the fully qualified table name to the StringBuffer. The last character appended will be a space.


appendTableNames

public static java.lang.StringBuffer appendTableNames(java.util.List tables,
                                                      java.lang.StringBuffer sb)
Appends the fully qualified table names to a StringBuffer. The names are separated by commas, and the last character appended is a space.

Parameters:
tables - A List of Table objects.
Returns:
The same StringBuffer that was passed in, after the table names have been appended.

appendWhereAssociationClause

public static java.lang.StringBuffer appendWhereAssociationClause(java.util.Map targetFDSandSourceFlds,
                                                                  java.lang.StringBuffer sb)
                                                           throws CMException
Appends the WHERE clause for an SQL association statement, based on a Map of FieldDescriptor objects and Fields, to a StringBuffer. The WHERE clause is designed to return only those rows whose fields exactly match the fields that are passed in to this method. The WHERE clause ends with a space. The Map will contain the tart file FieldDescriptors and the source file fields. This support allows Rows to get associated rows based on relating field descriptors and field values. Example: Given an Employee and Department tables we can ask the Employee.getAssociatedRow("Department") In this case we will examine Department field descriptors looking for assocation ids and then search Employee for the same ids which indicate an association has been configured. The result is that we need to generate an SQL statement that will take the Employee.deptId field and value and gen the sql to get the department from the Department table. Example: select * from department where deptid = **EmployeeRow.getFieldValue()**

Throws:
CMException

generateCreateTableStatementFromFDs

public static java.lang.String generateCreateTableStatementFromFDs(Table pTable)
                                                            throws CMException
Generates a CREATE TABLE Statement that constructs a table based on the specified Table

Parameters:
pTable - Table
Returns:
String
Throws:
CMException

generateCreateTableStatementFromRowCollection

public static java.lang.String generateCreateTableStatementFromRowCollection(Table pTable,
                                                                             RowCollection rc)
                                                                      throws CMException
Generates a CREATE TABLE Statement that constructs a table based on the specified Table

Parameters:
pTable - Table
Returns:
String
Throws:
CMException

generateFieldSQLValues

public static java.lang.String generateFieldSQLValues(java.util.List flds)
                                               throws CMException
Throws:
CMException

appendInsertStatement

public static java.lang.StringBuffer appendInsertStatement(Row row,
                                                           ExecutingContext ec,
                                                           java.lang.StringBuffer sql)
                                                    throws CMException
Throws:
CMException

appendInsertStatements

public static java.lang.StringBuffer appendInsertStatements(RowCollection rc,
                                                            ExecutingContext ec,
                                                            java.lang.StringBuffer sql)
                                                     throws CMException
Throws:
CMException

generateSelectAssociationStatement

public static java.lang.String generateSelectAssociationStatement(Table pTable,
                                                                  java.lang.String pSelectFields,
                                                                  java.util.Map pFldMap)
                                                           throws CMException
Generates a SQL select statement for retreiving Row associations Examples:

Parameters:
pTable - Table
pFldMap - (contains the Field and the value the field will be compared to in the where clause
Returns:
String
Throws:
CMException

generateSelectAssociationStatementForRowCollection

public static java.lang.String generateSelectAssociationStatementForRowCollection(Table pTable,
                                                                                  java.lang.String pSelectFields,
                                                                                  java.util.Map pTargetFDSandSourceFlds)
                                                                           throws CMException
Generates a SQL select statement for retreiving RowCollection associations Examples:

Parameters:
pTable - Table
Returns:
String
Throws:
CMException

generateSelectOperationStatement

public static java.lang.String generateSelectOperationStatement(Table pTable,
                                                                java.lang.String pSelectOperation,
                                                                java.lang.String pColumnName,
                                                                java.lang.String pWhereClause)
Generates a SQL select statement for the givin pSelectOperation with an optional pColumnName Examples: COUNT -> generateSelectOperationStatement(, SQLGenerator.COUNT, null, ) MIN -> generateSelectOperationStatement(
, SQLGenerator.MIN, , ) MAX -> generateSelectOperationStatement(
, SQLGenerator.MAX, , ) AVERAGE -> generateSelectOperationStatement(
, SQLGenerator.AVERAGE, , ) TOTAL -> generateSelectOperationStatement(
, SQLGenerator.SUM, , )

Parameters:
pTable - Table
pSelectOperation - COUNT, MIN, MAX, AVERAGE, SUM etc.
pColumnName - specified column name for min,max,average,total,etc...
pWhereClause - ie. WHERE id > 100
Returns:
String

generateSelectSQL

public static java.lang.String generateSelectSQL(Table tbl,
                                                 java.util.Map fdAndValues)
                                          throws CMException
Generate the SQL based on the Table and a Map of FieldDescriptors and Values Creation date: (1/16/2002 3:14:14 PM)

Parameters:
tbl - planetj.database.Table
fdAndValues - Map
Returns:
java.lang.String
Throws:
CMException

getInsertValues

public static java.lang.String getInsertValues(java.util.Map flds)
                                        throws CMException
Returns a String that contains column names and values for an insert SQL statment

Throws:
CMException

getSetValues

public static java.lang.String getSetValues(java.util.Map flds)
                                     throws CMException
Throws:
CMException

getSetValues

public static java.lang.String getSetValues(java.util.Collection clct)
                                     throws CMException
Throws:
CMException

getTableName

public static java.lang.String getTableName(Table table)
Gets fully qualified name of a Table object. The name ends with a space.


getTableNames

public static java.lang.String getTableNames(java.util.List tables)
Gets the fully qualified table names from a List of Table objects. The names are separated by commas, and the last character in the returned String is a space.


appendWhereClause

public static java.lang.StringBuffer appendWhereClause(java.util.Map flds,
                                                       java.lang.StringBuffer sb)
                                                throws CMException
Appends the WHERE clause for an SQL statement, based on a Map of field objects, to a StringBuffer. The WHERE clause is designed to return only those rows whose fields exactly match the fields that are passed in to this method. The WHERE clause ends with a space. The original values of the fields are used

Throws:
CMException

appendWhereClause

public static java.lang.StringBuffer appendWhereClause(java.util.Map flds,
                                                       boolean originalValues,
                                                       java.lang.StringBuffer sb)
                                                throws CMException
Appends the WHERE clause for an SQL statement, based on a Map of field objects, to a StringBuffer. The WHERE clause is designed to return only those rows whose fields exactly match the fields that are passed in to this method. The WHERE clause ends with a space.

Throws:
CMException

appendWhereClause

public static java.lang.StringBuffer appendWhereClause(java.util.Collection flds,
                                                       java.lang.StringBuffer sb)
                                                throws CMException
Appends the WHERE clause for an SQL statement, based on a Collection of field objects, to a StringBuffer. The WHERE clause is designed to return only those rows whose fields exactly match the fields that are passed in to this method. The WHERE clause ends with a space. The original, not the current values of the fields are used

Throws:
CMException

appendWhereClause

public static java.lang.StringBuffer appendWhereClause(java.util.Collection flds,
                                                       boolean originalValues,
                                                       java.lang.StringBuffer sb)
                                                throws CMException
Appends the WHERE clause for an SQL statement, based on a Collection of field objects, to a StringBuffer. The WHERE clause is designed to return only those rows whose fields exactly match the fields that are passed in to this method. The WHERE clause ends with a space.

Throws:
CMException