© 2002 BEA Systems, Inc.


com.beasys.commerce.ebusiness.catalog.service.query
Class QueryHelper

java.lang.Object
  |
  +--com.beasys.commerce.ebusiness.catalog.service.query.QueryHelper

public class QueryHelper
extends java.lang.Object

Helper class for performing Product Catalog queries.


Field Summary
static java.lang.String DEFAULT_ENTITY_ID_TABLE_NAME
          The default entity identifier table
static java.lang.String DEFAULT_PROPERTY_BOOLEAN_COLUMN_NAME
          The default boolean property table
static java.lang.String DEFAULT_PROPERTY_DATETIME_COLUMN_NAME
          The default date/time property table
static java.lang.String DEFAULT_PROPERTY_FLOAT_COLUMN_NAME
          The default float property table
static java.lang.String DEFAULT_PROPERTY_ID_TABLE_NAME
          The default property identifier table
static java.lang.String DEFAULT_PROPERTY_INTEGER_COLUMN_NAME
          The default integer property table
static java.lang.String DEFAULT_PROPERTY_TEXT_COLUMN_NAME
          The default text property table
static java.lang.String DEFAULT_PROPERTY_VALUE_TABLE
          The default property table
static java.lang.String DEFAULT_TABLE_PREFIX
          The default table prefix
 
Constructor Summary
QueryHelper(JdbcCatalogFactory jdbcCatFac, java.lang.Boolean supportsLikeEscapeClause)
           
 
Method Summary
static java.util.List fixKeywords(java.lang.String[] keywords)
          Fix up an array of keywords by removing nulls and duplicates.
protected  java.lang.StringBuffer getSearchSQL(boolean showAll, java.util.List params, boolean isCategory)
          Get the SQL where clause for the showAll parameter.
protected  java.lang.StringBuffer getSearchSQL(Expression expr, java.lang.String prefix, boolean supportsLikeEscapeClause, java.util.List params, boolean isCategory)
          Get the SQL where clause for an expression.
protected  java.lang.StringBuffer getSearchSQL(java.util.List keywords, java.lang.String logical, java.util.List params)
          Get the SQL where clause for the keywords.
protected  void getSearchSQL(java.lang.StringBuffer buf, Criteria c, java.lang.String prefix, boolean supportsLikeEscapeClause, java.util.List params, boolean isCategory)
          Get the SQL where clause for a Criteria.
protected  void getSearchSQL(java.lang.StringBuffer buf, Expression expr, java.lang.String prefix, boolean supportsLikeEscapeClause, java.util.List params, boolean isCategory)
          Get the SQL where clause for an expression.
protected  void getSearchSQL(java.lang.StringBuffer buf, Logical l, java.lang.String prefix, boolean supportsLikeEscapeClause, java.util.List params, boolean isCategory)
          Get the SQL where clause for a Criteria.
protected  void getSearchSQL(java.lang.StringBuffer buf, java.lang.String prefix, boolean supportsLikeEscapeClause, java.lang.String column, java.lang.String scope, java.lang.String name, java.lang.String op, java.lang.Object val, java.util.List params, boolean isCategory)
          Get the SQL for searching for an implicit property in a certain WLCS_PROP_* table.
protected  java.lang.StringBuffer getSearchSQL(java.lang.String lang, java.util.List params, boolean isCategory)
          Get the SQL where clause for the lang parameter.
static java.lang.String getSQLOperator(java.lang.String c)
          Return the corresponding SQL operator for the given comparator.
static boolean isLegalSingleValueComparator(java.lang.String c)
          Determine if a comparator is legal, single-value attribute comparator.
static void main(java.lang.String[] args)
          Quick unit test of keyword search.
 java.util.List search(java.sql.Connection con, boolean showAll, java.lang.String lang, Expression expr, java.lang.String tablePrefix)
          Perform an expression search.
 java.util.List search(java.sql.Connection con, boolean showAll, java.lang.String lang, java.util.List keywords)
          Perform an AND'ed keyword search.
 java.util.List search(java.sql.Connection con, boolean showAll, java.lang.String lang, java.util.List keywords, java.lang.String logical)
          Perform a keyword search.
 java.util.List search(java.sql.Connection con, boolean showAll, java.lang.String lang, java.util.List keywords, java.lang.String logical, Expression expr, java.lang.String tablePrefix, int maxSearchResults)
          Perform a search
 java.util.List search(java.sql.Connection con, boolean showAll, java.lang.String lang, java.lang.String logical, Expression expr, java.lang.String tablePrefix, int maxSearchResults)
          Perform a search
static java.lang.Object toSQLLike(java.lang.Object obj, boolean supportsLikeEscapeClause)
          Convert an object, which might be a string, to a SQL like string.
static java.lang.String toSQLLike(java.lang.String like, boolean supportsLikeEscapeClause)
          Convert a query LIKE value to a SQL LIKE value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENTITY_ID_TABLE_NAME

public static final java.lang.String DEFAULT_ENTITY_ID_TABLE_NAME
The default entity identifier table

DEFAULT_PROPERTY_ID_TABLE_NAME

public static final java.lang.String DEFAULT_PROPERTY_ID_TABLE_NAME
The default property identifier table

DEFAULT_PROPERTY_VALUE_TABLE

public static final java.lang.String DEFAULT_PROPERTY_VALUE_TABLE
The default property table

DEFAULT_PROPERTY_BOOLEAN_COLUMN_NAME

public static final java.lang.String DEFAULT_PROPERTY_BOOLEAN_COLUMN_NAME
The default boolean property table

DEFAULT_PROPERTY_INTEGER_COLUMN_NAME

public static final java.lang.String DEFAULT_PROPERTY_INTEGER_COLUMN_NAME
The default integer property table

DEFAULT_PROPERTY_FLOAT_COLUMN_NAME

public static final java.lang.String DEFAULT_PROPERTY_FLOAT_COLUMN_NAME
The default float property table

DEFAULT_PROPERTY_TEXT_COLUMN_NAME

public static final java.lang.String DEFAULT_PROPERTY_TEXT_COLUMN_NAME
The default text property table

DEFAULT_PROPERTY_DATETIME_COLUMN_NAME

public static final java.lang.String DEFAULT_PROPERTY_DATETIME_COLUMN_NAME
The default date/time property table

DEFAULT_TABLE_PREFIX

public static final java.lang.String DEFAULT_TABLE_PREFIX
The default table prefix
Constructor Detail

QueryHelper

public QueryHelper(JdbcCatalogFactory jdbcCatFac,
                   java.lang.Boolean supportsLikeEscapeClause)
Method Detail

fixKeywords

public static java.util.List fixKeywords(java.lang.String[] keywords)
Fix up an array of keywords by removing nulls and duplicates.

Parameters:
keywords - the array of keywords.
Returns:
the cleaned-up list of keywords.

search

public java.util.List search(java.sql.Connection con,
                             boolean showAll,
                             java.lang.String lang,
                             java.lang.String logical,
                             Expression expr,
                             java.lang.String tablePrefix,
                             int maxSearchResults)
                      throws CatalogException
Perform a search

Parameters:
con - the database connection to use.
showAll - true to show invisible items, false to not.
lang - the language to match on (null for any).
keywords - the list of keywords (no nulls, no duplicates, null for none).
logical - TypesHelper.AND or TypesHelper.OR (for keywords).
expr - the query expression to use (already normalized, null for none).
tablePrefix - the table prefix for the ConfigurableEntity tables for implicit properties.
Returns:
the list of ProductItemKeys of the items that match.
See Also:
TypesHelper

search

public java.util.List search(java.sql.Connection con,
                             boolean showAll,
                             java.lang.String lang,
                             java.util.List keywords,
                             java.lang.String logical,
                             Expression expr,
                             java.lang.String tablePrefix,
                             int maxSearchResults)
                      throws CatalogException
Perform a search

Parameters:
con - the database connection to use.
showAll - true to show invisible items, false to not.
lang - the language to match on (null for any).
keywords - the list of keywords (no nulls, no duplicates, null for none).
logical - TypesHelper.AND or TypesHelper.OR (for keywords).
expr - the query expression to use (already normalized, null for none).
tablePrefix - the table prefix for the ConfigurableEntity tables for implicit properties.
Returns:
the list of ProductItemKeys of the items that match.
See Also:
TypesHelper

search

public java.util.List search(java.sql.Connection con,
                             boolean showAll,
                             java.lang.String lang,
                             java.util.List keywords,
                             java.lang.String logical)
                      throws CatalogException
Perform a keyword search.

Parameters:
con - the database connection to use.
showAll - true to show invisible items, false to not.
lang - the language to match on (null for any).
keywords - the list of keywords (no nulls, no duplicates).
logical - TypesHelper.AND or TypesHelper.OR.
Returns:
the list of ProductItemKeys of the items that match.

search

public java.util.List search(java.sql.Connection con,
                             boolean showAll,
                             java.lang.String lang,
                             java.util.List keywords)
                      throws CatalogException
Perform an AND'ed keyword search.

Parameters:
con - the database connection to use.
showAll - true to show invisible items, false to not.
lang - the language to match on (null for any).
keywords - the list of keywords (no nulls, no duplicates).
Returns:
the list of ProductItemKeys of the items that match.

search

public java.util.List search(java.sql.Connection con,
                             boolean showAll,
                             java.lang.String lang,
                             Expression expr,
                             java.lang.String tablePrefix)
                      throws CatalogException
Perform an expression search.

Parameters:
con - the database connection to use.
showAll - true to show invisible items, false to not.
lang - the language to match on (null for any).
expr - the normalized expression to use.
tablePrefix - the table prefix for the ConfigurableEntity tables for implicit properties.
Returns:
the list of ProductItemKeys of the items that match.

getSearchSQL

protected java.lang.StringBuffer getSearchSQL(boolean showAll,
                                              java.util.List params,
                                              boolean isCategory)
Get the SQL where clause for the showAll parameter.

Parameters:
showAll - whether to show invisible items (true), or not (false).
params - the list of prepared statement params to add to.
Returns:
the SQL where clause, or null if there shouldn't be one.

getSearchSQL

protected java.lang.StringBuffer getSearchSQL(java.lang.String lang,
                                              java.util.List params,
                                              boolean isCategory)
Get the SQL where clause for the lang parameter.

Parameters:
showAll - the lang (null for none).
params - the list of prepared statement params to add to.
Returns:
the SQL where clause, or null if there shouldn't be one.

getSearchSQL

protected java.lang.StringBuffer getSearchSQL(java.util.List keywords,
                                              java.lang.String logical,
                                              java.util.List params)
Get the SQL where clause for the keywords.

Parameters:
keywords - the list of keywords (no nulls, no duplicates, null for none).
logical - TypesHelper.AND or TypesHelper.OR (for keywords).
params - the list of prepared statement params to add to.
Returns:
the SQL where clause, or null if there shouldn't be one.

getSearchSQL

protected java.lang.StringBuffer getSearchSQL(Expression expr,
                                              java.lang.String prefix,
                                              boolean supportsLikeEscapeClause,
                                              java.util.List params,
                                              boolean isCategory)
                                       throws CatalogException
Get the SQL where clause for an expression.

Parameters:
expr - the expression (already normalized, null for none).
prefix - the table prefix for the ConfigurableEntity tables for implicit properties.
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
params - the list of prepared statement params to add to.
Returns:
the SQL where clause, or null if there shouldn't be one.

getSearchSQL

protected void getSearchSQL(java.lang.StringBuffer buf,
                            Expression expr,
                            java.lang.String prefix,
                            boolean supportsLikeEscapeClause,
                            java.util.List params,
                            boolean isCategory)
                     throws CatalogException
Get the SQL where clause for an expression.

Parameters:
buf - the buffer to write into.
expr - the expression (already normalized, null for none).
prefix - the table prefix for the ConfigurableEntity tables for implicit properties.
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
params - the list of prepared statement params to add to.

getSearchSQL

protected void getSearchSQL(java.lang.StringBuffer buf,
                            Criteria c,
                            java.lang.String prefix,
                            boolean supportsLikeEscapeClause,
                            java.util.List params,
                            boolean isCategory)
                     throws CatalogException
Get the SQL where clause for a Criteria.

Parameters:
buf - the buffer to write into.
c - the Criteria.
prefix - the table prefix for the ConfigurableEntity tables for implicit properties.
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
params - the list of prepared statement params to add to.

getSearchSQL

protected void getSearchSQL(java.lang.StringBuffer buf,
                            java.lang.String prefix,
                            boolean supportsLikeEscapeClause,
                            java.lang.String column,
                            java.lang.String scope,
                            java.lang.String name,
                            java.lang.String op,
                            java.lang.Object val,
                            java.util.List params,
                            boolean isCategory)
Get the SQL for searching for an implicit property in a certain WLCS_PROP_* table.

Parameters:
buf - the buffer to write into.
prefix - the table prefix.
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
table - the WLCS_PROP_* table name (e.g. WLCS_PROP_TEXT).
scope - the property scope name (null for any scope).
name - the property name.
op - the operator.
val - the value to match
params - the list of prepared statement params to add to.

getSearchSQL

protected void getSearchSQL(java.lang.StringBuffer buf,
                            Logical l,
                            java.lang.String prefix,
                            boolean supportsLikeEscapeClause,
                            java.util.List params,
                            boolean isCategory)
                     throws CatalogException
Get the SQL where clause for a Criteria.

Parameters:
buf - the buffer to write into.
l - the Logical.
prefix - the table prefix for the ConfigurableEntity tables for implicit properties.
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
params - the list of prepared statement params to add to.

isLegalSingleValueComparator

public static boolean isLegalSingleValueComparator(java.lang.String c)
Determine if a comparator is legal, single-value attribute comparator.

getSQLOperator

public static java.lang.String getSQLOperator(java.lang.String c)
Return the corresponding SQL operator for the given comparator.

Parameters:
op - the comparator (one from TypesHelper).

toSQLLike

public static java.lang.String toSQLLike(java.lang.String like,
                                         boolean supportsLikeEscapeClause)
Convert a query LIKE value to a SQL LIKE value.

toSQLLike

public static java.lang.Object toSQLLike(java.lang.Object obj,
                                         boolean supportsLikeEscapeClause)
Convert an object, which might be a string, to a SQL like string.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Quick unit test of keyword search.

© 2002 BEA Systems, Inc.

Copyright © 2002 BEA Systems, Inc. All Rights Reserved