org.genericdao
Class MatchArg

java.lang.Object
  extended by org.genericdao.MatchArg

public abstract class MatchArg
extends Object

A class to specify constraints when matching beans. Use with the GenericDAO.match() method, which generates a SQL SELECT call on the underlying table. The MatchArg parameters are converted into the WHERE clause for the SELECT so as to constrain which rows are returned.

For example, given a the following User bean:

     public class User {
         private String userName;
         private String password;
         private String firstName;
         private String lastName;
         
         public String getUserName()  { return userName;  }
         public String getPassword()  { return password;  }
         public String getFirstName() { return firstName; }
         public String getLastName()  { return lastName;  }

         public void setUserName(String s)  { userName  = s; }
         public void setPassword(String s)  { password  = s; }
         public void setFirstName(String s) { firstName = s; }
         public void setLastName(String s)  { lastName  = s; }
     }
 

this call would return all users with password equal to "testing".:

     User[] array = dao.match(MatchArg.equals("password", "testing"));
 


Constructor Summary
protected MatchArg()
           
 
Method Summary
static MatchArg and(MatchArg... constraints)
          Logical AND operator for use with the GenericDAO.match() method.
static MatchArg contains(String fieldName, String s)
          String "contains" operator for use with the GenericDAO.match() method.
static MatchArg containsIgnoreCase(String fieldName, String s)
          String "contains" operator for use with the GenericDAO.match() method.
static MatchArg endsWith(String fieldName, String ending)
          String "ends with" operator for use with the GenericDAO.match() method.
static MatchArg endsWithIgnoreCase(String fieldName, String ending)
          String "ends with" operator for use with the GenericDAO.match() method.
static MatchArg equals(String fieldName, Object matchValue)
          Equals operator for use with the GenericDAO.match() method.
static MatchArg equalsIgnoreCase(String keyName, String matchValue)
           
protected abstract  org.genericdao.impl.matcharg.MatchOp getOp()
           
static MatchArg greaterThan(String keyName, Object matchValue)
           
static MatchArg greaterThanOrEqualTo(String keyName, Object matchValue)
           
static MatchArg lessThan(String keyName, Object matchValue)
           
static MatchArg lessThanOrEqualTo(String keyName, Object matchValue)
           
static MatchArg max(String keyName)
           
static MatchArg min(String keyName)
           
static MatchArg notEquals(String fieldName, Object matchValue)
          Not equals operator for use with the GenericDAO.match() method.
static MatchArg or(MatchArg... constraints)
          Logical OR operator for use with the GenericDAO.match() method.
static MatchArg startsWith(String keyName, String beginning)
           
static MatchArg startsWithIgnoreCase(String keyName, String beginning)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatchArg

protected MatchArg()
Method Detail

getOp

protected abstract org.genericdao.impl.matcharg.MatchOp getOp()

and

public static MatchArg and(MatchArg... constraints)
Logical AND operator for use with the GenericDAO.match() method. Takes as parameters a variable number of MatchArg constraints, all of which must evaluate to true for a row to be returned by GenericDAO.match(). For example, using the User bean defined above, this match call would return all users with first name "George" and last name "Bush".:

     User[] array = dao.match(
                          MatchArg.and(
                                MatchArg.equals("firstName", "George"),
                                MatchArg.equals("lastName",  "Bush")));
 

Parameters:
constraints - zero or more other MatchArg parameters
Returns:
a MatchArg which evaluates true for a row if all the constraint arguments evaluate to true for that row

contains

public static MatchArg contains(String fieldName,
                                String s)
String "contains" operator for use with the GenericDAO.match() method. It evaluates to true for a row when the value of the specified field contains the given string value. The database field must contain string values. If it does not, an exception is thrown by the match() method.

For example, using the User bean defined above, this match would return all users whose first name contains a lower case double "r":

     User[] array = dao.match(MatchArg.contains("firstName", "rr"));
 

Parameters:
fieldName - the name of the field in the table being matched. Field must contain string values.
s - the substring which must be present in the specified field for this MatchArg to evaluate to true.
Returns:
a MatchArg which evaluates true for a row if the specified field contains the given string

containsIgnoreCase

public static MatchArg containsIgnoreCase(String fieldName,
                                          String s)
String "contains" operator for use with the GenericDAO.match() method. It evaluates to true for a row when the value of the specified field contains the given string value, ignoring case. The database field must contain string values. If it does not, an exception is thrown by the match() method.

For example, using the User bean defined above, this match would return all users whose first name contains the substring "st", "sT", "St", or "ST":

     User[] array = dao.match(MatchArg.containsIgnoreCase("firstName", "st"));
 

Parameters:
fieldName - the name of the field in the table being matched. Field must contain string values.
s - the substring which must be present in the specified field, ignoring case, for this MatchArg to evaluate to true.
Returns:
a MatchArg which evaluates true for a row if the specified field contains the given string, ignoring case.

endsWith

public static MatchArg endsWith(String fieldName,
                                String ending)
String "ends with" operator for use with the GenericDAO.match() method. It evaluates to true for a row when the value of the specified field ends with the given string value. The database field must contain string values. If it does not, an exception is thrown by the match() method.

For example, using the User bean defined above, this match would return all users whose first name ends with the lower case "st" characters:

     User[] array = dao.match(MatchArg.endsWith("firstName", "st"));
 

Parameters:
fieldName - the name of the field in the table being matched. Field must contain string values.
ending - the substring which must be present at the end of the specified field for this MatchArg to evaluate to true.
Returns:
a MatchArg which evaluates true for a row if the specified field ends with the given string

endsWithIgnoreCase

public static MatchArg endsWithIgnoreCase(String fieldName,
                                          String ending)
String "ends with" operator for use with the GenericDAO.match() method. It evaluates to true for a row when the value of the specified field ends with the given string value, ignoring case. The database field must contain string values. If it does not, an exception is thrown by the match() method.

For example, using the User bean defined above, this match would return all users whose first name contains the "st", "sT", "St", or "ST":

     User[] array = dao.match(MatchArg.endsWithIgnoreCase("firstName", "st"));
 

Parameters:
fieldName - the name of the field in the table being matched. Field must contain string values.
ending - the substring which must be present at the end of the specified field, ignoring case, for this MatchArg to evaluate to true.
Returns:
a MatchArg which evaluates true for a row if the specified field ends with the given string, ignoring case.

equals

public static MatchArg equals(String fieldName,
                              Object matchValue)
Equals operator for use with the GenericDAO.match() method. It evaluates to true for a row when the value of the specified field equals the given value. This operator can be used on all types, except array types. Except, it can be used with byte[]. The matchValue must be of a type appropriate for the specified field. This is checked by the match() method.

For example, using the User bean defined above, this match would return all users whose friend count is zero:

     User[] array = dao.match(MatchArg.equals("friendCount", 0));
 

Parameters:
fieldName - the name of the field being matched.
matchValue - the value which the specified field must equal for this MatchArg to evaluate to true.
Returns:
a MatchArg which evaluates true for a row if the specified field is equals to the given value.

equalsIgnoreCase

public static MatchArg equalsIgnoreCase(String keyName,
                                        String matchValue)

greaterThan

public static MatchArg greaterThan(String keyName,
                                   Object matchValue)

greaterThanOrEqualTo

public static MatchArg greaterThanOrEqualTo(String keyName,
                                            Object matchValue)

lessThan

public static MatchArg lessThan(String keyName,
                                Object matchValue)

lessThanOrEqualTo

public static MatchArg lessThanOrEqualTo(String keyName,
                                         Object matchValue)

max

public static MatchArg max(String keyName)

min

public static MatchArg min(String keyName)

notEquals

public static MatchArg notEquals(String fieldName,
                                 Object matchValue)
Not equals operator for use with the GenericDAO.match() method. It evaluates to true for a row when the value of the specified field is not equal to the given value. This operator can be used on all types, except array types. Except, it can be used with byte[]. The matchValue must be of a type appropriate for the specified field. This is checked by the match() method.

For example, using the User bean defined above, this match would return all users whose friend count not zero:

     User[] array = dao.match(MatchArg.notEquals("friendCount", 0));
 

Parameters:
fieldName - the name of the field being matched.
matchValue - the value which the specified field must not equal for this MatchArg to evaluate to true.
Returns:
a MatchArg which evaluates true for a row if the specified field is not equal to the given value.

or

public static MatchArg or(MatchArg... constraints)
Logical OR operator for use with the GenericDAO.match() method. Takes as parameters a variable number of MatchArgs, any one of which must evaluate to true for a row to be returned. For example, using the User bean defined above, this match would return all users with first name "William" or first name "Bill".:

     User[] array = dao.match(
                          MatchArg.or(
                                MatchArg.equals("firstName", "William"),
                                MatchArg.equals("firstName", "Bill"));
 

Parameters:
constraints - zero or more other MatchArg parameters
Returns:
true when matching rows if all the constraint arguments evaluate to true for for that row

startsWith

public static MatchArg startsWith(String keyName,
                                  String beginning)

startsWithIgnoreCase

public static MatchArg startsWithIgnoreCase(String keyName,
                                            String beginning)


Copyright © 2012 Jeffrey L. Eppinger. All rights reserved. Permission granted for educational use only.