org.apache.torque.util
Class SqlExpression

java.lang.Object
  extended by org.apache.torque.util.SqlExpression

public final class SqlExpression
extends java.lang.Object

This class represents a part of an SQL query found in the WHERE section. For example:

 table_a.column_a = table_b.column_a
 column LIKE 'F%'
 table.column < 3
 
This class is used primarily by BasePeer.

Version:
$Id: SqlExpression.java 476550 2006-11-18 16:08:37Z tfischer $
Author:
John D. McNally, Daniel Rall, Fedor Karpelevitch, Martin Poeschl

Method Summary
static java.lang.String build(java.lang.String columnName, java.lang.Object criteria, SqlEnum comparison)
          Builds a simple SQL expression.
static java.lang.String build(java.lang.String columnName, java.lang.Object criteria, SqlEnum comparison, boolean ignoreCase, DB db)
          Builds a simple SQL expression.
static void build(java.lang.String columnName, java.lang.Object criteria, SqlEnum comparison, boolean ignoreCase, DB db, java.lang.StringBuffer whereClause)
          Builds a simple SQL expression.
static java.lang.String buildInnerJoin(java.lang.String column, java.lang.String relatedColumn)
          Used to specify a join on two columns.
static java.lang.String buildInnerJoin(java.lang.String column, java.lang.String relatedColumn, boolean ignoreCase, DB db)
          Used to specify a join on two columns.
static void buildInnerJoin(java.lang.String column, java.lang.String relatedColumn, boolean ignoreCase, DB db, java.lang.StringBuffer whereClause)
          Used to specify a join on two columns.
static java.lang.String quoteAndEscapeText(java.lang.String rawText, DB db)
          Quotes and escapes raw text for placement in a SQL expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buildInnerJoin

public static java.lang.String buildInnerJoin(java.lang.String column,
                                              java.lang.String relatedColumn)
Used to specify a join on two columns.

Parameters:
column - A column in one of the tables to be joined.
relatedColumn - The column in the other table to be joined.
Returns:
A join expression, e.g. UPPER(table_a.column_a) = UPPER(table_b.column_b).

buildInnerJoin

public static java.lang.String buildInnerJoin(java.lang.String column,
                                              java.lang.String relatedColumn,
                                              boolean ignoreCase,
                                              DB db)
Used to specify a join on two columns.

Parameters:
column - A column in one of the tables to be joined.
relatedColumn - The column in the other table to be joined.
ignoreCase - If true and columns represent Strings, the appropriate function defined for the database will be used to ignore differences in case.
db - Represents the database in use for vendor-specific functions.
Returns:
A join expression, e.g. UPPER(table_a.column_a) = UPPER(table_b.column_b).

buildInnerJoin

public static void buildInnerJoin(java.lang.String column,
                                  java.lang.String relatedColumn,
                                  boolean ignoreCase,
                                  DB db,
                                  java.lang.StringBuffer whereClause)
Used to specify a join on two columns.

Parameters:
column - A column in one of the tables to be joined.
relatedColumn - The column in the other table to be joined.
ignoreCase - If true and columns represent Strings, the appropriate function defined for the database will be used to ignore differences in case.
db - Represents the database in use for vendor-specific functions.
whereClause - A StringBuffer to which the sql expression will be appended.

build

public static java.lang.String build(java.lang.String columnName,
                                     java.lang.Object criteria,
                                     SqlEnum comparison)
                              throws TorqueException
Builds a simple SQL expression.

Parameters:
columnName - A column.
criteria - The value to compare the column against.
comparison - One of =, <, >, ^lt;=, >=, <>, !=, LIKE, etc.
Returns:
A simple SQL expression, e.g. UPPER(table_a.column_a) LIKE UPPER('ab%c').
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

build

public static java.lang.String build(java.lang.String columnName,
                                     java.lang.Object criteria,
                                     SqlEnum comparison,
                                     boolean ignoreCase,
                                     DB db)
                              throws TorqueException
Builds a simple SQL expression.

Parameters:
columnName - A column.
criteria - The value to compare the column against.
comparison - One of =, <, >, ^lt;=, >=, <>, !=, LIKE, etc.
ignoreCase - If true and columns represent Strings, the appropriate function defined for the database will be used to ignore differences in case.
db - Represents the database in use, for vendor specific functions.
Returns:
A simple sql expression, e.g. UPPER(table_a.column_a) LIKE UPPER('ab%c').
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

build

public static void build(java.lang.String columnName,
                         java.lang.Object criteria,
                         SqlEnum comparison,
                         boolean ignoreCase,
                         DB db,
                         java.lang.StringBuffer whereClause)
                  throws TorqueException
Builds a simple SQL expression.

Parameters:
columnName - A column.
criteria - The value to compare the column against.
comparison - One of =, <, >, ^lt;=, >=, <>, !=, LIKE, etc.
ignoreCase - If true and columns represent Strings, the appropriate function defined for the database will be used to ignore differences in case.
db - Represents the database in use, for vendor specific functions.
whereClause - A StringBuffer to which the sql expression will be appended.
Throws:
TorqueException

quoteAndEscapeText

public static java.lang.String quoteAndEscapeText(java.lang.String rawText,
                                                  DB db)
Quotes and escapes raw text for placement in a SQL expression. For simplicity, the text is assumed to be neither quoted nor escaped.

Parameters:
rawText - The unquoted, unescaped text to process.
db - the db
Returns:
Quoted and escaped text.


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.