com.ptc.windchill.enterprise.search.server
Class WhereClauseHandler

java.lang.Object
  extended bycom.ptc.windchill.enterprise.search.server.WhereClauseHandler
All Implemented Interfaces:
Externalizable, Serializable

final class WhereClauseHandler
extends Object
implements Externalizable

Translates the where clause from the client into AttributeContainerSets

Supported API: false

Extendable: false


Field Summary
private static String ATTR_NAME_REG_EX
          one or more characters until the next !, =, < or >
private static String CLASSNAME
           
private static Pattern DOUBLE_PAREN_PATTERN
          2 open parens followed by 0..1 search terms followed by 2 close parnes
private static Pattern EMPTY_TERM_PATTERN
          ()|,()&,|(),&()
static long EXTERNALIZATION_VERSION_UID
           
private static Pattern FAKE_CREATOR_REGEX
           
private static Pattern FAKE_NAME_REGEX
           
private static Pattern FAKE_NUMBER_REGEX
           
protected static long OLD_FORMAT_VERSION_UID
           
private static String OPERATOR_REG_EX
          !=,<=,>=,=,<,>
private static Hashtable PROPERTY_DESCRIPTOR_CACHE
          Cache of property descriptors.
private static String RESOURCE
           
(package private) static long serialVersionUID
           
private static DefaultFeedbackSpec SPEC
          Feedback spec for PrepareEntityCommand.
private static String TERM_REG_EX
          represents a valid search term attributeName='value'
private static String TERM_VALUE_REG_EX
          ', then everything up until next unescaped '
private static Pattern TOKEN_PATTERN
          (,),&,|,valid operators,valid attribute names,valid values
private static Pattern UNNECESSARY_ESCAPE_PATTERN
          a non \ character, followed by an odd number of \s, followed by a invalid escape character (not \,% or _)
private static Pattern VALID_WHERE_CLAUSE_PATTERN
          0..* parens followed by 0..1 search terms followed by 0..* parens, then 0..* additional parened search terms preceeded with an & or |
 
Constructor Summary
(package private) WhereClauseHandler()
           
 
Method Summary
private static String buildWhereClause(String cacheKey, String typename)
          Creates sub-where clause for attributes mapped in SearchableAttribtuesByType cache.
private static AttributeContainerSet createAttributeContainerSetFromTerm(Stack whereStack, String rightStr, SearchInfo searchInfo)
          Given a left='right' expression, return an AttributeContainerSet representing that search term.
private static AttributeContainerSet createCompositeAttributeContainerSet(Stack whereStack, SearchInfo searchInfo, boolean isUnion, boolean errorOnEmpty)
          Creates a AttributeContainerSet out of all AttributeContainerSets in the stack, up until the next open paren is encountered.
private static String escapeAndAliasSpecialCharacters(String whereClause, TypeIdentifier attributeTypeContext)
          Given a where clause, perform the following: 1) remove "fake" attribute name prefixes 2) replace all unescaped asterisks with percents 3) unescape escaped asterisks
private static Class getClassForAttributeType(AttributeTypeIdentifier attrTypeId)
          Given an AttributeTypeIdentifier return its property type.
private static Object getDateFromValue(Object value, AttributeTypeIdentifier ati)
          Given a value and an attribute determine if the attribute is of type java.sql.Timestamp and if it is return a Date object to be used as value to query against.
private static AttributeContainerSet getEqualsCriteria(AttributeTypeIdentifier[] atis, Object value, boolean negated)
          Creates an AttributeContainerSet for each name=value and name!=value term.
private static String getFormattedWhereClause(SearchInfo searchInfo)
          If the current search is a keyword search handles keyword" attribute.
private static AttributeContainerSet getGreaterThanLessThanCriteria(AttributeTypeIdentifier[] atis, Object right, boolean greaterThan, boolean inclusive)
          Returns an AttributeContainerSet for each namevalue or name >=value pair.
private static AttributeContainerSet getGreaterThanLessThanCriteria(AttributeTypeIdentifier ati, Object value, boolean greaterThan, boolean inclusive)
          Creates an AttributeContainerSet for the given attribute value pair.
private static Object getIBAValue(Object right, Locale locale, AttributeTypeIdentifier ati)
          Given an IBA attribute and it's value return the correct wrapper object to find the value in the database.
private static Timestamp getTimestamp(String value)
          Given a String value for a date of the form "yyyy-MM-dd" e.g., "2003-11-13" get a Timestamp object.
(package private) static AttributeContainerSet getWhereClauseCriteria(SearchInfo searchInfo)
          Generates where clause specific criteria for a search.
private static AttributeContainerSet getWildcardCriteria(AttributeTypeIdentifier[] atis, int wildcardMode, String pattern, boolean negated)
          Returns an AttributeContainerSet containing a criteria for each AttributeTypeIdentifier.
private static boolean isApplyUpperFunction(AttributeTypeIdentifier ati)
          Determines if an uppercase property is defined for the input AttributeTypeIdentifier.
private static AttributeContainerSet processWhereClause(SearchInfo searchInfo, String formattedWhereClause)
          Tokenizes the where clause.
 void readExternal(ObjectInput input)
          Reads the non-transient fields of this class from an external source.
private  boolean readOldVersion(ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
          Reads the non-transient fields of this class from an external source, which is not the current version.
protected  boolean readVersion(WhereClauseHandler thisObject, ObjectInput input, long readSerialVersionUID, boolean passThrough, boolean superDone)
          Reads the non-transient fields of this class from an external source.
private static String replaceFakeNameAndNumber(String whereClause, TypeIdentifier attributeTypeContext)
           
private static String simplifyWhereClause(String whereClause)
          Simplifies where clause for tokenizing.
 void writeExternal(ObjectOutput output)
          Writes the non-transient fields of this class to an external source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

ATTR_NAME_REG_EX

private static final String ATTR_NAME_REG_EX
one or more characters until the next !, =, < or >

See Also:
Constant Field Values

OPERATOR_REG_EX

private static final String OPERATOR_REG_EX
!=,<=,>=,=,<,>

See Also:
Constant Field Values

TERM_VALUE_REG_EX

private static final String TERM_VALUE_REG_EX
', then everything up until next unescaped '

See Also:
Constant Field Values

TERM_REG_EX

private static final String TERM_REG_EX
represents a valid search term attributeName='value'

See Also:
Constant Field Values

VALID_WHERE_CLAUSE_PATTERN

private static final Pattern VALID_WHERE_CLAUSE_PATTERN
0..* parens followed by 0..1 search terms followed by 0..* parens, then 0..* additional parened search terms preceeded with an & or |


DOUBLE_PAREN_PATTERN

private static final Pattern DOUBLE_PAREN_PATTERN
2 open parens followed by 0..1 search terms followed by 2 close parnes


EMPTY_TERM_PATTERN

private static final Pattern EMPTY_TERM_PATTERN
()|,()&,|(),&()


TOKEN_PATTERN

private static final Pattern TOKEN_PATTERN
(,),&,|,valid operators,valid attribute names,valid values


UNNECESSARY_ESCAPE_PATTERN

private static final Pattern UNNECESSARY_ESCAPE_PATTERN
a non \ character, followed by an odd number of \s, followed by a invalid escape character (not \,% or _)


PROPERTY_DESCRIPTOR_CACHE

private static final Hashtable PROPERTY_DESCRIPTOR_CACHE
Cache of property descriptors.


SPEC

private static final DefaultFeedbackSpec SPEC
Feedback spec for PrepareEntityCommand.


FAKE_NAME_REGEX

private static final Pattern FAKE_NAME_REGEX

FAKE_NUMBER_REGEX

private static final Pattern FAKE_NUMBER_REGEX

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

EXTERNALIZATION_VERSION_UID

public static final long EXTERNALIZATION_VERSION_UID
See Also:
Constant Field Values

OLD_FORMAT_VERSION_UID

protected static final long OLD_FORMAT_VERSION_UID
See Also:
Constant Field Values

FAKE_CREATOR_REGEX

private static final Pattern FAKE_CREATOR_REGEX
Constructor Detail

WhereClauseHandler

WhereClauseHandler()
Method Detail

writeExternal

public void writeExternal(ObjectOutput output)
                   throws IOException
Writes the non-transient fields of this class to an external source.

Supported API: false

Specified by:
writeExternal in interface Externalizable
Parameters:
output -
Throws:
IOException

readExternal

public void readExternal(ObjectInput input)
                  throws IOException,
                         ClassNotFoundException
Reads the non-transient fields of this class from an external source.

Supported API: false

Specified by:
readExternal in interface Externalizable
Parameters:
input -
Throws:
IOException
ClassNotFoundException

readVersion

protected boolean readVersion(WhereClauseHandler thisObject,
                              ObjectInput input,
                              long readSerialVersionUID,
                              boolean passThrough,
                              boolean superDone)
                       throws IOException,
                              ClassNotFoundException
Reads the non-transient fields of this class from an external source.

Supported API: false

Parameters:
thisObject -
input -
readSerialVersionUID -
passThrough -
superDone -
Returns:
boolean
Throws:
IOException
ClassNotFoundException

readOldVersion

private boolean readOldVersion(ObjectInput input,
                               long readSerialVersionUID,
                               boolean passThrough,
                               boolean superDone)
                        throws IOException,
                               ClassNotFoundException
Reads the non-transient fields of this class from an external source, which is not the current version.

Parameters:
input -
readSerialVersionUID -
passThrough -
superDone -
Returns:
boolean
Throws:
IOException
ClassNotFoundException

getWhereClauseCriteria

static AttributeContainerSet getWhereClauseCriteria(SearchInfo searchInfo)
                                             throws WTException
Generates where clause specific criteria for a search.

Supported API: false

Parameters:
searchInfo -
Returns:
AttributeContainerSet
Throws:
WTException

getFormattedWhereClause

private static String getFormattedWhereClause(SearchInfo searchInfo)
                                       throws WTException
If the current search is a keyword search handles keyword" attribute. Also, handles any logical attributes containing "fake" values. In both cases, a new where clause is created that is properly formatted.

Parameters:
searchInfo -
Returns:
String
Throws:
WTException

escapeAndAliasSpecialCharacters

private static String escapeAndAliasSpecialCharacters(String whereClause,
                                                      TypeIdentifier attributeTypeContext)
Given a where clause, perform the following: 1) remove "fake" attribute name prefixes 2) replace all unescaped asterisks with percents 3) unescape escaped asterisks

Parameters:
whereClause -
attributeTypeContext - Pass the TypeIdentifier in so we can get the alias information from the properties cache
Returns:
String

simplifyWhereClause

private static String simplifyWhereClause(String whereClause)
Simplifies where clause for tokenizing. Removes extra parens ((name='G%')) ==> (name='G%') and empty terms (name='G%')&() ==> (name='G%').

Parameters:
whereClause -
Returns:
String

processWhereClause

private static AttributeContainerSet processWhereClause(SearchInfo searchInfo,
                                                        String formattedWhereClause)
                                                 throws WTException
Tokenizes the where clause. Parens, operators, attribute names and attribute values all represent tokens. (name='G%') ==> [ ( ] [ name ] [ = ] [ 'G%' ] [ ) ] Then we step through the tokens, pushing them onto the stack until we hit a close paren. If we hit a close paren or a change in operator, we start popping tokens. If the first popped token is a String, we pop tokens off the stack to create an AttributeContainerSet from the search term. If the popped token is an ACS, we create a CompositeAttributeContainerSet out of all ACSs up until the next open paren and then push it back onto the stack. When we have processed all tokens, we know the stack only consists of ACSs and we create a CompositeAttributeContainerSet out of the ACSs on the stack.

Parameters:
searchInfo -
formattedWhereClause -
Returns:
AttributeContainerSet
Throws:
WTException

createCompositeAttributeContainerSet

private static AttributeContainerSet createCompositeAttributeContainerSet(Stack whereStack,
                                                                          SearchInfo searchInfo,
                                                                          boolean isUnion,
                                                                          boolean errorOnEmpty)
                                                                   throws WTException
Creates a AttributeContainerSet out of all AttributeContainerSets in the stack, up until the next open paren is encountered.

Parameters:
whereStack -
searchInfo -
isUnion -
errorOnEmpty -
Returns:
AttributeContainerSet
Throws:
WTException

createAttributeContainerSetFromTerm

private static AttributeContainerSet createAttributeContainerSetFromTerm(Stack whereStack,
                                                                         String rightStr,
                                                                         SearchInfo searchInfo)
                                                                  throws WTException
Given a left='right' expression, return an AttributeContainerSet representing that search term.

Parameters:
whereStack -
rightStr -
searchInfo -
Returns:
AttributeContainerSet
Throws:
WTException

getClassForAttributeType

private static Class getClassForAttributeType(AttributeTypeIdentifier attrTypeId)
                                       throws WTException
Given an AttributeTypeIdentifier return its property type.

Parameters:
attrTypeId -
Returns:
Class
Throws:
WTException

getIBAValue

private static Object getIBAValue(Object right,
                                  Locale locale,
                                  AttributeTypeIdentifier ati)
                           throws WTException
Given an IBA attribute and it's value return the correct wrapper object to find the value in the database.

Parameters:
right -
locale -
ati -
Returns:
Object
Throws:
WTException

getTimestamp

private static Timestamp getTimestamp(String value)
                               throws WTException
Given a String value for a date of the form "yyyy-MM-dd" e.g., "2003-11-13" get a Timestamp object. If the user has defined a time zone preference and the user's locale can be determined then create a Timestamp that accounts for that information. If either the user's locale or time zone can't be determined then use the server's locale and time zone. If no time zone is defined for the server then default to Greenwich Mean Time.

Parameters:
value -
Returns:
Timestamp
Throws:
WTException

getWildcardCriteria

private static AttributeContainerSet getWildcardCriteria(AttributeTypeIdentifier[] atis,
                                                         int wildcardMode,
                                                         String pattern,
                                                         boolean negated)
                                                  throws WTException
Returns an AttributeContainerSet containing a criteria for each AttributeTypeIdentifier.

Parameters:
atis -
wildcardMode -
pattern -
negated -
Returns:
AttributeContainerSet
Throws:
WTException

getEqualsCriteria

private static AttributeContainerSet getEqualsCriteria(AttributeTypeIdentifier[] atis,
                                                       Object value,
                                                       boolean negated)
                                                throws WTException
Creates an AttributeContainerSet for each name=value and name!=value term.

Parameters:
atis -
value -
negated -
Returns:
AttributeContainerSet
Throws:
WTException

getDateFromValue

private static Object getDateFromValue(Object value,
                                       AttributeTypeIdentifier ati)
                                throws WTException
Given a value and an attribute determine if the attribute is of type java.sql.Timestamp and if it is return a Date object to be used as value to query against.

Parameters:
value -
ati -
Returns:
Object
Throws:
WTException

getGreaterThanLessThanCriteria

private static AttributeContainerSet getGreaterThanLessThanCriteria(AttributeTypeIdentifier[] atis,
                                                                    Object right,
                                                                    boolean greaterThan,
                                                                    boolean inclusive)
                                                             throws WTException
Returns an AttributeContainerSet for each namevalue or name >=value pair.

Parameters:
atis -
right -
greaterThan -
inclusive -
Returns:
AttributeContainerSet
Throws:
WTException

getGreaterThanLessThanCriteria

private static AttributeContainerSet getGreaterThanLessThanCriteria(AttributeTypeIdentifier ati,
                                                                    Object value,
                                                                    boolean greaterThan,
                                                                    boolean inclusive)
                                                             throws WTException
Creates an AttributeContainerSet for the given attribute value pair.

Parameters:
ati -
value -
greaterThan -
inclusive -
Returns:
AttributeContainerSet
Throws:
WTException

isApplyUpperFunction

private static boolean isApplyUpperFunction(AttributeTypeIdentifier ati)
                                     throws WTException
Determines if an uppercase property is defined for the input AttributeTypeIdentifier.

Parameters:
ati -
Returns:
boolean
Throws:
WTException

replaceFakeNameAndNumber

private static String replaceFakeNameAndNumber(String whereClause,
                                               TypeIdentifier attributeTypeContext)
Parameters:
whereClause -
attributeTypeContext -
Returns:
String

buildWhereClause

private static String buildWhereClause(String cacheKey,
                                       String typename)
Creates sub-where clause for attributes mapped in SearchableAttribtuesByType cache.

Parameters:
cacheKey -
typename -
Returns:
String