com.wewebu.ow.server.field
Class OwSearchSQLOperator

java.lang.Object
  extended by com.wewebu.ow.server.field.OwSearchSQLOperator
Direct Known Subclasses:
OwSearchSQLPreparedStatementOperator

public class OwSearchSQLOperator
extends Object

Standard Operator to create SQL out of a OwSearchNode Tree.

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


Nested Class Summary
protected static class OwSearchSQLOperator.SqlOperatorSingleton
           Singleton for the SQL operators.
 
Field Summary
static int DATE_MODE_DB2
          date mode for converting data types in where clause, DB2 conform
static int DATE_MODE_DEFAULT
          date mode for converting data types in where clause, default mode
static int DATE_MODE_FNCM
          date mode for FileNet P8
static int DATE_MODE_FNIM
          date mode for FileNet Image Manager (days since 1.1.1970)
static int DATE_MODE_MS_ACCESS
          date mode for converting data types in where clause, Microsoft Access conform
static int DATE_MODE_MSSQL
          date mode for converting data types in where clause, MSSQL conform
static int DATE_MODE_ORACLE
          date mode for converting data types in where clause, ORACLE conform
static int DATE_MODE_TREAT_IGNORE_TIME_AS_RANGE
          date mode for date time optional
protected  int m_iMode
          mode to be used
protected static OwSearchSQLOperator.SqlOperatorSingleton m_SqlOperators
          singleton for the SQL operators
 
Constructor Summary
OwSearchSQLOperator(int iMode_p)
          create a new operator
 
Method Summary
protected  String convertWildCards(OwSearchCriteria criteria_p, String value_p)
          convert the wildcards to client format
 boolean createSQLSearchCriteria(OwSearchNode searchNode_p, Writer w_p)
          traverse the search criteria tree and generate a SQL Statement
protected  String getCriteriaQueryName(OwSearchCriteria criteria_p)
          (overridable) Method to get the property name, which is used for query statements.
This method can be overwritten if the field definition name and field definition query name are not corresponding.
protected static int getDateMode(int iMode_p)
          get the date mode part of the mode flag
protected  String getOperatorSQL(OwSearchCriteria criteria_p, Object value_p, boolean fFieldFirst_p)
          get a operator SQL Statement for the given criteria
protected  String getSingleOperatorSQL(OwSearchCriteria criteria_p, Object value_p, int iOperator_p, boolean fFieldFirst_p)
          get a single operator SQL Statement for the given criteria_p
protected  String getSQLOperatorAsString(int operator_p)
          Get the String representation of the operator.
protected  String getSQLValueString(OwSearchCriteria criteria_p, Object value_p, int iDateMode_p)
          get the value of the criteria and convert it to a SQL conform string
protected  String getStringValue(OwSearchCriteria criteria_p, String value_p)
          prevent the usage of " or ' in SQL query
protected  boolean isOperatorFieldFirst(int iOP_p)
          check if given operator has its field first
protected  boolean isStringLiteral(OwSearchCriteria criteria_p)
          (overridable) check if given criteria is a string literal and needs quotation marks
 void setDateFormats(DateFormat dateAndTimeFormat_p, DateFormat dateFormat_p)
          overwrite date format with a own one
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_MODE_FNIM

public static final int DATE_MODE_FNIM
date mode for FileNet Image Manager (days since 1.1.1970)

See Also:
Constant Field Values

DATE_MODE_MS_ACCESS

public static final int DATE_MODE_MS_ACCESS
date mode for converting data types in where clause, Microsoft Access conform

See Also:
Constant Field Values

DATE_MODE_FNCM

public static final int DATE_MODE_FNCM
date mode for FileNet P8

See Also:
Constant Field Values

DATE_MODE_ORACLE

public static final int DATE_MODE_ORACLE
date mode for converting data types in where clause, ORACLE conform

See Also:
Constant Field Values

DATE_MODE_MSSQL

public static final int DATE_MODE_MSSQL
date mode for converting data types in where clause, MSSQL conform

See Also:
Constant Field Values

DATE_MODE_DB2

public static final int DATE_MODE_DB2
date mode for converting data types in where clause, DB2 conform

See Also:
Constant Field Values

DATE_MODE_DEFAULT

public static final int DATE_MODE_DEFAULT
date mode for converting data types in where clause, default mode

See Also:
Constant Field Values

DATE_MODE_TREAT_IGNORE_TIME_AS_RANGE

public static final int DATE_MODE_TREAT_IGNORE_TIME_AS_RANGE
date mode for date time optional

See Also:
Constant Field Values

m_iMode

protected int m_iMode
mode to be used


m_SqlOperators

protected static final OwSearchSQLOperator.SqlOperatorSingleton m_SqlOperators
singleton for the SQL operators

Constructor Detail

OwSearchSQLOperator

public OwSearchSQLOperator(int iMode_p)
create a new operator

Parameters:
iMode_p - int defined as DATE_MODE_...
Method Detail

getDateMode

protected static int getDateMode(int iMode_p)
get the date mode part of the mode flag

Parameters:
iMode_p - int defined as bitwise combination of DATE_MODE_... and DATE_ACCURACY_...
Returns:
int defined with DATE_MODE_...

setDateFormats

public void setDateFormats(DateFormat dateAndTimeFormat_p,
                           DateFormat dateFormat_p)
overwrite date format with a own one

Parameters:
dateAndTimeFormat_p - date format for SQL Date and Time conversion
dateFormat_p - date format for SQL for just Date conversion, ignores time part

createSQLSearchCriteria

public boolean createSQLSearchCriteria(OwSearchNode searchNode_p,
                                       Writer w_p)
                                throws Exception
traverse the search criteria tree and generate a SQL Statement

Parameters:
searchNode_p - current search criteria tree node to traverse, null is allowed
w_p - stream to write SQL Statement to
Returns:
true = valid sub criteria was inserted, false = sub criteria is empty or null and can be ignored
Throws:
Exception

isOperatorFieldFirst

protected boolean isOperatorFieldFirst(int iOP_p)
check if given operator has its field first

Parameters:
iOP_p -
Returns:
boolean true = field first e.g.: MY_PROP = 'Hallo', false = field last e.g.: 'Hallo' in MY_PROP

getOperatorSQL

protected String getOperatorSQL(OwSearchCriteria criteria_p,
                                Object value_p,
                                boolean fFieldFirst_p)
                         throws Exception
get a operator SQL Statement for the given criteria

Parameters:
criteria_p - OwSearchCriteria
value_p - Object
fFieldFirst_p - boolean true = insert the field first, false = insert the value first
Returns:
String or null if criteria is empty and can be ignored
Throws:
Exception

getSingleOperatorSQL

protected String getSingleOperatorSQL(OwSearchCriteria criteria_p,
                                      Object value_p,
                                      int iOperator_p,
                                      boolean fFieldFirst_p)
                               throws Exception
get a single operator SQL Statement for the given criteria_p

Parameters:
criteria_p - OwSearchCriteria
value_p - Object
fFieldFirst_p - boolean true = insert the field first, false = insert the value first
Returns:
String or null if criteria is empty and can be ignored
Throws:
Exception

getSQLValueString

protected String getSQLValueString(OwSearchCriteria criteria_p,
                                   Object value_p,
                                   int iDateMode_p)
                            throws Exception
get the value of the criteria and convert it to a SQL conform string

Parameters:
criteria_p - the criteria to convert
iDateMode_p - int Date mode used to convert date types as defined with DATE_MODE_...
Returns:
String with SQL conform representation of value
Throws:
Exception

isStringLiteral

protected boolean isStringLiteral(OwSearchCriteria criteria_p)
                           throws Exception
(overridable) check if given criteria is a string literal and needs quotation marks

Parameters:
criteria_p -
Returns:
a boolean
Throws:
Exception

getStringValue

protected String getStringValue(OwSearchCriteria criteria_p,
                                String value_p)
prevent the usage of " or ' in SQL query

Parameters:
criteria_p - OwSearchCriteria
value_p - String
Returns:
String

convertWildCards

protected String convertWildCards(OwSearchCriteria criteria_p,
                                  String value_p)
convert the wildcards to client format

Parameters:
criteria_p -
value_p -

getSQLOperatorAsString

protected String getSQLOperatorAsString(int operator_p)
Get the String representation of the operator.

Parameters:
operator_p - int OwSearchOperator.CRIT_...
Returns:
String representing of SQL operator
Since:
2.5.3.0

getCriteriaQueryName

protected String getCriteriaQueryName(OwSearchCriteria criteria_p)
                               throws OwException
(overridable) Method to get the property name, which is used for query statements.
This method can be overwritten if the field definition name and field definition query name are not corresponding.

By default this method returns criteria_p.getFieldDefinition().getClassName().

Parameters:
criteria_p - OwSearchCriteria
Returns:
String name to be used for querying
Throws:
OwException - if can not retrieve field definition information
Since:
3.0.0.0


Copyright © 2013 Alfresco Business Solutions. All Rights Reserved.