com.wewebu.ow.csqlc
Class OwCSQLCProcessor

java.lang.Object
  extended by com.wewebu.ow.csqlc.OwCSQLCProcessor

public abstract class OwCSQLCProcessor
extends Object

Content SQL Creator node processing facade. An OwSearchNode + OwSort to content SQL abstract syntax tree conversion class. The supported SQL syntaxes must conform generally to the SQL-92 syntax.

Alfresco Workdesk
Copyright (c) Alfresco Software, Inc.
All rights reserved.

For licensing information read the license.txt file or
go to: http://wiki.alfresco.com

Since:
3.2.0.0

Nested Class Summary
static class OwCSQLCProcessor.OwProcessContext
           OwProcessContext.
 
Field Summary
protected  OwSQLEntitiesResolver m_entitiesResolver
           
 
Constructor Summary
OwCSQLCProcessor(OwSQLEntitiesResolver entitiesResolver_p)
           
OwCSQLCProcessor(OwSQLEntitiesResolver entitiesResolver_p, Integer maxRows)
           
 
Method Summary
protected  String convertWildCards(OwSearchCriteria criteria_p, String value_p)
          (overridable) Convert the wildcards from client format into native representation and do also an escaping of characters matching the native wildcard definition.
protected  OwBetweenPredicate createBetweenPredicate(OwSearchCriteria criteria_p, boolean negate_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  String createCBRAllExpression(OwSearchCriteria criteria_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  OwPredicate createCBRAllPredicate(OwSearchCriteria criteria_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  String createCBRInExpression(OwSearchCriteria criteria_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  OwPredicate createCBRInPredicate(OwSearchCriteria criteria_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected abstract  OwColumnQualifier createColumnQualifier(String propertyName_p, String repositoryID_p)
           
protected  OwColumnReference createColumnReference(OwColumnQualifier qualifier_p, String columnName_p)
           
protected  OwComparisonPredicate createComparisonPredicate(OwSearchCriteria criteria_p, OwComparisonOperator comparisonOperator_p, OwCSQLCProcessor.OwProcessContext context_p)
          Create a compare predicate, is called if current predicate is a compare operator.
protected  OwSearchCondition createContentCondition(OwSearchNode conditionRootNode_p, OwCSQLCProcessor.OwProcessContext context_p)
          Scan the node for existence or definition of CBR (a.k.a.
protected  OwCharacterStringLiteral createContentSearchLiteral(List<String> textSearchExpressions_p, OwSearchCriteria criteria_p)
          (overridable) Create a literal for the content search criteria, will return a null value if the provided expression list does not contain valid values (non-empty and non-null).
protected  OwLiteral createDefaultLiteral(OwSearchCriteria criteria_p, Object value_p)
           
protected  OwPredicate createExtendedPredicate(OwSearchCriteria criteria_p, OwCSQLCProcessor.OwProcessContext context_p, int operator_p)
          (overridable) This method is called if an unknown or by default unsupported operator is found in the provided OwSearchCriteria.
protected abstract  OwColumnQualifier createFromTableQualifier(String tableName_p, String typeName_p)
           
protected  OwInPredicate createInPredicate(OwSearchCriteria criteria_p, boolean negate_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected abstract  String createJoinColumnName(OwColumnQualifier qualifier_p)
           
protected abstract  OwPredicateFormat createLikeFormat()
           
protected  OwLikePredicate createLikePredicate(OwSearchCriteria criteria_p, boolean negate_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  OwSQLDateTimeLiteral createLiteral(OwSearchCriteria criteria_p, Date date_p)
           
protected  OwSignedNumericLiteral createLiteral(OwSearchCriteria criteria_p, Number number_p)
           
protected  OwLiteral createLiteral(OwSearchCriteria criteria_p, Object value_p)
           
protected  OwCharacterStringLiteral createLiteral(OwSearchCriteria criteria_p, String string_p)
           
protected  OwLiteral createNullLiteral()
           
protected  OwNullPredicate createNullPredicate(OwSearchCriteria criteria_p, boolean negate_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  OwQuantifiedInPredicate createQuantifiedInPredicate(OwSearchCriteria criteria_p, boolean negate_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected abstract  OwColumnQualifier createQueryColumnQualifier(String tableName_p, String typeName_p)
           
protected  String createQueryFieldName(OwFieldDefinition fieldDefinition_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected abstract  OwColumnQualifier createQueryFieldQualifier(OwFieldDefinition fieldDefinition_p, OwCSQLCProcessor.OwProcessContext context_p)
           
protected  OwSimpleTable createSimpleTable(OwSelectList selectList, OwFromClause fromClause, OwWhereClause where)
          (overridable) Factory method for OwSimpleTable object, which represents a SQL-statement object.
 OwExternal<List<OwQueryStatement>> createSQLStatements(OwSearchNode searchRootNode_p, Collection<String> propertyQueryNames_p, OwSort sortOrder_p)
          Create the SQL statement(s) by parsing the provided root search node.
 OwExternal<List<OwQueryStatement>> createSQLStatements(OwSearchNode searchRootNode_p, Collection<String> propertyQueryNames_p, OwSort sortOrder_p, int versionSelection_p)
          Create the SQL statement(s) by parsing the provided root search node.
protected  OwSearchCondition createSubclassesConditions(List<OwClass> subclasses_p)
          (overridable)
protected abstract  OwTextSearchPredicate createTextSearchPredicate(OwCharacterStringLiteral searchExpression_p, OwColumnReference columnReference_p)
           
protected  OwSearchCondition createVersionSelectionCondition(OwSearchNode searchRootNode_p, int versionSelection_p)
           
protected abstract  String escapeNativeWildCardRepresentation(String value_p, Collection<OwWildCardDefinition> wildCardDefs)
          If the value has characters representing native wild cards definitions, they should be escaped (if possible) before the convertWildCards(OwSearchCriteria, String) replace all client wild cards with native representation.
protected  String escapeStringValue(String value_p)
          String value escaping depending the definition of SQL part.
protected  Map<String,List<OwClass>> findMainObjectClasses(OwSearchNode searchRootNode_p)
           
protected  Map<String,List<OwClass>> findSelectedObjectClasses(OwSearchNode searchRootNode_p, String criteriaName_p)
           
protected abstract  OwFolderPredicateFormat getFolderPredicateFormat()
           
protected abstract  OwPredicateFormat getInFormat()
           
protected  String getMainObjectCriteria()
           
 Integer getMaxRows()
          Get the max row definition.
protected abstract  OwPredicateFormat getQuantifiedComparisonFormat()
           
protected abstract  OwPredicateFormat getQuantifiedInFormat()
           
protected  Map<Integer,OwComparisonOperator> getSQLComparisonOperatorMap()
          Map of operators which represent a simple compare function.
protected  void handleSingleContentCondition(OwSearchNode conditionRootNode_p, OwCSQLCProcessor.OwProcessContext context_p, List<String> textSearchExpressions_p)
          (overridable) Method specific called for parsing statements where the isMultipleTextSearchSyntax() return false.
protected abstract  boolean isMultipleTextSearchSyntax()
           
protected  boolean isValidPredicateValue(OwSearchCriteria criteria_p, OwCSQLCProcessor.OwProcessContext context_p, int operator_p)
          (overridable) Simple method called during createPredicate(OwSearchCriteria, OwProcessContext) process to quickly verify if the criteria value is good enough for a specific predicate/operator.
protected abstract  String joinType(OwCorrelatedTableName joinedTable_p)
           
protected  boolean qualifySingleTable(OwSearchNode searchRootNode_p, OwQueryStatement statement_p)
           
protected  OwFieldDefinition retrieveDefinition(OwSearchCriteria criteria_p)
           
 void setMaxRows(Integer rows)
          Set max rows, if ResultSet size should be controlled through generated SQL statement.
protected  List<OwClass> subclass(OwClass mainType_p, Map<String,List<OwClass>> typedSubclasses_p, boolean singleMainType_p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_entitiesResolver

protected OwSQLEntitiesResolver m_entitiesResolver
Constructor Detail

OwCSQLCProcessor

public OwCSQLCProcessor(OwSQLEntitiesResolver entitiesResolver_p)

OwCSQLCProcessor

public OwCSQLCProcessor(OwSQLEntitiesResolver entitiesResolver_p,
                        Integer maxRows)
Method Detail

createQueryFieldName

protected String createQueryFieldName(OwFieldDefinition fieldDefinition_p,
                                      OwCSQLCProcessor.OwProcessContext context_p)
                               throws OwException
Throws:
OwException

createQueryFieldQualifier

protected abstract OwColumnQualifier createQueryFieldQualifier(OwFieldDefinition fieldDefinition_p,
                                                               OwCSQLCProcessor.OwProcessContext context_p)
                                                        throws OwException
Throws:
OwException

createColumnQualifier

protected abstract OwColumnQualifier createColumnQualifier(String propertyName_p,
                                                           String repositoryID_p)
                                                    throws OwException
Throws:
OwException

createSQLStatements

public final OwExternal<List<OwQueryStatement>> createSQLStatements(OwSearchNode searchRootNode_p,
                                                                    Collection<String> propertyQueryNames_p,
                                                                    OwSort sortOrder_p)
                                                             throws OwException
Create the SQL statement(s) by parsing the provided root search node. Will set the version selection to default, for creating of the SQL statement(s).
See @link #createSQLStatements(OwSearchNode, Collection, OwSort, int)

Parameters:
searchRootNode_p - OwSearchNode root node to be used for parsing
propertyQueryNames_p - Collection List of query names
sortOrder_p - OwSort defined sort for search
Returns:
the SQL query statement for the given OwSearchNode , property collection and OwSort specification
Throws:
OwException

createSQLStatements

public OwExternal<List<OwQueryStatement>> createSQLStatements(OwSearchNode searchRootNode_p,
                                                              Collection<String> propertyQueryNames_p,
                                                              OwSort sortOrder_p,
                                                              int versionSelection_p)
                                                       throws OwException
Create the SQL statement(s) by parsing the provided root search node.

Parameters:
searchRootNode_p - OwSearchNode root node to be used for parsing
propertyQueryNames_p - Collection List of query names
sortOrder_p - OwSort defined sort for search
versionSelection_p - int the version selection which should be handled
Returns:
the SQL query statement for the given OwSearchNode , property collection and OwSort specification
Throws:
OwException

qualifySingleTable

protected boolean qualifySingleTable(OwSearchNode searchRootNode_p,
                                     OwQueryStatement statement_p)
                              throws OwException
Parameters:
searchRootNode_p -
statement_p -
Returns:
true statements with single main tables need qualified names
Throws:
OwException
Since:
3.2.0.3

joinType

protected abstract String joinType(OwCorrelatedTableName joinedTable_p)

createJoinColumnName

protected abstract String createJoinColumnName(OwColumnQualifier qualifier_p)

createSubclassesConditions

protected OwSearchCondition createSubclassesConditions(List<OwClass> subclasses_p)
                                                throws OwException
(overridable)

Parameters:
subclasses_p -
Returns:
subclasses search condition for the given subclasses if supported. If subclasses conditions are not supported an invalid condition is returned.
Throws:
OwException
Since:
3.2.0.3

isMultipleTextSearchSyntax

protected abstract boolean isMultipleTextSearchSyntax()

subclass

protected final List<OwClass> subclass(OwClass mainType_p,
                                       Map<String,List<OwClass>> typedSubclasses_p,
                                       boolean singleMainType_p)

getFolderPredicateFormat

protected abstract OwFolderPredicateFormat getFolderPredicateFormat()

createContentCondition

protected OwSearchCondition createContentCondition(OwSearchNode conditionRootNode_p,
                                                   OwCSQLCProcessor.OwProcessContext context_p)
                                            throws OwException
Scan the node for existence or definition of CBR (a.k.a. Full text search).

Parameters:
conditionRootNode_p - OwSearchNode the to be scanned
context_p - OwProcessContext current context
Returns:
OwSearchCondition or null if not found or available
Throws:
OwException

handleSingleContentCondition

protected void handleSingleContentCondition(OwSearchNode conditionRootNode_p,
                                            OwCSQLCProcessor.OwProcessContext context_p,
                                            List<String> textSearchExpressions_p)
                                     throws OwException
(overridable) Method specific called for parsing statements where the isMultipleTextSearchSyntax() return false. Will be called by the createContentCondition(OwSearchNode, OwProcessContext) method, only if syntax does not allow multiple content search predicate/conditions.

Parameters:
conditionRootNode_p - OwSearchNode containing the content search criteria
context_p - OwProcessContext current context for search
textSearchExpressions_p - List of String where to attach additional expressions
Throws:
OwException

createContentSearchLiteral

protected OwCharacterStringLiteral createContentSearchLiteral(List<String> textSearchExpressions_p,
                                                              OwSearchCriteria criteria_p)
(overridable) Create a literal for the content search criteria, will return a null value if the provided expression list does not contain valid values (non-empty and non-null).

Parameters:
textSearchExpressions_p - List of expressions (String)
criteria_p - OwSearchCriteria responsible for definition
Returns:
OwCharacterStringLiteral or null

createVersionSelectionCondition

protected OwSearchCondition createVersionSelectionCondition(OwSearchNode searchRootNode_p,
                                                            int versionSelection_p)
                                                     throws OwException
Throws:
OwException

createComparisonPredicate

protected OwComparisonPredicate createComparisonPredicate(OwSearchCriteria criteria_p,
                                                          OwComparisonOperator comparisonOperator_p,
                                                          OwCSQLCProcessor.OwProcessContext context_p)
                                                   throws OwException
Create a compare predicate, is called if current predicate is a compare operator. Current compare operators are retrieved by getSQLComparisonOperatorMap().

Parameters:
criteria_p - OwSearchCriteria
comparisonOperator_p - OwComparisonOperator
context_p - OwCSQLCProcessor.OwProcessContext
Returns:
OwComparisonPredicate
Throws:
OwException

getInFormat

protected abstract OwPredicateFormat getInFormat()

createInPredicate

protected OwInPredicate createInPredicate(OwSearchCriteria criteria_p,
                                          boolean negate_p,
                                          OwCSQLCProcessor.OwProcessContext context_p)
                                   throws OwException
Throws:
OwException

createLikePredicate

protected OwLikePredicate createLikePredicate(OwSearchCriteria criteria_p,
                                              boolean negate_p,
                                              OwCSQLCProcessor.OwProcessContext context_p)
                                       throws OwException
Throws:
OwException

createLikeFormat

protected abstract OwPredicateFormat createLikeFormat()

createNullPredicate

protected OwNullPredicate createNullPredicate(OwSearchCriteria criteria_p,
                                              boolean negate_p,
                                              OwCSQLCProcessor.OwProcessContext context_p)
                                       throws OwException
Throws:
OwException

getQuantifiedInFormat

protected abstract OwPredicateFormat getQuantifiedInFormat()

createQuantifiedInPredicate

protected OwQuantifiedInPredicate createQuantifiedInPredicate(OwSearchCriteria criteria_p,
                                                              boolean negate_p,
                                                              OwCSQLCProcessor.OwProcessContext context_p)
                                                       throws OwException
Throws:
OwException

createBetweenPredicate

protected OwBetweenPredicate createBetweenPredicate(OwSearchCriteria criteria_p,
                                                    boolean negate_p,
                                                    OwCSQLCProcessor.OwProcessContext context_p)
                                             throws OwException
Throws:
OwException

createExtendedPredicate

protected OwPredicate createExtendedPredicate(OwSearchCriteria criteria_p,
                                              OwCSQLCProcessor.OwProcessContext context_p,
                                              int operator_p)
                                       throws OwException
(overridable) This method is called if an unknown or by default unsupported operator is found in the provided OwSearchCriteria.

By default this method is throwing an invalid operation exception, and should be used to extend the operation capability of the OwCSQLCProcessor.

Parameters:
criteria_p - OwSearchCriteria
context_p - OwProcessContext
operator_p - int value representing one of the OwSearchOperator.CRIT_OP_...
Returns:
OwPredicate
Throws:
OwException

createCBRAllExpression

protected String createCBRAllExpression(OwSearchCriteria criteria_p,
                                        OwCSQLCProcessor.OwProcessContext context_p)
                                 throws OwException
Throws:
OwException

createCBRAllPredicate

protected OwPredicate createCBRAllPredicate(OwSearchCriteria criteria_p,
                                            OwCSQLCProcessor.OwProcessContext context_p)
                                     throws OwException
Throws:
OwException

createTextSearchPredicate

protected abstract OwTextSearchPredicate createTextSearchPredicate(OwCharacterStringLiteral searchExpression_p,
                                                                   OwColumnReference columnReference_p)
                                                            throws OwException
Throws:
OwException

createCBRInExpression

protected String createCBRInExpression(OwSearchCriteria criteria_p,
                                       OwCSQLCProcessor.OwProcessContext context_p)
                                throws OwException
Throws:
OwException

createCBRInPredicate

protected OwPredicate createCBRInPredicate(OwSearchCriteria criteria_p,
                                           OwCSQLCProcessor.OwProcessContext context_p)
                                    throws OwException
Throws:
OwException

getQuantifiedComparisonFormat

protected abstract OwPredicateFormat getQuantifiedComparisonFormat()

retrieveDefinition

protected OwFieldDefinition retrieveDefinition(OwSearchCriteria criteria_p)
                                        throws OwException
Throws:
OwException

createLiteral

protected OwSQLDateTimeLiteral createLiteral(OwSearchCriteria criteria_p,
                                             Date date_p)
                                      throws OwCSQLCException
Throws:
OwCSQLCException

createLiteral

protected OwSignedNumericLiteral createLiteral(OwSearchCriteria criteria_p,
                                               Number number_p)

createLiteral

protected OwCharacterStringLiteral createLiteral(OwSearchCriteria criteria_p,
                                                 String string_p)

createDefaultLiteral

protected OwLiteral createDefaultLiteral(OwSearchCriteria criteria_p,
                                         Object value_p)

createNullLiteral

protected OwLiteral createNullLiteral()

createLiteral

protected OwLiteral createLiteral(OwSearchCriteria criteria_p,
                                  Object value_p)
                           throws OwException
Throws:
OwException

convertWildCards

protected String convertWildCards(OwSearchCriteria criteria_p,
                                  String value_p)
(overridable) Convert the wildcards from client format into native representation and do also an escaping of characters matching the native wildcard definition.

Parameters:
criteria_p - OwSearchCriteria
value_p - String
Returns:
String representing the escaped value

escapeNativeWildCardRepresentation

protected abstract String escapeNativeWildCardRepresentation(String value_p,
                                                             Collection<OwWildCardDefinition> wildCardDefs)
If the value has characters representing native wild cards definitions, they should be escaped (if possible) before the convertWildCards(OwSearchCriteria, String) replace all client wild cards with native representation.

Parameters:
value_p - String
wildCardDefs - Collection current possible wildcards
Returns:
String with escaped native wildcard representations

getSQLComparisonOperatorMap

protected Map<Integer,OwComparisonOperator> getSQLComparisonOperatorMap()
Map of operators which represent a simple compare function.

Returns:
Map of OwSearchOperator.CRIT_OP... to OwComparisonOperator

createQueryColumnQualifier

protected abstract OwColumnQualifier createQueryColumnQualifier(String tableName_p,
                                                                String typeName_p)

createColumnReference

protected OwColumnReference createColumnReference(OwColumnQualifier qualifier_p,
                                                  String columnName_p)

findSelectedObjectClasses

protected final Map<String,List<OwClass>> findSelectedObjectClasses(OwSearchNode searchRootNode_p,
                                                                    String criteriaName_p)
                                                             throws OwException
Throws:
OwException

getMainObjectCriteria

protected String getMainObjectCriteria()

findMainObjectClasses

protected final Map<String,List<OwClass>> findMainObjectClasses(OwSearchNode searchRootNode_p)
                                                         throws OwException
Throws:
OwException

createFromTableQualifier

protected abstract OwColumnQualifier createFromTableQualifier(String tableName_p,
                                                              String typeName_p)

escapeStringValue

protected String escapeStringValue(String value_p)
String value escaping depending the definition of SQL part.

ATTENTION: This method is called by convertWildCards(OwSearchCriteria, String) before checking if the wild cards are allowed for search criteria or not. Wildcard escaping is done by the convertWildCards(OwSearchCriteria, String) method.

Parameters:
value_p - String to be escaped
Returns:
String representing the escaped sequence

isValidPredicateValue

protected boolean isValidPredicateValue(OwSearchCriteria criteria_p,
                                        OwCSQLCProcessor.OwProcessContext context_p,
                                        int operator_p)
(overridable) Simple method called during createPredicate(OwSearchCriteria, OwProcessContext) process to quickly verify if the criteria value is good enough for a specific predicate/operator.

Hint: This check should be kept lightweight (e.g. just verifying non-null values)!
For specific checks use the OwSearchCondition.isValid() method.

Parameters:
criteria_p - OwSearchCriteria
context_p - OwCSQLCProcessor.OwProcessContext
operator_p - int representing on of OwSearchOperator.CRIT_OP_...
Returns:
boolean true if predicate should be generated for given criteria

createSimpleTable

protected OwSimpleTable createSimpleTable(OwSelectList selectList,
                                          OwFromClause fromClause,
                                          OwWhereClause where)
(overridable) Factory method for OwSimpleTable object, which represents a SQL-statement object. Creation of instance also consider current getMaxRows() definition.

Parameters:
selectList - OwSelectList select property definitions
fromClause - OwFromClause SQL-from definition
where - OwWhereClause SQL-where definition, can be null
Returns:
OwSimpleTable
Since:
3.2.0.2
See Also:
setMaxRows(Integer), getMaxRows()

setMaxRows

public void setMaxRows(Integer rows)
Set max rows, if ResultSet size should be controlled through generated SQL statement.

No verification done for value, negative values are also accepted

Parameters:
rows - Integer can be null
Since:
3.2.0.2

getMaxRows

public Integer getMaxRows()
Get the max row definition.

Returns:
Integer or null
Since:
3.2.0.2


Copyright © 2013 Alfresco Business Solutions. All Rights Reserved.