com.objectwave.persist.sqlConstruction
Class SqlQueryBuilder

java.lang.Object
  |
  +--com.objectwave.persist.sqlConstruction.SqlQueryBuilder

public class SqlQueryBuilder
extends java.lang.Object

Utility class to build SQL statements.

Version:
$Id: SqlQueryBuilder.java,v 2.7 2002/03/23 13:42:11 dave_hoag Exp $
Author:
Dave Hoag

Nested Class Summary
static class SqlQueryBuilder.Test
           
 
Constructor Summary
SqlQueryBuilder()
           
 
Method Summary
protected  void buildAttributeWhereClause(SQLQuery query, SQLSelect sql, RDBPersistence pObj, RDBPersistence pRef)
          Look at all of our attribute values.
 void buildCountStatement(SQLSelect sql, SQLQuery obj)
          Update the sql object with the information necessary to perform a count statement as requested by the query obj.
 void buildFindStatement(RDBPersistence pObj, RDBPersistence pRef, SQLSelect sql)
          Create a find statement.
 void buildFindStatement(RDBPersistence pObj, RDBPersistence pRef, SQLSelect sql, java.util.List constraints)
          Create a find statement.
 void buildFindStatement(SQLSelect sqlObj, RDBPersistence pObj, RDBPersistence pRef)
           
 void buildFindStatement(SQLSelect sqlObj, RDBPersistence pObj, RDBPersistence pRef, java.util.List constraints)
           
 void buildFindStatement(SQLSelect sqlObj, SQLQuery obj)
          Build a SQLSelect object from the SQLQuery.
protected  void buildForeignKeyWhereClause(SQLQuery query, SQLSelect sql, RDBPersistence pObj, RDBPersistence pRef)
          Builds the where clause from the values of the foreign key instance variables that are not nil as defined in the foreign key map.
protected  void buildInstanceLinkWhereClause(SQLQuery query, SQLSelect sql, RDBPersistence pObj, RDBPersistence pRef)
          Builds the where clause from the values of the instance link instance variables that are not nil as defined in the instance link map.
protected  void checkFieldForWhereClause(AttributeTypeColumn col, SQLQuery query, SQLSelect sql, Persistence obj)
           
protected  SQLSelect createJoinObject(SQLSelect sql, RDBPersistence forObj, RDBPersistence obj)
          Takes care of building a find statement for obj and join it to sql.
protected  SQLSelect createJoinObject(SQLSelect sql, RDBPersistence forObj, RDBPersistence obj, java.util.List constraints)
          Takes care of building a find statement for obj and join it to sql.
static boolean defaultValue(java.lang.Object obj)
          Some objects will have a default value.
protected  java.lang.String[] getSelectColumnList(RDBPersistence pObj, RDBPersistence pRef)
          Get a list of all of the columns to be used in the selecte statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlQueryBuilder

public SqlQueryBuilder()
Method Detail

defaultValue

public static boolean defaultValue(java.lang.Object obj)
Some objects will have a default value. We use 'values' in the object to determine 'where clauses' for our SQL statements. Hence we use this method throughout the code to 'weed out' default values.

Parameters:
obj -
Returns:

getSelectColumnList

protected java.lang.String[] getSelectColumnList(RDBPersistence pObj,
                                                 RDBPersistence pRef)
Get a list of all of the columns to be used in the selecte statement. This will include the primaryKey column, the foreignKey columns, and any instanceLink columns that have columnNames.

Parameters:
pObj -
pRef -
Returns:
The SelectColumnList value

buildCountStatement

public void buildCountStatement(SQLSelect sql,
                                SQLQuery obj)
Update the sql object with the information necessary to perform a count statement as requested by the query obj.

Parameters:
sql - The instance that is modified with the SQL code.
obj - SQLQuery The details of the count request.

buildFindStatement

public void buildFindStatement(SQLSelect sqlObj,
                               RDBPersistence pObj,
                               RDBPersistence pRef)
Parameters:
sqlObj - The instance that is modified with the SQL code.
pObj -
pRef -

buildFindStatement

public void buildFindStatement(SQLSelect sqlObj,
                               RDBPersistence pObj,
                               RDBPersistence pRef,
                               java.util.List constraints)
Parameters:
sqlObj - The instance that is modified with the SQL code.
pObj -
pRef -
constraints -

buildFindStatement

public void buildFindStatement(RDBPersistence pObj,
                               RDBPersistence pRef,
                               SQLSelect sql)
Create a find statement.

Parameters:
pObj -
pRef -
sql - The instance that is modified with the SQL code.

buildFindStatement

public void buildFindStatement(RDBPersistence pObj,
                               RDBPersistence pRef,
                               SQLSelect sql,
                               java.util.List constraints)
Create a find statement.

Parameters:
pObj -
pRef -
sql - The instance that is modified with the SQL code.
constraints -

buildFindStatement

public void buildFindStatement(SQLSelect sqlObj,
                               SQLQuery obj)
Build a SQLSelect object from the SQLQuery. The SQLSelect contains the information formatting the SQL statement.

Parameters:
sqlObj - The instance that is modified with the SQL code.
obj -

buildAttributeWhereClause

protected void buildAttributeWhereClause(SQLQuery query,
                                         SQLSelect sql,
                                         RDBPersistence pObj,
                                         RDBPersistence pRef)
Look at all of our attribute values. (non relational values, usually primitives or Strings) If we find a value, other than nil or the default value, this value will become part of the sql where clause.

Parameters:
query -
sql -
pObj -
pRef -
See Also:
defaultValue(java.lang.Object)

checkFieldForWhereClause

protected void checkFieldForWhereClause(AttributeTypeColumn col,
                                        SQLQuery query,
                                        SQLSelect sql,
                                        Persistence obj)
Parameters:
col -
query -
sql -
obj -

buildForeignKeyWhereClause

protected void buildForeignKeyWhereClause(SQLQuery query,
                                          SQLSelect sql,
                                          RDBPersistence pObj,
                                          RDBPersistence pRef)
Builds the where clause from the values of the foreign key instance variables that are not nil as defined in the foreign key map.

Parameters:
sql - is the SQLObject that we are currently building.
query -
pObj -
pRef -

buildInstanceLinkWhereClause

protected void buildInstanceLinkWhereClause(SQLQuery query,
                                            SQLSelect sql,
                                            RDBPersistence pObj,
                                            RDBPersistence pRef)
Builds the where clause from the values of the instance link instance variables that are not nil as defined in the instance link map.

Parameters:
sql - is the SQLObject that we are currently building.
query -
pObj -
pRef -

createJoinObject

protected SQLSelect createJoinObject(SQLSelect sql,
                                     RDBPersistence forObj,
                                     RDBPersistence obj)
Takes care of building a find statement for obj and join it to sql.

Parameters:
sql - is the find statement built for forObj.
forObj - is the object from the search object that is referencing obj. It is needed to calculate the recordOffset for obj.
obj -
Returns:

createJoinObject

protected SQLSelect createJoinObject(SQLSelect sql,
                                     RDBPersistence forObj,
                                     RDBPersistence obj,
                                     java.util.List constraints)
Takes care of building a find statement for obj and join it to sql.

Parameters:
sql - is the find statement built for forObj.
forObj - is the object from the search object that is referencing obj. It is needed to calculate the recordOffset for obj.
obj -
constraints -
Returns: