© 2002 BEA Systems, Inc.


com.bea.p13n.content.document.ref
Class RefSQLGenerator

java.lang.Object
  |
  +--com.bea.p13n.content.document.ref.RefSQLGenerator

public class RefSQLGenerator
extends java.lang.Object

A class which generate and execute SQL based upon the reference document management implementation.


Inner Class Summary
static class RefSQLGenerator.Info
          The generated SQL and information about the Search.
 
Field Summary
static short AND_TYPE
          The LogicalAnd/LogicalMulitAnd expression type.
static short COLLECTION_CONTAINS_ALL_TYPE
          The CollectionContainsAll expression type.
static short COLLECTION_CONTAINS_TYPE
          The CollectionContains expression type.
static java.text.DateFormat dateFormat
          A date formatter for "MM/dd/yyyy HH:mm:ss z" (02/28/2000 15:58:35 MST).
static java.util.Map defPropertyColumnMap
          The default map of property name to document table column name.
static java.util.Map defPropertyTypeMap
          The default map of property names to valid value class.
 java.lang.String docMDTable
          The document_metadata table name this should use.
 java.lang.String docTable
          The document table name this should use.
static short EQUALS_TYPE
          The Equals expression type.
 boolean failOnNonExplicit
          Control what happens if docMDTable is null and a property is found that isn't in propertyColumnMap.
static short GREATER_OR_EQUALS_TYPE
          The GreaterOrEquals expression type.
static short GREATER_THAN_TYPE
          The GreaterThan expression type.
static RefSQLGenerator instance
          A default static instance.
static short LESS_OR_EQUALS_TYPE
          The LessOrEquals expression type.
static short LESS_THAN_TYPE
          The LessThan expression type.
static short LIKE_TYPE
          The StringLike expression type.
static short NOT_EQUALS_TYPE
          The NotEquals expression type.
static short NOT_TYPE
          The LogicalNot expression type.
static short OR_TYPE
          The LogicalOr/LogicalMulitOr expression type.
 java.util.Map propertyColumnMap
          The map of Criteria property to table column name this should use.
 java.util.Map propertyTypeMap
          The map of property to valid value class this should use.
 boolean sortExplicitOnly
          Control if sorting should happen on explicit properties only.
 
Constructor Summary
RefSQLGenerator()
           
 
Method Summary
protected  void createBranchInfo(java.lang.StringBuffer buf, Expression expr, java.util.List params, boolean supportsLikeEscapeClause)
          Utility to convert a branch expression into a SQL expression.
protected  java.lang.String createInfo(Expression expr, java.util.List params, boolean supportsLikeEscapeClause)
          Utility method to convert an Expression into a SQL expression.
protected  void createInfo(java.lang.StringBuffer buf, Expression expr, java.util.List params, boolean supportsLikeEscapeClause)
          Utility method to convert an Expression into a SQL expression.
protected  void createLeafInfo(java.lang.StringBuffer buf, Expression expr, java.util.List params, boolean supportsLikeEscapeClause)
          Utility to convert a valid leaf Expression into a SQL expression.
 java.lang.String getExpressionString(short type)
          Get the expression string for the specified expression type.
 short getExpressionType(Expression expr)
          Get a type constant for the given expression.
protected static PropertyRef getLeftHandSide(Expression expr)
          Get the left-hand-side of an expression.
protected static java.lang.Object getRightHandSide(Expression expr)
          Get the right-hand-side of an expression.
 RefSQLGenerator.Info getSearchInfo(java.lang.String baseSql, Search params, boolean supportsLikeEscapeClause)
          Utility method to get an Info object from the Search params.
 java.lang.String getSQLOperator(short type)
          Return the corresponding SQL operator for the given expression type.
protected static Expression getSubExpression(Expression expr, int count)
          Get the specified subexpression.
 boolean isLegalSingleValueExpressionType(short type)
          Determine if a comparator is legal, single-value attribute comparator.
 java.sql.PreparedStatement prepare(java.sql.Connection con, RefSQLGenerator.Info info)
          Prepare a JDBC statement from the specified information on the given database connection.
 void sort(java.util.List list, RefSQLGenerator.Info info)
          Sort a list of DocumentMetadataDefs based upon the info's sort criteria.
 java.lang.Object toSQLLike(java.lang.Object obj, boolean supportsLikeEscapeClause)
          Deprecated.  
 java.lang.Object toSQLLike(java.lang.Object obj, boolean patternMatchIgnoreCase, boolean supportsLikeEscapeClause)
          Convert an object, which might be a string, to a SQL like string.
 java.lang.String toSQLLike(java.lang.String like, boolean supportsLikeEscapeClause)
          Deprecated.  
 java.lang.String toSQLLike(java.lang.String like, boolean patternMatchIgnoreCase, 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

instance

public static final RefSQLGenerator instance
A default static instance.

This can be used to access any of the default utility method implementations:

Those methods exist as instance methods to allow for subclasses to override behavior.


NOT_EQUALS_TYPE

public static final short NOT_EQUALS_TYPE
The NotEquals expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

EQUALS_TYPE

public static final short EQUALS_TYPE
The Equals expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

GREATER_THAN_TYPE

public static final short GREATER_THAN_TYPE
The GreaterThan expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

LESS_THAN_TYPE

public static final short LESS_THAN_TYPE
The LessThan expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

GREATER_OR_EQUALS_TYPE

public static final short GREATER_OR_EQUALS_TYPE
The GreaterOrEquals expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

LESS_OR_EQUALS_TYPE

public static final short LESS_OR_EQUALS_TYPE
The LessOrEquals expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

LIKE_TYPE

public static final short LIKE_TYPE
The StringLike expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

COLLECTION_CONTAINS_TYPE

public static final short COLLECTION_CONTAINS_TYPE
The CollectionContains expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

COLLECTION_CONTAINS_ALL_TYPE

public static final short COLLECTION_CONTAINS_ALL_TYPE
The CollectionContainsAll expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

AND_TYPE

public static final short AND_TYPE
The LogicalAnd/LogicalMulitAnd expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

OR_TYPE

public static final short OR_TYPE
The LogicalOr/LogicalMulitOr expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

NOT_TYPE

public static final short NOT_TYPE
The LogicalNot expression type.
See Also:
getExpressionType(com.bea.p13n.expression.Expression)

defPropertyColumnMap

public static final java.util.Map defPropertyColumnMap
The default map of property name to document table column name.

defPropertyTypeMap

public static final java.util.Map defPropertyTypeMap
The default map of property names to valid value class.

dateFormat

public static final java.text.DateFormat dateFormat
A date formatter for "MM/dd/yyyy HH:mm:ss z" (02/28/2000 15:58:35 MST).

docTable

public java.lang.String docTable
The document table name this should use.
See Also:
RefDocumentProvider.DOC_TABLE

docMDTable

public java.lang.String docMDTable
The document_metadata table name this should use.

Set this to null for this to only handle explicit properties. In this case, if a property is found that is not in the propertyColumnMap, this will either produce SQL that will never match (if failOnNonExplicit is false) or throw an exception (if failOnNonExplicit is true).

See Also:
RefDocumentProvider.DOC_MD_TABLE

propertyColumnMap

public java.util.Map propertyColumnMap
The map of Criteria property to table column name this should use.

If the property name from the expression is in this map, then the associated value will be the document table column name in the resulting SQL statement. If the property name is not in this map, then it is assumed the property is from the document_metadata table (unless docMDTable is set null, in which case an exception is raised). For example, if the property name is "identifier" and the associated value in the map is "ID", then all expressions written against "identifier" will get converted into SQL statements againsts the "ID" column of the document table.


propertyTypeMap

public java.util.Map propertyTypeMap
The map of property to valid value class this should use.

If the property name from the expression is in propertyColumnMap, it also needs to be in this map. The associated value is the Class object minimum type that the literal in the expression being compared to the property must have. For example, if the property name "size" is mapped to the "DOCUMENT_SIZE" column in propertyColumnMap and mapped to Number.class here, then, in the expression, all comparisions to "size" must be against numbers (e.g. "size != 1024", "size < 10000.0").


sortExplicitOnly

public boolean sortExplicitOnly
Control if sorting should happen on explicit properties only.

Explicit properties are those that are mapped to document table columns in propertyColumnMap. If the sortBy of a Search contains a non-explicit property reference and docMDTable is not null, this will control what happens. If this is false (the default), then the SortCriteria will be assigned to the Info instance and no database level sorting will occur; something else should handle the sorting (the sort(java.util.List, com.bea.p13n.content.document.ref.RefSQLGenerator.Info) method can be used to sort a List of DocumentMetadataDefs). If this is true, then the property will be skipped for the sort and all sorting will occur in the database.


failOnNonExplicit

public boolean failOnNonExplicit
Control what happens if docMDTable is null and a property is found that isn't in propertyColumnMap.

If this is true, an exception will be thrown; otherwise, SQL that will never match any document will be generated (default).

Constructor Detail

RefSQLGenerator

public RefSQLGenerator()
Method Detail

prepare

public java.sql.PreparedStatement prepare(java.sql.Connection con,
                                          RefSQLGenerator.Info info)
                                   throws java.sql.SQLException
Prepare a JDBC statement from the specified information on the given database connection.

sort

public void sort(java.util.List list,
                 RefSQLGenerator.Info info)
          throws DocumentException
Sort a list of DocumentMetadataDefs based upon the info's sort criteria.

getSearchInfo

public RefSQLGenerator.Info getSearchInfo(java.lang.String baseSql,
                                          Search params,
                                          boolean supportsLikeEscapeClause)
                                   throws DocumentException
Utility method to get an Info object from the Search params.

Parameters:
baseSql - the base select part of the sql (no from, no where).
params - the list to add the prepared statement parameters to.
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.

createInfo

protected java.lang.String createInfo(Expression expr,
                                      java.util.List params,
                                      boolean supportsLikeEscapeClause)
                               throws DocumentException
Utility method to convert an Expression into a SQL expression.

Parameters:
expr - the expression object.
params - the prepared statement input parameters list (will be appended to).
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
Returns:
the SQL expression (no WHERE, no SELECT).
Throws:
DocumentException - thrown on invalid expression data.

createInfo

protected void createInfo(java.lang.StringBuffer buf,
                          Expression expr,
                          java.util.List params,
                          boolean supportsLikeEscapeClause)
                   throws DocumentException
Utility method to convert an Expression into a SQL expression.

Parameters:
buf - the string buffer to write into.
expr - the expression object.
params - the prepared statement input parameters list (will be appended to).
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
Returns:
the SQL expression (no WHERE, no SELECT).
Throws:
DocumentException - thrown on invalid expression data.

getSubExpression

protected static Expression getSubExpression(Expression expr,
                                             int count)
                                      throws DocumentException
Get the specified subexpression.

Throws:
DocumentException - thrown on invalid expression.
See Also:
ExpressionHelper.getSubExpression(com.bea.p13n.expression.Expression, int)

getLeftHandSide

protected static PropertyRef getLeftHandSide(Expression expr)
                                      throws DocumentException
Get the left-hand-side of an expression.

Throws:
DocumentException - thrown on invalid expression.
See Also:
ExpressionHelper.getLeftHandSide(com.bea.p13n.expression.Expression)

getRightHandSide

protected static java.lang.Object getRightHandSide(Expression expr)
                                            throws DocumentException
Get the right-hand-side of an expression.

Throws:
DocumentException - thrown on invalid expression.
See Also:
ExpressionHelper.getRightHandSide(com.bea.p13n.expression.Expression)

createLeafInfo

protected void createLeafInfo(java.lang.StringBuffer buf,
                              Expression expr,
                              java.util.List params,
                              boolean supportsLikeEscapeClause)
                       throws DocumentException
Utility to convert a valid leaf Expression into a SQL expression.

Parameters:
buf - the string buffer to write into.
expr - the expression object.
params - the prepared statement input parameters list (will be appended to).
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
Returns:
the SQL expression (no WHERE, no SELECT).
Throws:
DocumentException - thrown on invalid expression data.

createBranchInfo

protected void createBranchInfo(java.lang.StringBuffer buf,
                                Expression expr,
                                java.util.List params,
                                boolean supportsLikeEscapeClause)
                         throws DocumentException
Utility to convert a branch expression into a SQL expression.

Parameters:
buf - the string buffer to write into.
expr - the branch expression.
params - the prepared statement input parameters list (will be appended to).
supportsLikeEscapeClause - tells if the SQL statement can use the LIKE ESCAPE clause.
Returns:
the SQL expression (no WHERE, no SELECT).
Throws:
DocumentException - thrown on invalid expression data.

getExpressionType

public short getExpressionType(Expression expr)
                        throws DocumentException
Get a type constant for the given expression.

See Also:
NOT_EQUALS_TYPE, EQUALS_TYPE, GREATER_THAN_TYPE, LESS_THAN_TYPE, GREATER_OR_EQUALS_TYPE, LESS_OR_EQUALS_TYPE, LIKE_TYPE, COLLECTION_CONTAINS_TYPE, COLLECTION_CONTAINS_ALL_TYPE, AND_TYPE, OR_TYPE, NOT_TYPE

getExpressionString

public java.lang.String getExpressionString(short type)
                                     throws DocumentException
Get the expression string for the specified expression type.

See Also:
NOT_EQUALS_TYPE, EQUALS_TYPE, GREATER_THAN_TYPE, LESS_THAN_TYPE, GREATER_OR_EQUALS_TYPE, LESS_OR_EQUALS_TYPE, LIKE_TYPE, COLLECTION_CONTAINS_TYPE, COLLECTION_CONTAINS_ALL_TYPE, AND_TYPE, OR_TYPE, NOT_TYPE

isLegalSingleValueExpressionType

public boolean isLegalSingleValueExpressionType(short type)
Determine if a comparator is legal, single-value attribute comparator.

getSQLOperator

public java.lang.String getSQLOperator(short type)
                                throws DocumentException
Return the corresponding SQL operator for the given expression type.

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

toSQLLike

public java.lang.String toSQLLike(java.lang.String like,
                                  boolean supportsLikeEscapeClause)
Deprecated.  
Backward compatible to previous case-sensitive pattern match method

toSQLLike

public java.lang.Object toSQLLike(java.lang.Object obj,
                                  boolean supportsLikeEscapeClause)
Deprecated.  
Backward compatible to previous case-sensitive pattern match method

toSQLLike

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

toSQLLike

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

© 2002 BEA Systems, Inc.

Copyright © 2002 BEA Systems, Inc. All Rights Reserved