com.objectwave.persist.constraints
Class ConstraintCompare

java.lang.Object
  |
  +--com.objectwave.persist.constraints.Constraint
        |
        +--com.objectwave.persist.constraints.ConstraintCompare
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class ConstraintCompare
extends Constraint

The constraint object to handle the following comparison capabilities. "LIKE", "MATCHES", "=", "!=", "<", ">=", ">", "<=" .

Version:
$Id: ConstraintCompare.java,v 2.1 2002/02/08 22:41:28 dave_hoag Exp $
Author:
Steven Sinclair
See Also:
Serialized Form

Field Summary
static int equalsIndex
          Description of the Field
static int greaterOrEqualIndex
          Description of the Field
static int greaterThanIndex
          Description of the Field
static int lessOrEqualIndex
          Description of the Field
static int lessThanIndex
          Description of the Field
static int likeIndex
          Description of the Field
static int matchesIndex
          Description of the Field
static int notEqualsIndex
          Description of the Field
 
Fields inherited from class com.objectwave.persist.constraints.Constraint
columnName, defaultObjectFormatter, objectFormatter
 
Constructor Summary
ConstraintCompare()
           
 
Method Summary
 boolean checkConstraint(java.lang.Object fieldObj, java.lang.Object queryObj)
          Check to see if a given object passes this constraint.
 java.lang.String constructQueryString()
          Return the string which will appear in the query string.
protected  boolean dateCompare(java.util.Date fDate, java.util.Date rDate, java.lang.String comp)
          Compare the two dates with the specified comparison operation.
 void fromString(java.lang.String str)
          Parse the string.
 java.lang.String getComparison()
           
 int getComparisonIndex()
           
static java.lang.String[] getComparisons()
           
 java.lang.String getCompValue()
           
static java.util.Vector getFields()
           
 java.util.Enumeration getStaticList()
          Gets the StaticList attribute of the Constraint object
 java.lang.String getType()
          This is a unique, readable string identifying the constraint type (ex, anyof, null)
 boolean isComparisonValueFromPersistentObject()
           
 void setComparison(int index)
           
 void setComparison(java.lang.String comp)
           
 void setCompValue(java.lang.String val)
          Sets the CompValue attribute of the ConstraintCompare object
protected  java.lang.String sqlCompValue()
           
 void staticListInsert(java.lang.String field)
          Each type of constraint will have a specific set of fields associated with it.
protected  boolean stringCompare(java.lang.String fStr, java.lang.String rStr, java.lang.String comp)
          Compare the two strings with the specified comparison operation.
 java.lang.String stringify()
          A nice display version of the object.
 
Methods inherited from class com.objectwave.persist.constraints.Constraint
checkConstraint, classOfField, clone, equals, findField, formatString, getColumnName, getField, getNot, getObjectFormatter, getPersistence, isUsingColumnName, setColumnName, setField, setNot, setObjectFormatter, setPersistence, sqlString, stringToObject, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

likeIndex

public static final int likeIndex
Description of the Field

See Also:
Constant Field Values

matchesIndex

public static final int matchesIndex
Description of the Field

See Also:
Constant Field Values

equalsIndex

public static final int equalsIndex
Description of the Field

See Also:
Constant Field Values

notEqualsIndex

public static final int notEqualsIndex
Description of the Field

See Also:
Constant Field Values

lessThanIndex

public static final int lessThanIndex
Description of the Field

See Also:
Constant Field Values

greaterOrEqualIndex

public static final int greaterOrEqualIndex
Description of the Field

See Also:
Constant Field Values

greaterThanIndex

public static final int greaterThanIndex
Description of the Field

See Also:
Constant Field Values

lessOrEqualIndex

public static final int lessOrEqualIndex
Description of the Field

See Also:
Constant Field Values
Constructor Detail

ConstraintCompare

public ConstraintCompare()
Method Detail

getComparisons

public static java.lang.String[] getComparisons()
Returns:
The Comparisons value

getFields

public static java.util.Vector getFields()
Returns:
The Fields value

setComparison

public void setComparison(int index)
Parameters:
index - The new Comparison value

setComparison

public void setComparison(java.lang.String comp)
Parameters:
comp - The new Comparison value

setCompValue

public void setCompValue(java.lang.String val)
Sets the CompValue attribute of the ConstraintCompare object

Parameters:
val - The new CompValue value

getComparison

public java.lang.String getComparison()
Returns:
The Comparison value

getComparisonIndex

public int getComparisonIndex()
Returns:
The ComparisonIndex value

getCompValue

public java.lang.String getCompValue()
Returns:
The CompValue value

getStaticList

public java.util.Enumeration getStaticList()
Description copied from class: Constraint
Gets the StaticList attribute of the Constraint object

Specified by:
getStaticList in class Constraint
Returns:
The StaticList value

getType

public java.lang.String getType()
Description copied from class: Constraint
This is a unique, readable string identifying the constraint type (ex, anyof, null)

Specified by:
getType in class Constraint
Returns:
The Type value

isComparisonValueFromPersistentObject

public boolean isComparisonValueFromPersistentObject()
Overrides:
isComparisonValueFromPersistentObject in class Constraint
Returns:
true If the constraint object should use the comparison value from the persistent object.

checkConstraint

public boolean checkConstraint(java.lang.Object fieldObj,
                               java.lang.Object queryObj)
Description copied from class: Constraint
Check to see if a given object passes this constraint.

Specified by:
checkConstraint in class Constraint
Parameters:
fieldObj - java.lang.Object The value being compared.
queryObj - java.lang.Object
Returns:
boolean True if the constraing matches.

constructQueryString

public java.lang.String constructQueryString()
Description copied from class: Constraint
Return the string which will appear in the query string. That is, what should follow the field specification? (ex, "NOT IN ('cat','dog')"). If this constraint is simply an operator, and the original comparison value should go on the RHS, then the last character should be a '*'. Ex, If the field is "quote.status", and the field' value has been specified to be "Q%", then returning "MATCHES*" will produce "quote.status MATCHES Q%". Ex, Using the above example, returning "NOT IN ('cat','dog')" will produce "quote.status NOT IN ('cat','dog')". Note that the returned string is never padded with spaces. Note that this method will return null if the string cannot be constructed for some reason (an messafe will already have been presented to the user. Perhaps I should delegate that responsability to the calling method... hmmm....)

Specified by:
constructQueryString in class Constraint
Returns:
Description of the Returned Value

fromString

public void fromString(java.lang.String str)
                throws java.text.ParseException
Description copied from class: Constraint
Parse the string. Probably a string encoded via the toString() call, this method attempts to build the object's state from the information in string "str".

Specified by:
fromString in class Constraint
Parameters:
str - Description of Parameter
Throws:
java.text.ParseException - Description of Exception

staticListInsert

public void staticListInsert(java.lang.String field)
Description copied from class: Constraint
Each type of constraint will have a specific set of fields associated with it. This is to allow the user to select them via Gui.

Specified by:
staticListInsert in class Constraint
Parameters:
field - Description of Parameter

stringify

public java.lang.String stringify()
A nice display version of the object.

Specified by:
stringify in class Constraint
Returns:
Description of the Returned Value

dateCompare

protected boolean dateCompare(java.util.Date fDate,
                              java.util.Date rDate,
                              java.lang.String comp)
Compare the two dates with the specified comparison operation.

Parameters:
fDate - The left hand argument to the comparison
rDate - The right hand argument to the comparison
comp - The comparison type. ex. '=', ' <=', etc...
Returns:
boolean The result of the comparison.

stringCompare

protected boolean stringCompare(java.lang.String fStr,
                                java.lang.String rStr,
                                java.lang.String comp)
Compare the two strings with the specified comparison operation. NOTE: instanceof is a faster comparison that isInstance

Parameters:
fStr - The left hand argument to the comparison
rStr - The right hand argument to the comparison
comp - The comparison type. ex. '=', ' <=', etc...
Returns:
boolean The result of the comparison.

sqlCompValue

protected java.lang.String sqlCompValue()
                                 throws java.lang.NoSuchFieldException,
                                        java.lang.NumberFormatException,
                                        java.text.ParseException,
                                        java.io.IOException
Returns:
Description of the Returned Value
Throws:
java.lang.NoSuchFieldException - Description of Exception
java.lang.NumberFormatException - Description of Exception
java.text.ParseException - Description of Exception
java.io.IOException