planetj.database
Class SQLGenerator

java.lang.Object
  |
  +--planetj.database.SQLGenerator

public class SQLGenerator
extends Object

A Helper class for generating SQL statements from objects.


Field Summary
static String AVERAGE
           
static String className
           
static String COUNT
           
static String MAX
           
static String MIN
           
static String SUM
           
 
Constructor Summary
SQLGenerator()
           
 
Method Summary
static StringBuffer appendFromClause(List tables, StringBuffer sql)
          Appends a FROM clause to the given StringBuffer.
static StringBuffer appendFromClause(String library, String table, StringBuffer sql)
          Appends a FROM clause to the given StringBuffer.
static StringBuffer appendSelectClause(List columnNames, StringBuffer sql)
          Appends a SELECT clause with the given column names to the given StringBuffer.
static StringBuffer appendTableName(Table table, StringBuffer sb)
          Appends the fully qualified table name to the StringBuffer.
static StringBuffer appendTableNames(List tables, StringBuffer sb)
          Appends the fully qualified table names to a StringBuffer.
static StringBuffer appendWhereAssociationClause(Map targetFDSandSourceFlds, StringBuffer sb)
          Appends the WHERE clause for an SQL association statement, based on a Map of FieldDescriptor objects and Fields, to a StringBuffer.
static StringBuffer appendWhereClause(Collection flds, StringBuffer sb)
          Appends the WHERE clause for an SQL statement, based on a Collection of field objects, to a StringBuffer.
static StringBuffer appendWhereClause(Map flds, StringBuffer sb)
          Appends the WHERE clause for an SQL statement, based on a Map of field objects, to a StringBuffer.
static String generateCreateTableStatementFromFDs(Table pTable)
          Generates a CREATE TABLE Statement that constructs a table based on the specified Table
static String generateCreateTableStatementFromRowCollection(Table pTable, RowCollection rc)
          Generates a CREATE TABLE Statement that constructs a table based on the specified Table
static String generateFieldSQLValues(List flds)
           
static String generateSelectAssociationStatement(Table pTable, String pSelectFields, Map pFldMap)
          Generates a SQL select statement for retreiving Row associations Examples:
static String generateSelectAssociationStatementForRowCollection(Table pTable, String pSelectFields, Map pTargetFDSandSourceFlds)
          Generates a SQL select statement for retreiving RowCollection associations Examples:
static String generateSelectOperationStatement(Table pTable, String pSelectOperation, String pColumnName, 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 String generateSelectSQL(Table tbl, 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 String getInsertValues(Map flds)
          Returns a String that contains column names and values for an insert SQL statment
static String getSetValues(Map flds)
           
static String getTableName(Table table)
          Gets fully qualified name of a Table object.
static String getTableNames(List tables)
          Gets the fully qualified table names from a List of Table objects.
static String getWhereClause(Map flds)
          Gets the WHERE clause for an SQL statement, based on a Map of field objects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

className

public static final String className

COUNT

public static final String COUNT
See Also:
Constant Field Values

MIN

public static final String MIN
See Also:
Constant Field Values

MAX

public static final String MAX
See Also:
Constant Field Values

AVERAGE

public static final String AVERAGE
See Also:
Constant Field Values

SUM

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

SQLGenerator

public SQLGenerator()
Method Detail

appendFromClause

public static StringBuffer appendFromClause(String library,
                                            String table,
                                            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 StringBuffer appendFromClause(List tables,
                                            StringBuffer sql)
Appends a FROM clause to the given StringBuffer.

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

appendSelectClause

public static StringBuffer appendSelectClause(List columnNames,
                                              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 StringBuffer appendTableName(Table table,
                                           StringBuffer sb)
Appends the fully qualified table name to the StringBuffer. The last character appended will be a space.


appendTableNames

public static StringBuffer appendTableNames(List tables,
                                            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 StringBuffer appendWhereAssociationClause(Map targetFDSandSourceFlds,
                                                        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()**

CMException

appendWhereClause

public static StringBuffer appendWhereClause(Map flds,
                                             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.

CMException

generateCreateTableStatementFromFDs

public static 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
CMException

generateCreateTableStatementFromRowCollection

public static 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
CMException

generateFieldSQLValues

public static String generateFieldSQLValues(List flds)
                                     throws CMException
CMException

generateSelectAssociationStatement

public static String generateSelectAssociationStatement(Table pTable,
                                                        String pSelectFields,
                                                        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
CMException

generateSelectAssociationStatementForRowCollection

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

Parameters:
pTable - Table
Returns:
String
CMException

generateSelectOperationStatement

public static String generateSelectOperationStatement(Table pTable,
                                                      String pSelectOperation,
                                                      String pColumnName,
                                                      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 String generateSelectSQL(Table tbl,
                                       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
CMException

getInsertValues

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

CMException

getSetValues

public static String getSetValues(Map flds)
                           throws CMException
CMException

getTableName

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


getTableNames

public static String getTableNames(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.


getWhereClause

public static String getWhereClause(Map flds)
                             throws CMException
Gets the WHERE clause for an SQL statement, based on a Map of field objects. 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.

CMException

appendWhereClause

public static StringBuffer appendWhereClause(Collection flds,
                                             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.

CMException