Top Description Fields Constructors Methods
org.apache.derby.iapi.types

public Class Like

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, java.text.CollationElementIterator, .Collator, .RuleBasedCollator, java.util.Locale

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

Field Summary

Modifier and TypeField and Description
private static final char
private static final char
private static final String

Constructor Summary

AccessConstructor and Description
private
Like()

Method Summary

Modifier and TypeMethod and Description
private static boolean

Returns:

TRUE if the character in val and vLoc match based on straight equality or collation element based equality. Otherwise we will return FALSE.
checkEquality
(char[]
value to compare.
val
,
int
character position in val.
vLoc
,
char[]
pattern to look for in val.
pat
,
int
character position in pat.
pLoc
,
RuleBasedCollator
null if we are dealing with UCS_BASIC character string types. If not null, then we use it to determine the equality of the 2 characters in pat and val if they are not same.
collator
)

If the character in val matches the character in pat, then it does not matter if the database is UCS_BASIC or territory based, we simply return TRUE from the method.

pack-priv static Boolean
checkLengths(int
current index into char[] val
vLoc
,
int
end index or our value
vEnd
,
int
current index into our char[] pattern
pLoc
,
char[]
pattern char []
pat
,
int
end index of our pattern []
pEnd
)

checkLengths Returns null if we are not done.

pack-priv static int
getMinLen(char[] pattern, int pStart, int pEnd, boolean haveEsc, char escChar)

Calculate the shortest length string that could match this pattern

public static String

Returns:

The String for the >= clause
greaterEqualString
(String
The right side of the LIKE
pattern
,
String
The escape clause
escape
,
int
Maximum length of column, for null padding
maxWidth
)

Return the substring from the pattern for the optimization >= clause.

private static String
greaterEqualString(String
like pattern to build from
pattern
,
char
the escape character in the pattern
escChar
)

greaterEqualString -- for Escape clause only Walk the pattern character by character

public static String
greaterEqualStringFromParameter(String pattern, int maxWidth)

public static String
greaterEqualStringFromParameterWithEsc(String pattern, String escape, int maxWidth)

public static boolean

Returns:

Whether or not the like comparison is still needed.
isLikeComparisonNeeded
(String
The right side of the LIKE
pattern
)

Return whether or not the like comparison is still needed after performing the like transformation on a constant string.

public static boolean

Returns:

Whether or not the LIKE can be transformed
isOptimizable
(String
The right side of the LIKE
pattern
)

Determine whether or not this LIKE can be transformed into optimizable clauses.

public static String

Returns:

The String for the < clause
lessThanString
(String
The right side of the LIKE
pattern
,
String
The escape clause
escape
,
int
Maximum length of column, for null padding
maxWidth
)

Return the substring from the pattern for the < clause.

public static String
lessThanStringFromParameter(String pattern, int maxWidth)

public static String
lessThanStringFromParameterWithEsc(String pattern, String escape, int maxWidth)

public static Boolean

Returns:

null if val or pat null, otherwise true if match and false if not.
like
(char[]
value to compare. if null, result is null.
val
,
int
length of val
valLength
,
char[]
pattern to compare. if null, result is null.
pat
,
int
length of pat
patLength
,
char[]
escape character. Must be 1 char long. if null, no escape character is used.
escape
,
int
length of escape
escapeLength
,
RuleBasedCollator
null if we are dealing with UCS_BASIC character string types. If not null, then we use it to get collation elements for characters in val and non-metacharacters in pat to do the comparison.
collator
)

This method gets called for UCS_BASIC and territory based character string types to look for a pattern in a value string.

private static Boolean
like(char[] val, int vLoc, int vEnd, char[] pat, int pLoc, int pEnd, char[] escape, int escapeLength, RuleBasedCollator collator)

public static Boolean
like(char[] value, int valueLength, char[] pattern, int patternLength, RuleBasedCollator collator)

private static String

Returns:

the string padded with 0s up to the given length
padWithNulls
(String
The string to pad
string
,
int
Max number of characters to pad to
len
)

Pad a string with null characters, in order to make it > and < comparable with SQLChar.

public static String

Returns:

a stripped of ESC char string if no pattern chars, null otherwise
stripEscapesNoPatternChars
(String
pattern String to search
pattern
,
char
the escape character
escChar
)

stripEscapesNoPatternChars

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

anyCharback to summary
private static final char anyChar
anyStringback to summary
private static final char anyString
SUPER_STRINGback to summary
private static final String SUPER_STRING

Constructor Detail

Likeback to summary
private Like()

Method Detail

checkEqualityback to summary
private static boolean checkEquality(char[] val, int vLoc, char[] pat, int pLoc, RuleBasedCollator collator)

If the character in val matches the character in pat, then it does not matter if the database is UCS_BASIC or territory based, we simply return TRUE from the method. If the characters do not match and we are running with UCS_BASIC collation, then we will return FALSE. But if the database is territory based, then we want to use the Collator for the territory to determine if the Collator treats the 2 characters as equal (ie if their collation elements match, then the 2 characters are equal even if they are not the same character).

Parameters
val:char[]

value to compare.

vLoc:int

character position in val.

pat:char[]

pattern to look for in val.

pLoc:int

character position in pat.

collator:RuleBasedCollator

null if we are dealing with UCS_BASIC character string types. If not null, then we use it to determine the equality of the 2 characters in pat and val if they are not same.

Returns:boolean

TRUE if the character in val and vLoc match based on straight equality or collation element based equality. Otherwise we will return FALSE.

checkLengthsback to summary
pack-priv static Boolean checkLengths(int vLoc, int vEnd, int pLoc, char[] pat, int pEnd)

checkLengths 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:int

current index into char[] val

vEnd:int

end index or our value

pLoc:int

current index into our char[] pattern

pat:char[]

pattern char []

pEnd:int

end index of our pattern []

getMinLenback to summary
pack-priv static int getMinLen(char[] pattern, int pStart, int pEnd, boolean haveEsc, char escChar)

Calculate the shortest length string that could match this pattern

greaterEqualStringback to summary
public static String greaterEqualString(String pattern, String escape, int maxWidth) throws StandardException

Return the substring from the pattern for the optimization >= clause.

Parameters
pattern:String

The right side of the LIKE

escape:String

The escape clause

maxWidth:int

Maximum length of column, for null padding

Returns:String

The String for the >= clause

greaterEqualStringback to summary
private static String greaterEqualString(String pattern, char escChar) throws StandardException

greaterEqualString -- for Escape clause only Walk the pattern character by character

Parameters
pattern:String

like pattern to build from

escChar:char

the escape character in the pattern

greaterEqualStringFromParameterback to summary
public static String greaterEqualStringFromParameter(String pattern, int maxWidth) throws StandardException
greaterEqualStringFromParameterWithEscback to summary
public static String greaterEqualStringFromParameterWithEsc(String pattern, String escape, int maxWidth) throws StandardException
isLikeComparisonNeededback to summary
public static boolean isLikeComparisonNeeded(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:String

The right side of the LIKE

Returns:boolean

Whether or not the like comparison is still needed.

isOptimizableback to summary
public static boolean isOptimizable(String pattern)

Determine whether or not this LIKE can be transformed into optimizable clauses. It can if the pattern is non-null and if the length == 0 or the first character is not a wild card.

Parameters
pattern:String

The right side of the LIKE

Returns:boolean

Whether or not the LIKE can be transformed

lessThanStringback to summary
public static String lessThanString(String pattern, String escape, int maxWidth) throws StandardException

Return the substring from the pattern for the < clause.

Parameters
pattern:String

The right side of the LIKE

escape:String

The escape clause

maxWidth:int

Maximum length of column, for null padding

Returns:String

The String for the < clause

Exceptions
StandardException:
thrown if data invalid
lessThanStringFromParameterback to summary
public static String lessThanStringFromParameter(String pattern, int maxWidth) throws StandardException
lessThanStringFromParameterWithEscback to summary
public static String lessThanStringFromParameterWithEsc(String pattern, String escape, int maxWidth) throws StandardException
likeback to summary
public static Boolean like(char[] val, int valLength, char[] pat, int patLength, char[] escape, int escapeLength, RuleBasedCollator collator) throws StandardException

This method gets called for UCS_BASIC and territory based character string types to look for a pattern in a value string. It also deals with escape character if user has provided one.

Parameters
val:char[]

value to compare. if null, result is null.

valLength:int

length of val

pat:char[]

pattern to compare. if null, result is null.

patLength:int

length of pat

escape:char[]

escape character. Must be 1 char long. if null, no escape character is used.

escapeLength:int

length of escape

collator:RuleBasedCollator

null if we are dealing with UCS_BASIC character string types. If not null, then we use it to get collation elements for characters in val and non-metacharacters in pat to do the comparison.

Returns:Boolean

null if val or pat null, otherwise true if match and false if not.

Exceptions
StandardException:
thrown if data invalid
likeback to summary
private static Boolean like(char[] val, int vLoc, int vEnd, char[] pat, int pLoc, int pEnd, char[] escape, int escapeLength, RuleBasedCollator collator) throws StandardException
likeback to summary
public static Boolean like(char[] value, int valueLength, char[] pattern, int patternLength, RuleBasedCollator collator) throws StandardException
padWithNullsback to summary
private static String padWithNulls(String string, int len)

Pad a string with null characters, in order to make it > and < comparable with SQLChar.

Parameters
string:String

The string to pad

len:int

Max number of characters to pad to

Returns:String

the string padded with 0s up to the given length

stripEscapesNoPatternCharsback to summary
public static String stripEscapesNoPatternChars(String pattern, char escChar) throws StandardException

stripEscapesNoPatternChars

Parameters
pattern:String

pattern String to search

escChar:char

the escape character

Returns:String

a stripped of ESC char string if no pattern chars, null otherwise

Exceptions
StandardException:
thrown if data invalid