|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sri.common.util.QueryUtils
public class QueryUtils
Title: QueryUtils
Description: Utilities for formatting keywords and where clauses for queries
Note: DBObj.buildWhereClause() basically works for building where clauses, so why do I write similar methods here? There are some issues with buildWhereClause and package protection for it (and various) methods, so I had to do my own methods here. Hopefully a later version of Expresso will make more methods public instead of protected. Here are some of the issues with using DBObject.buildWhereClause() in the version of Expresso we are currently using:
So, I wrote my own below. In some of the methods below I would have liked to pass the DBObject and just look for what fields were set (like buildWhereClause does) but I can't even access getAllFieldsIterator() here (it is package protected also) so I can't loop through the fields in the object to see which ones are set. Aaag! So I just construct and pass arrays with the relevant fields instead.
| Field Summary | |
|---|---|
static String |
DESC_SORT
|
static String |
ENCLOSE_CHAR
|
static String |
ESCAPE_CHAR
|
static String[] |
LIKE_WILDCARDS
|
static String[] |
STRIP_CHARS
|
static String |
UNKNOWN_VALUE
|
| Constructor Summary | |
|---|---|
QueryUtils()
|
|
| Method Summary | |
|---|---|
static String |
addAnyRequiredField(String fieldsToRetrieve,
String[] requiredFields)
Adds necessary fields to fieldsToRetrieve. |
static String |
alphaLikeClause(String field,
String alphaChunk)
See comments in other method signature. |
static String |
alphaLikeClause(String field,
String alphaChunk,
boolean reverseChunk)
Takes a field and an alphabetical "chunk" and constructs a query to check for values for the field passed in starting with characters within that chunk's (inclusive) range. |
static String |
escapeChar(String value,
String charToEsc)
Precedes each instance of a character passed in with the escape character in the string passed in. |
static String |
fieldEqualsManyValuesClause(String field,
String[] values)
Constructs a SQL where clause checking if a field equals any of the values in the array passed in. |
static String |
fieldEqualsManyValuesClause(String field,
String[] values,
boolean caseSensitive,
boolean not)
Constructs a SQL where clause checking if a field equals any of the values in the array passed in. |
static String |
fieldEqualsNullClause(String field,
boolean not)
Generate a subclause that determines if the values is null a given field of an object. |
static String |
fieldEqualsValueClause(String[] fields,
String[] values)
Generate a subclause that determines if the values exist for the given fields of an object. |
static String |
fieldEqualsValueClause(String[] fields,
String[] values,
boolean useOr,
boolean caseSensitive,
boolean not)
Generate a subclause that determines if the values exist for the given fields of an object. |
static String |
fieldEqualsValueClause(String field,
String value)
Generate a subclause that determines if the values exist for the given fields of an object. |
static String |
fieldEqualsValueClause(String field,
String value,
boolean caseSensitive,
boolean not)
Generate a subclause that determines if the values exist for the given fields of an object. |
static String |
fieldInSetClause(String field,
String[] values,
boolean not)
Generate a subclause that determines if a field has a value in the given set of values. |
static String |
fieldIsBlankClause(String field,
boolean inverse)
Returns a REGEXP clause to determine if a field is blank. |
static String |
fieldLikeValue(String field,
String value)
Return a LIKE clause of the form |
static String |
getBoolStr(String dataContext,
boolean value)
Returns a boolean string for use in a database query, given the database context found in the request. |
static boolean |
isValueInAlphaChunk(String alphaChunk,
String value,
boolean reverseChunk)
Return true if the value passed in is in the alphabetical chunk passed in. |
static String |
keywordMatchClause(String[] keywordArray,
String field)
Generate a subclause that determines if all of the keywords exist in the given field of an object using AND. |
static String |
keywordMatchClause(String[] keywordArray,
String[] fields)
Generate a subclause that determines if all of the keywords exist in the given fields of an object using AND. |
static String |
keywordMatchClause(String keywordToMatch,
String field)
Generate a subclause that determines if the keywords exist in the given fields of an object. |
static String |
keywordMatchClause(String keywordToMatch,
String[] fields)
Generate a subclause that determines if the keywords exist in the given fields of an object. |
static String |
prepEqualsValue(String value)
Prepares a value to be in a equals clause by escaping the enclosing character and stripping any characters db can't handle. |
static String |
prepLikeValue(String value)
Prepares a value to be in a like clause by escaping the enclosing character and any wildcards and stripping any characters db can't handle. |
static String |
stripChars(String value)
Removes undesirable characters from a string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String[] STRIP_CHARS
public static final String[] LIKE_WILDCARDS
public static final String ESCAPE_CHAR
public static final String ENCLOSE_CHAR
public static String UNKNOWN_VALUE
public static String DESC_SORT
| Constructor Detail |
|---|
public QueryUtils()
| Method Detail |
|---|
public static String prepLikeValue(String value)
value - The value to be modified
public static String prepEqualsValue(String value)
value - The value to be modified
public static String stripChars(String value)
value - The string value passed in
public static String escapeChar(String value,
String charToEsc)
value - The string to modifycharToEsc - The character precede with the escape character
public static String fieldEqualsValueClause(String[] fields,
String[] values)
fields - the array of fieldsvalues - the array of values
public static String fieldEqualsValueClause(String[] fields,
String[] values,
boolean useOr,
boolean caseSensitive,
boolean not)
fields - the array of fieldsvalues - the array of valuesuseOr - true if the clause should OR results, otherwise it will ANDcaseSensitive - true if the field match should be case sensitivenot - If true, matches field that aren't equal
public static String fieldEqualsManyValuesClause(String field,
String[] values)
field - The field to checkvalues - The values to check the field against
public static String fieldEqualsManyValuesClause(String field,
String[] values,
boolean caseSensitive,
boolean not)
field - The field to checkvalues - The values to check the field againstcaseSensitive - If true, query is case sensitivenot - If true, checks if field doesn't equal any of the values
public static String fieldEqualsValueClause(String field,
String value)
field - The field of the object to look invalue - The value to look for
public static String fieldEqualsValueClause(String field,
String value,
boolean caseSensitive,
boolean not)
field - The field of the object to look invalue - The value to look forcaseSensitive - If true, query is case sensitivenot - If true, query checks if field does NOT equal value
public static String fieldEqualsNullClause(String field,
boolean not)
field - The field of the object to look innot - If true, query checks if field is NOT null
public static String keywordMatchClause(String[] keywordArray,
String field)
keywordArray - The keyword array to matchfield - The field to match
public static String keywordMatchClause(String[] keywordArray,
String[] fields)
keywordArray - the keyword array to matchfields - The fields to match
public static String keywordMatchClause(String keywordToMatch,
String field)
keywordToMatch - the keyword string to matchfield - the field of the object to look in
public static String keywordMatchClause(String keywordToMatch,
String[] fields)
keywordToMatch - The keyword string to matchfields - The fields to match
public static String fieldIsBlankClause(String field,
boolean inverse)
field - The field to checkinverse - If true, checks if field is NOT blank
public static String fieldLikeValue(String field,
String value)
field - the database object fieldvalue - the value to match
public static String alphaLikeClause(String field,
String alphaChunk)
throws ControllerException
field - The field to use in the clausealphaChunk - The alphabetical "chunk" to use as a range
ControllerException
public static String alphaLikeClause(String field,
String alphaChunk,
boolean reverseChunk)
throws ControllerException
field - The field to use in the clausealphaChunk - The alphabetical "chunk" to use as a rangereverseChunk - If true, the sort is reversed
ControllerException
public static String getBoolStr(String dataContext,
boolean value)
throws DBException
dataContext - The database contextvalue - The boolean value
DBException
public static String addAnyRequiredField(String fieldsToRetrieve,
String[] requiredFields)
fieldsToRetrieve - String of fields to retrieverequiredFields - Required fields
public static boolean isValueInAlphaChunk(String alphaChunk,
String value,
boolean reverseChunk)
throws ControllerException
alphaChunk - The alphabetical chunkvalue - The value to checkreverseChunk - If true, the sort is reversed
ControllerException
public static String fieldInSetClause(String field,
String[] values,
boolean not)
field - the field namevalues - the array of valuesnot - If true, matches field that aren't equal
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||