|
Oracle BPEL Process Manager Client Java API Reference 10g Release 3 (10.1.3.1.0) B28986-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.oracle.bpel.client.util.WhereCondition
public final class WhereCondition
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();
WhereConditionHelper
, Serialized FormField 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 |
---|
public static final long serialVersionUID
Constructor Detail |
---|
public WhereCondition()
public WhereCondition(java.lang.String clause)
public WhereCondition(java.lang.String clause, java.lang.String orderBy)
Method Detail |
---|
public final java.lang.String getClause()
public final void setClause(java.lang.String clause)
public final java.lang.String getOrderBy()
public final WhereCondition prependOrderBy(java.lang.String clause)
clause
- the ordering clause to insert.public final WhereCondition appendOrderBy(java.lang.String clause)
clause
- the ordering clause to insert.public final int getLastParameterIndex()
WhereCondition cond1 = new WhereCondition( "boo = ? and foo = ?" ); cond1.setString( 1, "hello" ); cond1.setInt( 2, 2342 );the last parameter index would be 2.
public final int getParameterCount()
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.public final WhereCondition prepend(java.lang.String clause)
clause
- the clause to insert.public final WhereCondition prepend(WhereCondition cond)
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:
boo value
2734627
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.
cond
- the where condition to insert.public final WhereCondition append(java.lang.String clause)
clause
- the clause to insert.public final WhereCondition append(WhereCondition cond)
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:
boo value
2734627
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.
cond
- the where condition to insert.public final void replace(java.lang.String search, java.lang.String replace)
search
- the string to search forreplace
- the string to replace matches withpublic final void clearParameters()
public final void setBoolean(int parmIndex, boolean x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setByte(int parmIndex, byte x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setDate(int parmIndex, java.util.Date x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setDouble(int parmIndex, double x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setFloat(int parmIndex, float x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setInt(int parmIndex, int x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setLong(int parmIndex, long x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setNull(int parmIndex, int sqlType)
Note: You must specify the parameter's SQL type.
paramIndex
- the first parameter is 1, the second is 2, ...x
- the SQL type code defined in java.sql.Types
.public final void setObject(int parmIndex, java.lang.Object x)
java.lang
equivalent objects for integral values.paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setShort(int parmIndex, short x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setString(int parmIndex, java.lang.String x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setTimestamp(int parmIndex, java.sql.Timestamp x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void setTimestamp(int parmIndex, java.util.Date x)
paramIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value.public final void apply(java.sql.PreparedStatement sqlStmt) throws java.sql.SQLException
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();
sqlStmt
- the SQL prepared statement.java.sql.SQLException
- if a database access error occurs.public final java.lang.String getReplacedClause()
java.sql.Statement
instead of using a java.sql.PreparedStatement
.
|
Oracle BPEL Process Manager Client Java API Reference 10g Release 3 (10.1.3.1.0) B28986-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |