org.apache.derby.iapi.types
Class Like

java.lang.Object
  extended byorg.apache.derby.iapi.types.Like

public class Like
extends java.lang.Object

Like matching algorithm. Not too speedy for %s. SQL92 says the escape character can only and must be followed by itself, %, or _. So if you choose % or _ as the escape character, you can no longer do that sort of matching. Not the most recent Like -- missing the unit tests

Author:
ames

Field Summary
private static char anyChar
           
private static char anyString
           
private static java.lang.String SUPER_STRING
           
 
Constructor Summary
private Like()
           
 
Method Summary
(package private) static java.lang.Boolean checkLengths(int vLoc, int vEnd, int pLoc, char[] pat, int pEnd)
          checkLengths -- non-national chars Returns null if we are not done.
(package private) static java.lang.Boolean checkLengths(int vLoc, int vEnd, int pLoc, int[] pat, int pEnd, int[] anyStringInts)
          checkLengths -- national chars Returns null if we are not done.
(package private) static int getMinLen(char[] pattern, int pStart, int pEnd, boolean haveEsc, char escChar)
          Calculate the shortest length string that could match this pattern for non-national chars
(package private) static int getMinLen(int[] pattern, int pStart, int pEnd, boolean haveEsc, int[] escCharInts, int[] anyStringInts)
          Calculate the shortest length string that could match this pattern for national chars
private static java.lang.String greaterEqualString(java.lang.String pattern, char escChar)
          greaterEqualString -- for Escape clause only Walk the pattern character by character
static java.lang.String greaterEqualString(java.lang.String pattern, java.lang.String escape)
          Return the substring from the pattern for the optimization >= clause.
static java.lang.String greaterEqualStringFromParameter(java.lang.String pattern)
           
static java.lang.String greaterEqualStringFromParameterWithEsc(java.lang.String pattern, java.lang.String escape)
           
static boolean isLikeComparisonNeeded(java.lang.String pattern)
          Return whether or not the like comparison is still needed after performing the like transformation on a constant string.
static boolean isOptimizable(java.lang.String pattern)
          Determine whether or not this LIKE can be transformed into optimizable clauses.
static java.lang.String lessThanString(java.lang.String pattern)
          Return the substring from the pattern for the < clause.
static java.lang.String lessThanString(java.lang.String pattern, java.lang.String escape)
          Return the substring from the pattern for the < clause.
static java.lang.String lessThanStringFromParameter(java.lang.String pattern)
           
static java.lang.String lessThanStringFromParameterWithEsc(java.lang.String pattern, java.lang.String escape)
           
static java.lang.Boolean like(char[] value, int valueLength, char[] pattern, int patternLength)
           
static java.lang.Boolean like(char[] val, int valLength, char[] pat, int patLength, char[] escape, int escapeLength)
           
private static java.lang.Boolean like(char[] val, int vLoc, int vEnd, char[] pat, int pLoc, int pEnd, char[] escape, int escapeLength)
           
static java.lang.Boolean like(int[] val, int valLength, int[] pat, int patLength, int[] escape, int escapeLength, java.text.RuleBasedCollator collator)
          For national chars.
static java.lang.Boolean like(int[] value, int valueLength, int[] pattern, int patternLength, java.text.RuleBasedCollator collator)
           
private static java.lang.Boolean like(int[] val, int vLoc, int vEnd, int[] pat, int pLoc, int pEnd, int[] escape, int escapeLength, java.text.RuleBasedCollator collator)
           
private static boolean matchSpecial(int[] pat, int patStart, int patEnd, int[] specialInts)
          matchSpecial check the pattern against the various special character arrays.
static java.lang.String stripEscapesNoPatternChars(java.lang.String pattern, char escChar)
          stripEscapesNoPatternChars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

anyChar

private static final char anyChar
See Also:
Constant Field Values

anyString

private static final char anyString
See Also:
Constant Field Values

SUPER_STRING

private static final java.lang.String SUPER_STRING
See Also:
Constant Field Values
Constructor Detail

Like

private Like()
Method Detail

like

public static java.lang.Boolean like(char[] val,
                                     int valLength,
                                     char[] pat,
                                     int patLength,
                                     char[] escape,
                                     int escapeLength)
                              throws StandardException
Parameters:
val - value to compare. if null, result is null.
valLength - length of val
pat - pattern to compare. if null, result is null.
patLength - length of pat
escape - escape character. Must be 1 char long. if null, no escape character is used.
escapeLength - length of escape
Returns:
null if val or pat null, otherwise true if match and false if not.
Throws:
StandardException - thrown if data invalid

like

public static java.lang.Boolean like(int[] val,
                                     int valLength,
                                     int[] pat,
                                     int patLength,
                                     int[] escape,
                                     int escapeLength,
                                     java.text.RuleBasedCollator collator)
                              throws StandardException
For national chars.

Parameters:
val - value to compare. if null, result is null.
valLength - length of val
pat - pattern to compare. if null, result is null.
patLength - length of pat
escape - escape character. Must be 1 char long. if null, no escape character is used.
escapeLength - length of escape
collator - The collator to use.
Returns:
null if val or pat null, otherwise true if match and false if not.
Throws:
StandardException - thrown if data invalid

like

private static java.lang.Boolean like(char[] val,
                                      int vLoc,
                                      int vEnd,
                                      char[] pat,
                                      int pLoc,
                                      int pEnd,
                                      char[] escape,
                                      int escapeLength)
                               throws StandardException
Throws:
StandardException

like

private static java.lang.Boolean like(int[] val,
                                      int vLoc,
                                      int vEnd,
                                      int[] pat,
                                      int pLoc,
                                      int pEnd,
                                      int[] escape,
                                      int escapeLength,
                                      java.text.RuleBasedCollator collator)
                               throws StandardException
Throws:
StandardException

getMinLen

static int getMinLen(char[] pattern,
                     int pStart,
                     int pEnd,
                     boolean haveEsc,
                     char escChar)
Calculate the shortest length string that could match this pattern for non-national chars


getMinLen

static int getMinLen(int[] pattern,
                     int pStart,
                     int pEnd,
                     boolean haveEsc,
                     int[] escCharInts,
                     int[] anyStringInts)
Calculate the shortest length string that could match this pattern for national chars


checkLengths

static java.lang.Boolean checkLengths(int vLoc,
                                      int vEnd,
                                      int pLoc,
                                      char[] pat,
                                      int pEnd)
checkLengths -- non-national chars Returns null if we are not done. Returns true if we are at the end of our value and pattern Returns false if there is more pattern left but out of input value

Parameters:
vLoc - current index into char[] val
vEnd - end index or our value
pLoc - current index into our char[] pattern
pat - pattern char []
pEnd - end index of our pattern []

checkLengths

static java.lang.Boolean checkLengths(int vLoc,
                                      int vEnd,
                                      int pLoc,
                                      int[] pat,
                                      int pEnd,
                                      int[] anyStringInts)
checkLengths -- national chars Returns null if we are not done. Returns true if we are at the end of our value and pattern Returns false if there is more pattern left but out of input value

Parameters:
vLoc - current index into int[] val
vEnd - end index or our value
pLoc - current index into our int[] pattern
pat - pattern int []
pEnd - end index of our pattern []

matchSpecial

private static boolean matchSpecial(int[] pat,
                                    int patStart,
                                    int patEnd,
                                    int[] specialInts)
matchSpecial check the pattern against the various special character arrays. The array can be anyStringInts, anyCharInts or anyEscChars (always 1)


like

public static java.lang.Boolean like(char[] value,
                                     int valueLength,
                                     char[] pattern,
                                     int patternLength)
                              throws StandardException
Throws:
StandardException

like

public static java.lang.Boolean like(int[] value,
                                     int valueLength,
                                     int[] pattern,
                                     int patternLength,
                                     java.text.RuleBasedCollator collator)
                              throws StandardException
Throws:
StandardException

isOptimizable

public static boolean isOptimizable(java.lang.String pattern)
Determine whether or not this LIKE can be transformed into optimizable clauses. It can if the pattern is non-null, of length > 0 and the first character is not a wild card.

Parameters:
pattern - The right side of the LIKE
Returns:
Whether or not the LIKE can be transformed

greaterEqualStringFromParameter

public static java.lang.String greaterEqualStringFromParameter(java.lang.String pattern)
                                                        throws StandardException
Throws:
StandardException

greaterEqualStringFromParameterWithEsc

public static java.lang.String greaterEqualStringFromParameterWithEsc(java.lang.String pattern,
                                                                      java.lang.String escape)
                                                               throws StandardException
Throws:
StandardException

greaterEqualString

public static java.lang.String greaterEqualString(java.lang.String pattern,
                                                  java.lang.String escape)
                                           throws StandardException
Return the substring from the pattern for the optimization >= clause.

Parameters:
pattern - The right side of the LIKE
escape - The escape clause
Returns:
The String for the >= clause
Throws:
StandardException

greaterEqualString

private static java.lang.String greaterEqualString(java.lang.String pattern,
                                                   char escChar)
                                            throws StandardException
greaterEqualString -- for Escape clause only Walk the pattern character by character

Parameters:
pattern - like pattern to build from
escChar - the escape character in the pattern
Throws:
StandardException

stripEscapesNoPatternChars

public static java.lang.String stripEscapesNoPatternChars(java.lang.String pattern,
                                                          char escChar)
                                                   throws StandardException
stripEscapesNoPatternChars

Parameters:
pattern - pattern String to search
escChar - the escape character
Returns:
a stripped of ESC char string if no pattern chars, null otherwise
Throws:
StandardException - thrown if data invalid

lessThanString

public static java.lang.String lessThanString(java.lang.String pattern)
                                       throws StandardException
Return the substring from the pattern for the < clause. (NOTE: This may be null in the degenerate case where the last char before the first wild card can't be incremented.) Optimized for ESCAPE This function uses the greaterThanString, and bumps its last character by one. This string has no escape characters, they were stripped out, and ends just before any real pattern chars or at the end of the pattern literal. See LikeEscapeOp*Node.preprocess.

Parameters:
pattern - The right side of the LIKE
Returns:
The String for the < clause
Throws:
StandardException - thrown if data invalid

lessThanStringFromParameter

public static java.lang.String lessThanStringFromParameter(java.lang.String pattern)
                                                    throws StandardException
Throws:
StandardException

lessThanStringFromParameterWithEsc

public static java.lang.String lessThanStringFromParameterWithEsc(java.lang.String pattern,
                                                                  java.lang.String escape)
                                                           throws StandardException
Throws:
StandardException

lessThanString

public static java.lang.String lessThanString(java.lang.String pattern,
                                              java.lang.String escape)
                                       throws StandardException
Return the substring from the pattern for the < clause. (NOTE: This may be null in the degenerate case where the last char before the first wild card can't be incremented.) This is unoptimized for ESCAPE.

Parameters:
pattern - The right side of the LIKE
escape - The escape clause
Returns:
The String for the < clause
Throws:
StandardException - thrown if data invalid

isLikeComparisonNeeded

public static boolean isLikeComparisonNeeded(java.lang.String pattern)
Return whether or not the like comparison is still needed after performing the like transformation on a constant string. The comparison is not needed if the constant string is of the form: CONSTANT% (constant followed by a trailing %)

Parameters:
pattern - The right side of the LIKE
Returns:
Whether or not the like comparison is still needed.

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.