RefSQLGenerator Class

DEPRECATED

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

public class RefSQLGenerator

    extends Object

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


Hierarchy
Object
  RefSQLGenerator

Nested Class Summary

public static classcom.bea.p13n.content.document.ref.RefSQLGenerator.Info
           The generated SQL and information about the Search.

Field Summary

public static final short
AND_TYPE
The LogicalAnd/LogicalMulitAnd expression type.
public static final short
COLLECTION_CONTAINS_ALL_TYPE
The CollectionContainsAll expression type.
public static final short
COLLECTION_CONTAINS_TYPE
The CollectionContains expression type.
public static final DateFormat
dateFormat
A date formatter for "MM/dd/yyyy HH:mm:ss z" (02/28/2000 15:58:35 MST).
public static final Map
defPropertyColumnMap
The default map of property name to document table column name.
public static final Map
defPropertyTypeMap
The default map of property names to valid value class.
public String
docMDTable
The document_metadata table name this should use.
public String
docTable
The document table name this should use.
public static final short
EQUALS_TYPE
The Equals expression type.
public boolean
failOnNonExplicit
Control what happens if RefSQLGenerator.docMDTable is null and a property is found that isn't in RefSQLGenerator.propertyColumnMap.
public static final short
GREATER_OR_EQUALS_TYPE
The GreaterOrEquals expression type.
public static final short
GREATER_THAN_TYPE
The GreaterThan expression type.
public static final com.bea.p13n.content.document.ref.RefSQLGenerator
instance
A default static instance.
public static final short
LESS_OR_EQUALS_TYPE
The LessOrEquals expression type.
public static final short
LESS_THAN_TYPE
The LessThan expression type.
public static final short
LIKE_TYPE
The StringLike expression type.
public static final short
NOT_EQUALS_TYPE
The NotEquals expression type.
public static final short
NOT_TYPE
The LogicalNot expression type.
public static final short
OR_TYPE
The LogicalOr/LogicalMulitOr expression type.
public Map
propertyColumnMap
The map of Criteria property to table column name this should use.
public Map
propertyTypeMap
The map of property to valid value class this should use.
public boolean
sortExplicitOnly
Control if sorting should happen on explicit properties only.
 

Constructor Summary

RefSQLGenerator()

 

Method Summary

protected void
createBranchInfo(StringBuffer buf, Expression expr, List params, boolean supportsLikeEscapeClause)
Utility to convert a branch expression into a SQL expression.
protected String
createInfo(Expression expr, List params, boolean supportsLikeEscapeClause)
Utility method to convert an Expression into a SQL expression.
protected void
createInfo(StringBuffer buf, Expression expr, List params, boolean supportsLikeEscapeClause)
Utility method to convert an Expression into a SQL expression.
protected void
createLeafInfo(StringBuffer buf, Expression expr, List params, boolean supportsLikeEscapeClause)
Utility to convert a valid leaf Expression into a SQL expression.
public String
getExpressionString(short type)
Get the expression string for the specified expression type.
public 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 Object
getRightHandSide(Expression expr)
Get the right-hand-side of an expression.
public RefSQLGenerator.Info
getSearchInfo(String baseSql, Search params, boolean supportsLikeEscapeClause)
Utility method to get an Info object from the Search params.
public 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.
public boolean
isLegalSingleValueExpressionType(short type)
Determine if a comparator is legal, single-value attribute comparator.
public PreparedStatement
prepare(Connection con, RefSQLGenerator.Info info)
Prepare a JDBC statement from the specified information on the given database connection.
public void
sort(List list, RefSQLGenerator.Info info)
Sort a list of DocumentMetadataDefs based upon the info's sort criteria.
public String
toSQLLike(String like, boolean patternMatchIgnoreCase, boolean supportsLikeEscapeClause)
Convert a query LIKE value to a SQL LIKE value.
public String
toSQLLike(String like, boolean supportsLikeEscapeClause)
Convert a query LIKE value to a SQL LIKE value.
public Object
toSQLLike(Object obj, boolean patternMatchIgnoreCase, boolean supportsLikeEscapeClause)
Convert an object, which might be a string, to a SQL like string.
public Object
toSQLLike(Object obj, boolean supportsLikeEscapeClause)
Convert an object, which might be a string, to a SQL like string.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   

Field Detail

AND_TYPE

public static final short AND_TYPE
The LogicalAnd/LogicalMulitAnd expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


COLLECTION_CONTAINS_ALL_TYPE

public static final short COLLECTION_CONTAINS_ALL_TYPE
The CollectionContainsAll expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


COLLECTION_CONTAINS_TYPE

public static final short COLLECTION_CONTAINS_TYPE
The CollectionContains expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


dateFormat

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


defPropertyColumnMap

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


defPropertyTypeMap

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


docMDTable

public 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 RefSQLGenerator.propertyColumnMap, this will either produce SQL that will never match (if RefSQLGenerator.failOnNonExplicit is false) or throw an exception (if RefSQLGenerator.failOnNonExplicit is true).

Related Topics

RefDocumentProvider.DOC_MD_TABLE


docTable

public String docTable
The document table name this should use.

Related Topics

RefDocumentProvider.DOC_TABLE


EQUALS_TYPE

public static final short EQUALS_TYPE
The Equals expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


failOnNonExplicit

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

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


GREATER_OR_EQUALS_TYPE

public static final short GREATER_OR_EQUALS_TYPE
The GreaterOrEquals expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


GREATER_THAN_TYPE

public static final short GREATER_THAN_TYPE
The GreaterThan expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


instance

public static final com.bea.p13n.content.document.ref.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.


LESS_OR_EQUALS_TYPE

public static final short LESS_OR_EQUALS_TYPE
The LessOrEquals expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


LESS_THAN_TYPE

public static final short LESS_THAN_TYPE
The LessThan expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


LIKE_TYPE

public static final short LIKE_TYPE
The StringLike expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


NOT_EQUALS_TYPE

public static final short NOT_EQUALS_TYPE
The NotEquals expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


NOT_TYPE

public static final short NOT_TYPE
The LogicalNot expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


OR_TYPE

public static final short OR_TYPE
The LogicalOr/LogicalMulitOr expression type.

Related Topics

RefSQLGenerator.getExpressionType(Expression)


propertyColumnMap

public 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 RefSQLGenerator.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 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 RefSQLGenerator.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 RefSQLGenerator.propertyColumnMap. If the sortBy of a Search contains a non-explicit property reference and RefSQLGenerator.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 RefSQLGenerator.sort(List, 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.

 

Constructor Detail

RefSQLGenerator

public RefSQLGenerator()
 

Method Detail

createBranchInfo(StringBuffer, Expression, List, boolean) Method

protected void createBranchInfo(StringBuffer buf, 
                                Expression expr, 
                                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).

Exceptions

DocumentException
thrown on invalid expression data.

createInfo(Expression, List, boolean) Method

protected String createInfo(Expression expr, 
                            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).

Exceptions

DocumentException
thrown on invalid expression data.

createInfo(StringBuffer, Expression, List, boolean) Method

protected void createInfo(StringBuffer buf, 
                          Expression expr, 
                          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).

Exceptions

DocumentException
thrown on invalid expression data.

createLeafInfo(StringBuffer, Expression, List, boolean) Method

protected void createLeafInfo(StringBuffer buf, 
                              Expression expr, 
                              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).

Exceptions

DocumentException
thrown on invalid expression data.

getExpressionString(short) Method

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

Exceptions

DocumentException

Related Topics

RefSQLGenerator.NOT_EQUALS_TYPE
RefSQLGenerator.EQUALS_TYPE
RefSQLGenerator.GREATER_THAN_TYPE
RefSQLGenerator.LESS_THAN_TYPE
RefSQLGenerator.GREATER_OR_EQUALS_TYPE
RefSQLGenerator.LESS_OR_EQUALS_TYPE
RefSQLGenerator.LIKE_TYPE
RefSQLGenerator.COLLECTION_CONTAINS_TYPE
RefSQLGenerator.COLLECTION_CONTAINS_ALL_TYPE
RefSQLGenerator.AND_TYPE
RefSQLGenerator.OR_TYPE
RefSQLGenerator.NOT_TYPE


getExpressionType(Expression) Method

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

Exceptions

DocumentException

Related Topics

RefSQLGenerator.NOT_EQUALS_TYPE
RefSQLGenerator.EQUALS_TYPE
RefSQLGenerator.GREATER_THAN_TYPE
RefSQLGenerator.LESS_THAN_TYPE
RefSQLGenerator.GREATER_OR_EQUALS_TYPE
RefSQLGenerator.LESS_OR_EQUALS_TYPE
RefSQLGenerator.LIKE_TYPE
RefSQLGenerator.COLLECTION_CONTAINS_TYPE
RefSQLGenerator.COLLECTION_CONTAINS_ALL_TYPE
RefSQLGenerator.AND_TYPE
RefSQLGenerator.OR_TYPE
RefSQLGenerator.NOT_TYPE


getLeftHandSide(Expression) Method

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

Exceptions

DocumentException
thrown on invalid expression.

Related Topics

ExpressionHelper.getLeftHandSide(Expression)


getRightHandSide(Expression) Method

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

Exceptions

DocumentException
thrown on invalid expression.

Related Topics

ExpressionHelper.getRightHandSide(Expression)


getSearchInfo(String, Search, boolean) Method

public RefSQLGenerator.Info getSearchInfo(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.

Exceptions

DocumentException

getSQLOperator(short) Method

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

Parameters

type
the comparator (one from TypesHelper).

Exceptions

DocumentException

getSubExpression(Expression, int) Method

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

Exceptions

DocumentException
thrown on invalid expression.

Related Topics

ExpressionHelper.getSubExpression(Expression, int)


isLegalSingleValueExpressionType(short) Method

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


prepare(Connection, RefSQLGenerator.Info) Method

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

Exceptions

SQLException

sort(List, RefSQLGenerator.Info) Method

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

Exceptions

DocumentException

toSQLLike(String, boolean, boolean) Method

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


toSQLLike(String, boolean) Method

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


toSQLLike(Object, boolean, boolean) Method

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


toSQLLike(Object, boolean) Method

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