Skip navigation links

Oracle BPEL Process Manager Client Java API Reference
10g Release 3 (10.1.3.1.0)

B28986-01


com.oracle.bpel.client.util
Class WhereCondition

java.lang.Object
  extended by com.oracle.bpel.client.util.WhereCondition

All Implemented Interfaces:
java.io.Serializable

public final class WhereCondition
extends java.lang.Object
implements java.io.Serializable

Simple utility class to wrap a SQL prepared statement where condition. This class caches a SQL statement and any IN parameters that the user wishes to bind to the SQL statement; these parameters are then applied at a later date when the actual SQL prepared statement is generated by the process domain.

Note: The setXXX methods for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For instance, if the IN parameter has SQL type Integer, then the method setInt should be used.

Here is an example of setting a creating and setting the parameters on a where condition.

 WhereCondition cond = new WhereCondition( "instance_id = ?" );
 cond.setLong( 1, 10l );
 

Where condition objects may be concatenated together to form a larger query. The methods append and prepend allow the user to add a clause (in String format) or even a whole WhereCondition object to the beginning or end of the current where condition.

 WhereCondition cond1 = new WhereCondition( "boo = ?" );
 WhereCondition cond2 = new WhereCondition( "foo = ?" );
 WhereCondition cond3 = new WhereCondition( "goo = ?" );

 // Will change cond2 into: (boo = ? and foo =?) or goo = ?
 //
 cond2.prepend( "and" ).prepend( "(" ).prepend( cond1 )
      .append( ") or" ).append( cond3 );
 

When the where condition is to be applied to a SQL prepared statement, the apply method should be invoked after the prepared statement has been created (in the example below, assume that c is an active connection).

 PreparedStatement pStmt = c.prepareStatement(
               "select * from cube_instance where " + cond.getClause() );
 cond.apply( pStmt );
 ResultSet rs = pStmt.executeQuery();
 
Since:
1.0
See Also:
WhereConditionHelper, Serialized Form

Field Summary
static long serialVersionUID
          IMPORTANT!!!!!! Every change to this class that causes it to be incompatible with an older version must be accompanied with a change in the serialVersionUID.

 

Constructor Summary
WhereCondition()
          Default constructor.
WhereCondition(java.lang.String clause)
          Constructs a where condition with the specified clause.
WhereCondition(java.lang.String clause, java.lang.String orderBy)
          Constructs a where condition with the specified clause and ordering clause.

 

Method Summary
 WhereCondition append(java.lang.String clause)
          Inserts the specified clause at the end of this where condition.
 WhereCondition append(WhereCondition cond)
          Inserts the specified where condition at the end of this where condition.
 WhereCondition appendOrderBy(java.lang.String clause)
          Inserts the specified clause at the end of this where condition's ordering clause.
 void apply(java.sql.PreparedStatement sqlStmt)
          Binds all the parameters bound to this where condition to the specified SQL prepared statement.
 void clearParameters()
          Removes all parameter bindings from this where condition.
 java.lang.String getClause()
          Returns the clause of this where condition.
 int getLastParameterIndex()
          Returns the largest parameter index for all the parameters cached by this where condition.
 java.lang.String getOrderBy()
          Returns the ordering clause of this where condition.
 int getParameterCount()
          Returns the total number of parameters bound to this where condition.
 java.lang.String getReplacedClause()
          Returns a SQL statement with all the parameters substituted in their proper positions in the query.
 WhereCondition prepend(java.lang.String clause)
          Inserts the specified clause at the beginning of this where condition.
 WhereCondition prepend(WhereCondition cond)
          Inserts the specified where condition at the beginning of this where condition.
 WhereCondition prependOrderBy(java.lang.String clause)
          Inserts the specified clause at the beginning of the ordering clause for this where condition.
 void replace(java.lang.String search, java.lang.String replace)
          Replaces all instances of the specified search string with the specified replacement string in this where condition's clause.
 void setBoolean(int parmIndex, boolean x)
          Sets the designated parameter to a Java boolean value.
 void setByte(int parmIndex, byte x)
          Sets the designated parameter to a Java byte value.
 void setClause(java.lang.String clause)
          Sets the clause for this where condition.
 void setDate(int parmIndex, java.util.Date x)
          Sets the designated parameter to a java.sql.Date value.
 void setDouble(int parmIndex, double x)
          Sets the designated parameter to a Java double value.
 void setFloat(int parmIndex, float x)
          Sets the designated parameter to a Java float value.
 void setInt(int parmIndex, int x)
          Sets the designated parameter to a Java int value.
 void setLong(int parmIndex, long x)
          Sets the designated parameter to a Java long value.
 void setNull(int parmIndex, int sqlType)
          Sets the designated parameter to SQL NULL.
 void setObject(int parmIndex, java.lang.Object x)
          Sets the value of a parameter using an object; use the java.lang equivalent objects for integral values.
 void setShort(int parmIndex, short x)
          Sets the designated parameter to a Java short value.
 void setString(int parmIndex, java.lang.String x)
          Sets the designated parameter to a Java String value.
 void setTimestamp(int parmIndex, java.util.Date x)
          Sets the designated parameter to a java.sql.Timestamp value.
 void setTimestamp(int parmIndex, java.sql.Timestamp x)
          Sets the designated parameter to a java.sql.Timestamp value.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

serialVersionUID

public static final long serialVersionUID
IMPORTANT!!!!!! Every change to this class that causes it to be incompatible with an older version must be accompanied with a change in the serialVersionUID. That is, if the members or interface changes.
See Also:
Constant Field Values

Constructor Detail

WhereCondition

public WhereCondition()
Default constructor.

WhereCondition

public WhereCondition(java.lang.String clause)
Constructs a where condition with the specified clause.

WhereCondition

public WhereCondition(java.lang.String clause,
                      java.lang.String orderBy)
Constructs a where condition with the specified clause and ordering clause.

Method Detail

getClause

public final java.lang.String getClause()
Returns the clause of this where condition. The clause is in a format suitable for inclusion in a SQL prepared statement (that is, without the '?' replaced with their associated parameters.

setClause

public final void setClause(java.lang.String clause)
Sets the clause for this where condition. The clause must be in a format suitable for inclusion in a SQL prepared statement (that is, without the '?' replaced with their associated parameters.

getOrderBy

public final java.lang.String getOrderBy()
Returns the ordering clause of this where condition.

prependOrderBy

public final WhereCondition prependOrderBy(java.lang.String clause)
Inserts the specified clause at the beginning of the ordering clause for this where condition. A space (" ") is inserted between the end of the clause and the start of this where condition's ordering clause.
Parameters:
clause - the ordering clause to insert.
Returns:
a reference to this where condition.

appendOrderBy

public final WhereCondition appendOrderBy(java.lang.String clause)
Inserts the specified clause at the end of this where condition's ordering clause. A space (" ") is inserted between the end of this where condition's ordering clause and the start of the clause.
Parameters:
clause - the ordering clause to insert.
Returns:
a reference to this where condition.

getLastParameterIndex

public final int getLastParameterIndex()
Returns the largest parameter index for all the parameters cached by this where condition. For example, if the following code were executed:
 WhereCondition cond1 = new WhereCondition( "boo = ? and foo = ?" );
 cond1.setString( 1, "hello" );
 cond1.setInt( 2, 2342 );
 
the last parameter index would be 2.

getParameterCount

public final int getParameterCount()
Returns the total number of parameters bound to this where condition. For example, if the following code were executed:
 WhereCondition cond1 = new WhereCondition( "boo = ?" );
 WhereCondition cond2 = new WhereCondition( "foo = ?" );
 WhereCondition cond3 = new WhereCondition( "goo = ?" );

 // Will change cond2 into: (boo = ? and foo =?) or goo = ?
 //
 cond2.prepend( "and" ).prepend( "(" ).prepend( cond1 )
      .append( ") or" ).append( cond3 );
 
The total number of parameters for cond2 would be 3.

prepend

public final WhereCondition prepend(java.lang.String clause)
Inserts the specified clause at the beginning of this where condition. A space (" ") is inserted between the end of the clause and the start of this where condition's clause.
Parameters:
clause - the clause to insert.
Returns:
a reference to this where condition.

prepend

public final WhereCondition prepend(WhereCondition cond)
Inserts the specified where condition at the beginning of this where condition. If the specified where condition has bound parameters to itself, those parameters are copied over to this where condition's parameters. For example, if the following code were executed:
 WhereCondition cond1 = new WhereCondition( "boo = ?" );
 cond1.setString( 1, "boo value" );
 WhereCondition cond2 = new WhereCondition( "foo = ?" );
 cond2.setInt( 1, 2734627 );
 WhereCondition cond3 = new WhereCondition( "goo = ?" );
 cond3.setString( "goo value" );

 // Will change cond2 into: (boo = ? and foo =?) or goo = ?
 //
 cond2.prepend( "and" ).prepend( "(" ).prepend( cond1 )
      .append( ") or" ).append( cond3 );
 
the parameters for cond2 will be:
  1. 1: boo value
  2. 2: 2734627
  3. 3: goo value

A space is inserted (" ") between the end of the specified where condition's clause and the start of this where condition's clause.

Parameters:
cond - the where condition to insert.
Returns:
a reference to this where condition.

append

public final WhereCondition append(java.lang.String clause)
Inserts the specified clause at the end of this where condition. A space (" ") is inserted between the end of this where condition's clause and the start of the clause.
Parameters:
clause - the clause to insert.
Returns:
a reference to this where condition.

append

public final WhereCondition append(WhereCondition cond)
Inserts the specified where condition at the end of this where condition. If the specified where condition has bound parameters to itself, those parameters are copied over to this where condition's parameters. For example, if the following code were executed:
 WhereCondition cond1 = new WhereCondition( "boo = ?" );
 cond1.setString( 1, "boo value" );
 WhereCondition cond2 = new WhereCondition( "foo = ?" );
 cond2.setInt( 1, 2734627 );
 WhereCondition cond3 = new WhereCondition( "goo = ?" );
 cond3.setString( "goo value" );

 // Will change cond2 into: (boo = ? and foo =?) or goo = ?
 //
 cond2.prepend( "and" ).prepend( "(" ).prepend( cond1 )
      .append( ") or" ).append( cond3 );
 
the parameters for cond2 will be:
  1. 1: boo value
  2. 2: 2734627
  3. 3: goo value

A space is inserted (" ") between the end of this where condition's clause and the start of the specified where condition's clause.

Parameters:
cond - the where condition to insert.
Returns:
a reference to this where condition.

replace

public final void replace(java.lang.String search,
                          java.lang.String replace)
Replaces all instances of the specified search string with the specified replacement string in this where condition's clause.
Parameters:
search - the string to search for
replace - the string to replace matches with

clearParameters

public final void clearParameters()
Removes all parameter bindings from this where condition.

setBoolean

public final void setBoolean(int parmIndex,
                             boolean x)
Sets the designated parameter to a Java boolean value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setByte

public final void setByte(int parmIndex,
                          byte x)
Sets the designated parameter to a Java byte value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setDate

public final void setDate(int parmIndex,
                          java.util.Date x)
Sets the designated parameter to a java.sql.Date value. The prepared statement will convert this to an SQL DATE value when it sends it to the database.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setDouble

public final void setDouble(int parmIndex,
                            double x)
Sets the designated parameter to a Java double value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setFloat

public final void setFloat(int parmIndex,
                           float x)
Sets the designated parameter to a Java float value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setInt

public final void setInt(int parmIndex,
                         int x)
Sets the designated parameter to a Java int value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setLong

public final void setLong(int parmIndex,
                          long x)
Sets the designated parameter to a Java long value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setNull

public final void setNull(int parmIndex,
                          int sqlType)
Sets the designated parameter to SQL NULL.

Note: You must specify the parameter's SQL type.

Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the SQL type code defined in java.sql.Types.

setObject

public final void setObject(int parmIndex,
                            java.lang.Object x)
Sets the value of a parameter using an object; use the java.lang equivalent objects for integral values.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setShort

public final void setShort(int parmIndex,
                           short x)
Sets the designated parameter to a Java short value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setString

public final void setString(int parmIndex,
                            java.lang.String x)
Sets the designated parameter to a Java String value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setTimestamp

public final void setTimestamp(int parmIndex,
                               java.sql.Timestamp x)
Sets the designated parameter to a java.sql.Timestamp value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

setTimestamp

public final void setTimestamp(int parmIndex,
                               java.util.Date x)
Sets the designated parameter to a java.sql.Timestamp value.
Parameters:
paramIndex - the first parameter is 1, the second is 2, ...
x - the parameter value.

apply

public final void apply(java.sql.PreparedStatement sqlStmt)
                 throws java.sql.SQLException
Binds all the parameters bound to this where condition to the specified SQL prepared statement. The SQL prepared statement should already be created with the proper SQL statement (the where condition clause can be fetching using the getClause() method). For example (assume that c is an active connection:
 PreparedStatement pStmt = c.prepareStatement(
               "select * from cube_instance where " + cond.getClause() );
 cond.apply( pStmt );
 ResultSet rs = pStmt.executeQuery();
 
Parameters:
sqlStmt - the SQL prepared statement.
Throws:
java.sql.SQLException - if a database access error occurs.

getReplacedClause

public final java.lang.String getReplacedClause()
Returns a SQL statement with all the parameters substituted in their proper positions in the query. This method is helpful when the user wishes to create a java.sql.Statement instead of using a java.sql.PreparedStatement.

Skip navigation links

Oracle BPEL Process Manager Client Java API Reference
10g Release 3 (10.1.3.1.0)

B28986-01


Copyright © 2006, Oracle. All rights reserved.