Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright 2014-2015 the original author or authors.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
   * either express or implied. See the License for the specific language
   * governing permissions and limitations under the License.
   */
  package org.dbflute.cbean;
  
  import java.util.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
The abstract class of condition-query.

Author(s):
jflute
 
 public abstract class AbstractConditionQuery implements ConditionQuery {
 
     // ===================================================================================
     //                                                                          Definition
     //                                                                          ==========
     private static final Logger _log = LoggerFactory.getLogger(AbstractConditionQuery.class);
 
     protected static final ConditionKey CK_EQ = .;
     protected static final ConditionKey CK_NES = .;
     protected static final ConditionKey CK_NET = .;
     protected static final ConditionKey CK_GT = .;
     protected static final ConditionKey CK_LT = .;
     protected static final ConditionKey CK_GE = .;
     protected static final ConditionKey CK_LE = .;
     protected static final ConditionKey CK_INS = .;
     protected static final ConditionKey CK_NINS = .;
     protected static final ConditionKey CK_LS = .;
     protected static final ConditionKey CK_NLS = .;
     protected static final ConditionKey CK_ISN = .;
     protected static final ConditionKey CK_ISNOE = .;
     protected static final ConditionKey CK_ISNN = .;

    
Object for DUMMY.
 
     protected static final Object DOBJ = new Object();

    
The property of condition-query.
 
     protected static final String CQ_PROPERTY = "conditionQuery";
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     
SQL clause. (NotNull)
 
     protected final SqlClause _sqlClause;

    
My alias name. (NotNull)
 
     protected final String _aliasName;

    
The nest level of relation.
 
     protected final int _nestLevel;

    
The level of subQuery.
 
     protected int _subQueryLevel;

    
The base condition-bean of this query. (NotNull: after setting, basically is set)
 
     protected ConditionBean _baseCB;
 
     // -----------------------------------------------------
     //                                          Foreign Info
     //                                          ------------
     
The property name of foreign.
 
     protected String _foreignPropertyName;

    
The path of relation.
 
     protected String _relationPath;

    
The referrer query.
 
     protected final ConditionQuery _referrerQuery;
 
     // -----------------------------------------------------
     //                                                Inline
     //                                                ------
     
Is it the in-line.
 
     protected boolean _inline;

    
Is it on-clause.
 
     protected boolean _onClause;
 
     // -----------------------------------------------------
     //                                      Relation Keeping
     //                                      ----------------
     
The map of query-relation condition-query to keep parameters for parameter comment.
 
     protected Map<StringConditionQuery_queryRelationKeepingMap;

    
The map of sub-query condition-query to keep parameters for parameter comment.
 
     protected Map<StringMap<StringConditionQuery>> _subQueryKeepingMap;

    
The map of sub-query parameter to keep parameters for parameter comment.
 
     protected Map<StringMap<StringObject>> _subQueryParameterKeepingMap;

    
The map of parameter option for parameter comment.
 
 
     // ===================================================================================
     //                                                                         Constructor
     //                                                                         ===========
     
Constructor.

Parameters:
referrerQuery The instance of referrer query. (NullAllowed: If null, this is base query)
sqlClause The instance of SQL clause. (NotNull)
aliasName The alias name for this query. (NotNull)
nestLevel The nest level of this query. (If zero, this is base query)
 
     public AbstractConditionQuery(ConditionQuery referrerQuerySqlClause sqlClauseString aliasNameint nestLevel) {
          = referrerQuery;
          = sqlClause;
          = aliasName;
          = nestLevel;
     }
 
     // *constructor can not be changed so set it up later
 
     public void xsetBaseCB(ConditionBean baseCB) {
          = baseCB;
     }
 
     protected <CQ extends AbstractConditionQuery> CQ xinitRelCQ(CQ cqConditionBean baseCBString foreignPropertyName,
             String nestRelationPath) {
         cq.xsetBaseCB();
         cq.xsetForeignPropertyName(foreignPropertyName);
         cq.xsetRelationPath(nestRelationPath);
         return cq;
     }
 
     // ===================================================================================
     //                                                                     DBMeta Provider
     //                                                                     ===============
     
Get the provider of DB meta.

Returns:
The provider of DB meta. (NotNull)
 
     protected abstract DBMetaProvider xgetDBMetaProvider();

    
Find the DB meta.

Parameters:
tableFlexibleName The table flexible name. (NotNull)
Returns:
The DB meta of the table. (NotNull)
 
     protected DBMeta findDBMeta(String tableFlexibleName) {
         return xgetDBMetaProvider().provideDBMetaChecked(tableFlexibleName);
     }

    
Get the local DB meta.

Returns:
The instance of local DB meta. (NotNull)
 
     protected DBMeta xgetLocalDBMeta() {
         return findDBMeta(asTableDbName());
     }
 
     // ===================================================================================
     //                                                                  Important Accessor
     //                                                                  ==================
     
 
     public ConditionBean xgetBaseCB() {
         return ;
     }

    
 
     public ConditionQuery xgetBaseQuery() {
         ConditionQuery currentQuery = this;
         while (true) {
             final ConditionQuery referrerQuery = currentQuery.xgetReferrerQuery();
             if (referrerQuery == null) {
                 break;
             }
             currentQuery = referrerQuery;
         }
         return currentQuery;
     }

    
 
     public ConditionQuery xgetReferrerQuery() {
         return ;
     }

    
 
     public SqlClause xgetSqlClause() {
         return ;
     }

    
 
     public String xgetAliasName() {
         return ;
     }

    
 
     public int xgetNestLevel() {
         return ;
     }

    
 
     public int xgetNextNestLevel() {
         return  + 1;
     }
 
     protected int xgetNNLvl() { // for generated source
         return xgetNextNestLevel();
     }

    
 
     public boolean isBaseQuery() {
         return (xgetReferrerQuery() == null);
     }
 
     // -----------------------------------------------------
     //                                             Real Name
     //                                             ---------
     
 
     public ColumnRealName toColumnRealName(String columnDbName) { // with finding DBMeta
         return ColumnRealName.create(xgetAliasName(), toColumnSqlName(columnDbName));
     }

    
 
     public ColumnRealName toColumnRealName(ColumnInfo columnInfo) { // without finding DBMeta
         return ColumnRealName.create(xgetAliasName(), columnInfo.getColumnSqlName());
     }

    
 
     public ColumnSqlName toColumnSqlName(String columnDbName) { // with finding DBMeta
         return xgetLocalDBMeta().findColumnInfo(columnDbName).getColumnSqlName();
     }
 
     // -----------------------------------------------------
     //                                          Foreign Info
     //                                          ------------
     
 
     public String xgetForeignPropertyName() {
         return ;
     }
 
     public void xsetForeignPropertyName(String foreignPropertyName) {
         this. = foreignPropertyName;
     }

    
 
     public String xgetRelationPath() {
         return ;
     }
 
     public void xsetRelationPath(String relationPath) {
         this. = relationPath;
     }
 
     // -----------------------------------------------------
     //                                                Inline
     //                                                ------
     public void xsetOnClause(boolean onClause) {
          = onClause;
     }
 
     // -----------------------------------------------------
     //                                              Location
     //                                              --------
     
 
     public String xgetLocationBase() {
         final StringBuilder sb = new StringBuilder();
         ConditionQuery query = this;
         while (true) {
             if (query.isBaseQuery()) {
                 sb.insert(0,  + ".");
                 break;
             } else {
                 final String foreignPropertyName = query.xgetForeignPropertyName();
                 if (foreignPropertyName == null) {
                     String msg = "The foreignPropertyName of the query should not be null:";
                     msg = msg + " query=" + query;
                     throw new IllegalStateException(msg);
                 }
                 sb.insert(0,  + initCap(foreignPropertyName) + ".");
             }
             query = query.xgetReferrerQuery();
         }
         return sb.toString();
     }

    
Get the location of the property.

Parameters:
propertyName The name of property. (NotNull)
Returns:
The location of the property as path. (NotNull)
 
     protected String xgetLocation(String propertyName) {
         return xgetLocationBase() + propertyName;
     }
 
     // ===================================================================================
     //                                                                  Nested SetupSelect
     //                                                                  ==================
     public void xdoNss(NssCall callback) { // very internal
         final String foreignPropertyName = callback.qf().xgetForeignPropertyName();
         final String foreignTableAliasName = callback.qf().xgetAliasName();
         final String localRelationPath = xgetRelationPath();
         final String foreignRelationPath = callback.qf().xgetRelationPath();
         xgetSqlClause().registerSelectedRelation(foreignTableAliasNameasTableDbName(), foreignPropertyNamelocalRelationPath,
                 foreignRelationPath);
     }
 
     public static interface NssCall { // very internal
         public ConditionQuery qf();
     }
 
     // ===================================================================================
     //                                                                          Outer Join
     //                                                                          ==========
     
Register outer-join.
Optional info, fixed condition and fixed in-line, are resolved in this method.

Parameters:
foreignCQ The condition-query for foreign table. (NotNull)
joinOnResourceMap The resource map of join condition on on-clause. (NotNull)
foreignPropertyName The property name of foreign relation corresponding to this join. (NotNull)
 
     protected void registerOuterJoin(ConditionQuery foreignCQMap<StringStringjoinOnResourceMapString foreignPropertyName) {
         final DBMeta dbmeta = xgetLocalDBMeta();
         final ForeignInfo foreignInfo = dbmeta.findForeignInfo(foreignPropertyName);
         doRegisterOuterJoin(foreignCQjoinOnResourceMapforeignPropertyNameforeignInfo);
     }
 
     protected void doRegisterOuterJoin(ConditionQuery foreignCQMap<StringStringjoinOnResourceMapfinal String foreignPropertyName,
             ForeignInfo foreignInfo) {
         // translate join-on map using column real name
         final Map<ColumnRealNameColumnRealNamejoinOnMap = newLinkedHashMap();
         for (Entry<StringStringentry : joinOnResourceMap.entrySet()) {
             final String local = entry.getKey();
             final String foreign = entry.getValue();
             joinOnMap.put(toColumnRealName(local), foreignCQ.toColumnRealName(foreign));
         }
         final String foreignAlias = foreignCQ.xgetAliasName();
         final String foreignTable = foreignCQ.asTableDbName();
         final String localAlias = xgetAliasName();
         final String localTable = asTableDbName();
         final String fixedCondition = foreignInfo.getFixedCondition();
         final boolean fixedInline = foreignInfo.isFixedInline();
         final FixedConditionResolver resolver = createForeignFixedConditionResolver(foreignCQ);
         final String relationPath = foreignCQ.xgetRelationPath();
         if (fixedInline) {
             xgetSqlClause().registerOuterJoinFixedInline(foreignAliasforeignTablelocalAliaslocalTable // basic
                     , joinOnMaprelationPathforeignInfo // join objects
                     , fixedConditionresolver); // fixed condition (to in-line view)
         } else { // normally here
             xgetSqlClause().registerOuterJoin(foreignAliasforeignTablelocalAliaslocalTable // basic
                     , joinOnMaprelationPathforeignInfo // join objects
                     , fixedConditionresolver); // fixed condition (to on-clause)
         }
         xprepareFixedConditionDynamicParameterLazyChecker(foreignPropertyNameforeignInfo);
     }
 
         return newFixedConditionResolver(thisforeignCQxgetDBMetaProvider());
     }
 
             DBMetaProvider dbmetaProvider) {
         return new HpFixedConditionQueryResolver(localCQforeignCQdbmetaProvider);
     }
 
     protected void xprepareFixedConditionDynamicParameterLazyChecker(final String foreignPropertyNamefinal ForeignInfo foreignInfo) {
         if (!foreignInfo.hasFixedConditionDynamicParameter()) {
             return;
         }
         // lazy check because the following code is allowed:
         // e.g. ColumnQuery
         //   cb.columnQuery(new ... {
         //   }).lessThan(new ... {
         //       cb.specify().specifyMemberAddressAsValid()... // no dynamic parameter
         //   });
             public void check() {
                 xcalbackAssertFixedConditionDynamicParameter(foreignPropertyNameforeignInfo);
             }
         });
     }
 
     protected void xcalbackAssertFixedConditionDynamicParameter(String foreignPropertyNameForeignInfo foreignInfo) {
         // cannot get dynamic parameter map directly in super classes of runtime
         // and does not want to add inner class in generated classes,
         // so this way...as a last-ditch measure
         final Map<StringObjectparameterMap = xfindFixedConditionDynamicParameterMap(foreignPropertyName);
         xdoAssertFixedConditionDynamicParameter(foreignPropertyNameforeignInfoparameterMap);
     }
 
     protected abstract Map<StringObjectxfindFixedConditionDynamicParameterMap(String property);
 
     protected void xassertFCDP(String propertyMap<StringObjectparameterMap) { // assertFixedConditionDynamicParameter()
         final ForeignInfo foreignInfo = xgetLocalDBMeta().findForeignInfo(property);
         xdoAssertFixedConditionDynamicParameter(propertyforeignInfoparameterMap);
     }
 
     protected void xdoAssertFixedConditionDynamicParameter(String propertyForeignInfo foreignInfoMap<StringObjectparameterMap) {
         if (foreignInfo.isFixedConditionDynamicParameterRequired()) { // required check
             boolean notFound = false;
             if (parameterMap != null) {
                 for (Object value : parameterMap.values()) {
                     if (value == null) {
                         notFound = true;
                         break;
                     }
                 }
             } else { // null treated as not found
                 notFound = true;
             }
             if (notFound) {
                 final String tableDbName = asTableDbName();
                 final String fixedCondition = foreignInfo.getFixedCondition();
                 createCBExThrower().throwFixedConditionParameterNotFoundException(tableDbNamepropertyfixedConditionparameterMap);
             }
         }
     }
 
     // ===================================================================================
     //                                                                         Union Query
     //                                                                         ===========
     
The map parameter-bean of union query.
 
     protected SimpleMapPmb<ConditionQuery_unionQueryMap;

    
Get the map parameter-bean of union query. (for parameter comment) {Internal}

Returns:
The instance of map parameter-bean. (NotNull)
 
         if ( == null) {
              = xcreateUnionMapPmb();
         }
         return ;
     }

    
Set union query. {Internal}

Parameters:
unionQuery Union query. (NotNull)
 
     public void xsetUnionQuery(ConditionQuery unionQuery) {
         xsetupUnion(unionQueryfalsexdfgetInternalUnionQueryMap());
     }

    
The map parameter-bean of union all query.
 
     protected SimpleMapPmb<ConditionQuery_unionAllQueryMap;

    
Get the map parameter-bean of union all query. (for parameter comment) {Internal}

Returns:
The instance of map parameter-bean. (NotNull)
 
         if ( == null) {
              = xcreateUnionMapPmb();
         }
         return ;
     }
 
         return new SimpleMapPmb<ConditionQuery>();
     }

    
Set union all query. {Internal}

Parameters:
unionAllQuery Union all query. (NotNull)
 
     public void xsetUnionAllQuery(ConditionQuery unionAllQuery) {
         xsetupUnion(unionAllQuerytruexdfgetInternalUnionAllQueryMap());
     }
 
     protected void xsetupUnion(final ConditionQuery unionQueryboolean unionAllSimpleMapPmb<ConditionQueryunionQueryMap) {
         if (unionQuery == null) {
             String msg = "The argument 'unionQuery' should not be null.";
             throw new IllegalArgumentException(msg);
         }
         // needs to reflect lazily for:
         // o SetupSelect(Relation) after Union (however, basically they should be called before union)
         // o ManualOrder with Dream Cruise using Specify(Relation) after Union
         final ConditionQuery selfCQ = this;
             public void reflect() {
                 reflectRelationOnUnionQuery(selfCQunionQuery); // reflect relations
             }
         });
         final String key = (unionAll ? "unionAllQuery" : "unionQuery") + unionQueryMap.size();
         unionQueryMap.addParameter(keyunionQuery);
         final String propName = "internalUnion" + (unionAll ? "All" : "") + "QueryMap." + key;
         registerUnionQuery(unionQueryunionAllpropName);
     }

    
Reflect relation on union query.

Parameters:
baseQueryAsSuper Base query as super. (NotNull)
unionQueryAsSuper Union query as super. (NotNull)
 
     protected abstract void reflectRelationOnUnionQuery(ConditionQuery baseQueryAsSuperConditionQuery unionQueryAsSuper);

    
Has union query or union all query?

Returns:
The determination, true or false.
 
     public boolean hasUnionQueryOrUnionAllQuery() {
         return ( != null && !.isEmpty()) || ( != null && !.isEmpty());
     }
 
     // ===================================================================================
     //                                                                        Normal Query
     //                                                                        ============
     protected void regQ(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         if (prepareQueryChecked(keyvaluecvaluecolumnDbName).newClause()) {
             setupConditionValueAndRegisterWhereClause(keyvaluecvaluecolumnDbName);
         }
     }
 
     protected void regQ(ConditionKey keyObject valueConditionValue cvalueString columnDbNameConditionOption option) {
         if (prepareQueryChecked(keyvaluecvaluecolumnDbName).newClause()) {
             setupConditionValueAndRegisterWhereClause(keyvaluecvaluecolumnDbNameoption);
         }
     }

    

Parameters:
key The condition key for the query. (NotNull)
value The value of the condition. (NotNull)
cvalue The object of condition value. (NotNull)
columnDbName The DB name of column for the query. (NotNull)
Returns:
The result of the preparation for the condition key. (NotNull)
 
     protected ConditionKeyPrepareResult prepareQueryChecked(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         return xdoPrepareQuery(keyvaluecvaluecolumnDbNametrue);
     }

    

Parameters:
key The condition key for the query. (NotNull)
value The value of the condition. (NotNull)
cvalue The object of condition value. (NotNull)
columnDbName The DB name of column for the query. (NotNull)
Returns:
The result of the preparation for the condition key. (NotNull)
 
     protected ConditionKeyPrepareResult prepareQueryNoCheck(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         return xdoPrepareQuery(keyvaluecvaluecolumnDbNamefalse);
     }
 
     protected ConditionKeyPrepareResult xdoPrepareQuery(ConditionKey keyObject valueConditionValue cvalueString columnDbName,
             boolean invalidChecked) {
         final ConditionKeyPrepareResult result = key.prepareQuery(xcreateQueryModeProvider(), cvaluevalue);
         if (result.overridden()) {
             handleOverridingQuery(keyvaluecvaluecolumnDbName);
         }
         if (result.duplicate()) {
             noticeRegistered(keyvaluecvaluecolumnDbName);
         }
         if (invalidChecked && result.invalid()) {
             handleInvalidQuery(keyvaluecvaluecolumnDbName);
         }
         return result;
     }
 
     // ===================================================================================
     //                                                                    Overriding Query
     //                                                                    ================
     protected void handleOverridingQuery(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         if (isOverrideQueryAllowed(keyvaluecvaluecolumnDbName)) {
             return;
         }
         throwQueryAlreadyRegisteredException(keyvaluecvaluecolumnDbName);
     }
 
     protected boolean isOverrideQueryAllowed(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         return xgetSqlClause().isOverridingQueryAllowed();
     }
 
     protected void noticeRegistered(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         if (.isDebugEnabled()) {
             .debug("*Found the duplicate query: target=" + columnDbName + "." + key + " value=" + value);
         }
     }
 
     // ===================================================================================
     //                                                                       Invalid Query
     //                                                                       =============
     protected void handleInvalidQuery(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         final HpInvalidQueryInfo invalidQueryInfo = xcreateInvalidQueryInfo(keyvaluecolumnDbName);
         xdoHandleInvalidQuery(columnDbNameinvalidQueryInfo);
     }
 
     protected void handleInvalidQueryList(List<ConditionKeykeyListList<? extends ObjectvalueListString columnDbName) {
         if (keyList.size() != valueList.size()) {
             String msg = "The argument 'keyList' should have the same size as 'valueList':";
             msg = msg + " keyList=" + keyList + ", valueList=" + valueList;
             throw new IllegalArgumentException(msg);
         }
         final HpInvalidQueryInfo[] invalidQueryInfoAry = new HpInvalidQueryInfo[keyList.size()];
         int index = 0;
         for (ConditionKey key : keyList) {
             final Object value = valueList.get(index);
             invalidQueryInfoAry[index] = xcreateInvalidQueryInfo(keyvaluecolumnDbName);
             ++index;
         }
         xdoHandleInvalidQuery(columnDbNameinvalidQueryInfoAry);
     }
 
     protected void xdoHandleInvalidQuery(String columnDbNameHpInvalidQueryInfo... invalidQueryInfoAry) {
         if (xgetSqlClause().isNullOrEmptyQueryChecked()) {
             throwInvalidQueryRegisteredException(invalidQueryInfoAry);
         } else {
             for (HpInvalidQueryInfo invalidQueryInfo : invalidQueryInfoAry) {
                 xgetSqlClause().saveInvalidQuery(invalidQueryInfo);
             }
         }
     }
 
     protected HpInvalidQueryInfo xcreateInvalidQueryInfo(ConditionKey keyObject valueString columnDbName) {
         final String locationBase = xgetLocationBase();
         final ColumnInfo targetColumn = xgetLocalDBMeta().findColumnInfo(columnDbName);
         final HpInvalidQueryInfo invalidQueryInfo = new HpInvalidQueryInfo(locationBasetargetColumnkeyvalue);
         if () {
             invalidQueryInfo.inlineView();
         } else if () {
             invalidQueryInfo.onClause();
         }
         return invalidQueryInfo;
     }
 
         return new QueryModeProvider() {
             public boolean isOrScopeQuery() {
                 return xgetSqlClause().isOrScopeQueryEffective();
             }
 
             public boolean isInline() {
                 return ;
             }
 
             public boolean isOnClause() {
                 return ;
             }
         };
     }
 
     protected void throwQueryAlreadyRegisteredException(ConditionKey keyObject valueConditionValue cvalueString columnDbName) {
         createCBExThrower().throwQueryAlreadyRegisteredException(keyvaluecvaluecolumnDbName);
     }
 
     protected void throwInvalidQueryRegisteredException(HpInvalidQueryInfo... invalidQueryInfoAry) {
         createCBExThrower().throwInvalidQueryRegisteredException(invalidQueryInfoAry);
     }
 
     // ===================================================================================
     //                                                                    LikeSearch Query
     //                                                                    ================
     protected void regLSQ(ConditionKey keyString valueConditionValue cvalueString columnDbNameLikeSearchOption option) {
         registerLikeSearchQuery(keyvaluecvaluecolumnDbNameoption);
     }
 
     protected void registerLikeSearchQuery(ConditionKey keyString valueConditionValue cvalueString columnDbName,
             LikeSearchOption option) {
         if (option == null) {
             throwLikeSearchOptionNotFoundException(columnDbNamevalue);
             return// unreachable
         }
         if (!prepareQueryChecked(keyvaluecvaluecolumnDbName).newClause()) {
             return;
         }
         if (xsuppressEscape()) {
             option.notEscape();
         }
         // basically for DBMS that has original wild-cards
         xgetSqlClause().adjustLikeSearchDBWay(option);
 
         if (value == null || !option.isSplit()) {
             if (option.canOptimizeCompoundColumnLikePrefix()) {
                 // - - - - - - - - - -
                 // optimized compound
                 // - - - - - - - - - -
                 doRegisterLikeSearchQueryCompoundOptimized(valuecvaluecolumnDbNameoption);
             } else {
                 // - - - - - - - - - - - - -
                 // normal or normal compound
                 // - - - - - - - - - - - - -
                 setupConditionValueAndRegisterWhereClause(keyvaluecvaluecolumnDbNameoption);
             }
             return;
         }
         // - - - - - - -
         // splitByXxx()
         // - - - - - - -
         doRegisterLikeSearchQuerySplitBy(keyvaluecvaluecolumnDbNameoption);
     }
 
     protected void doRegisterLikeSearchQueryCompoundOptimized(String valueConditionValue cvalueString columnDbName,
             LikeSearchOption option) {
         if (!option.isLikePrefix()) {
             String msg = "This optimization is only for LikePrefix: " + option;
             throw new IllegalStateException(msg);
         }
         // *char type only but no checked (cannot check)
         final List<SpecifiedColumncompoundColumnList = option.getCompoundColumnList();
         final List<IntegersizeList = option.getCompoundColumnSizeList();
         String currentValue = value;
         int currentLength = value.length();
         String currentColumn = columnDbName;
         final boolean needsAndPart = isOrScopeQueryDirectlyUnder();
         if (needsAndPart) {
             xgetSqlClause().beginOrScopeQueryAndPart();
         }
         try {
             boolean shortLengthBreak = false;
             final Iterator<SpecifiedColumncompoundColumnIterator = compoundColumnList.iterator();
             for (Integer columnSize : sizeList) { // should be less or equal column count (checked in option)
                 if (currentLength >= columnSize) { // can treat current condition as equal
                     final String equalValue = currentValue.substring(0, columnSize);
                     invokeQueryEqual(currentColumnequalValue);
                     currentValue = currentValue.substring(columnSize);
                     currentLength = currentValue.length();
                     final SpecifiedColumn specifiedColumn;
                     if (compoundColumnIterator.hasNext()) {
                         specifiedColumn = compoundColumnIterator.next();
                         currentColumn = specifiedColumn.getColumnDbName();
                     } else { // means just size
                         currentColumn = null// means end
                         break// though basically no need to break because of size loop end
                     }
                 } else { // short length condition value
                     shortLengthBreak = true;
                     break;
                 }
             }
             if (currentValue.length() > 0 && currentColumn != null) { // double check
                 final LikeSearchOption copyOption = option.createDeepCopy();
                 copyOption.clearCompoundColumn(); // also fixed sizes cleared
                 if (!shortLengthBreak) {
                     while (compoundColumnIterator.hasNext()) {
                         copyOption.addCompoundColumn(compoundColumnIterator.next());
                     }
                 }
                 invokeQueryLikeSearch(currentColumncurrentValuecopyOption);
             }
         } finally {
             if (needsAndPart) {
                 xgetSqlClause().endOrScopeQueryAndPart();
             }
         }
     }
 
     protected void doRegisterLikeSearchQuerySplitBy(ConditionKey keyString valueConditionValue cvalueString columnDbName,
             LikeSearchOption option) {
         assertObjectNotNull("option(LikeSearchOption)"option);
         // these values should be valid only (already filtered before)
         // and invalid values are ignored even at the check mode
         // but if all elements are invalid, it is an exception
         final String[] strArray = option.generateSplitValueArray(value);
         if (strArray.length == 0) {
             handleInvalidQuery(keyvaluecvaluecolumnDbName);
             return;
         }
         if (!option.isAsOrSplit()) {
             // as 'and' condition
             final boolean needsAndPart = isOrScopeQueryDirectlyUnder();
             if (needsAndPart) {
                 xgetSqlClause().beginOrScopeQueryAndPart();
             }
             try {
                 for (int i = 0; i < strArray.lengthi++) {
                     final String currentValue = strArray[i];
                     setupConditionValueAndRegisterWhereClause(keycurrentValuecvaluecolumnDbNameoption);
                 }
             } finally {
                 if (needsAndPart) {
                     xgetSqlClause().endOrScopeQueryAndPart();
                 }
             }
         } else {
             // as 'or' condition
             if (isOrScopeQueryAndPartEffective()) {
                 // limit because of so complex
                 String msg = "The AsOrSplit in and-part is unsupported: " + asTableDbName();
                 throw new OrScopeQueryAndPartUnsupportedOperationException(msg);
             }
             final boolean needsNewOrScope = !isOrScopeQueryEffective();
             if (needsNewOrScope) {
                 xgetSqlClause().beginOrScopeQuery();
             }
             try {
                 for (int i = 0; i < strArray.lengthi++) {
                     final String currentValue = strArray[i];
                     if (i == 0) {
                         setupConditionValueAndRegisterWhereClause(keycurrentValuecvaluecolumnDbNameoption);
                     } else {
                         invokeQueryLikeSearch(columnDbNamecurrentValueoption);
                     }
                 }
             } finally {
                 if (needsNewOrScope) {
                     xgetSqlClause().endOrScopeQuery();
                 }
             }
         }
     }
 
     protected void throwLikeSearchOptionNotFoundException(String columnDbNameString value) {
         final DBMeta dbmeta = xgetDBMetaProvider().provideDBMeta(asTableDbName());
         createCBExThrower().throwLikeSearchOptionNotFoundException(columnDbNamevaluedbmeta);
     }
 
     protected boolean xsuppressEscape() { // for override
         return false// as default
     }
 
     protected void invokeQueryLikeSearch(String columnFlexibleNameObject valueLikeSearchOption option) {
         invokeQuery(columnFlexibleName"likeSearch"valueoption);
     }
 
     protected boolean isOrScopeQueryDirectlyUnder() {
         final boolean orScopeQuery = isOrScopeQueryEffective();
         final boolean orScopeQueryAndPart = isOrScopeQueryAndPartEffective();
         return orScopeQuery && !orScopeQueryAndPart;
     }
 
     protected boolean isOrScopeQueryEffective() {
         return xgetSqlClause().isOrScopeQueryEffective();
     }
 
     protected boolean isOrScopeQueryAndPartEffective() {
         return xgetSqlClause().isOrScopeQueryAndPartEffective();
     }
 
     // ===================================================================================
     //                                                                        FromTo Query
     //                                                                        ============
     protected void regFTQ(Date fromDateDate toDateConditionValue cvalueString columnDbNameFromToOption option) {
         assertObjectNotNull("option(FromToOption)"option);
         filterFromToOption(columnDbNameoption); // for fixed option
 
         // this FromTo process is very similar to RangeOf process
         final Date filteredFromDate = option.filterFromDate(fromDate);
         final ConditionKey fromKey = option.getFromDateConditionKey();
         final ConditionKeyPrepareResult fromResult = prepareQueryNoCheck(fromKeyfilteredFromDatecvaluecolumnDbName);
 
         final Date filteredToDate = option.filterToDate(toDate);
         final ConditionKey toKey = option.getToDateConditionKey();
         final ConditionKeyPrepareResult toResult = prepareQueryNoCheck(toKeyfilteredToDatecvaluecolumnDbName);
 
         final boolean needsAndPart = isOrScopeQueryDirectlyUnder() && fromResult.newClause() && toResult.newClause();
         if (needsAndPart) {
             xgetSqlClause().beginOrScopeQueryAndPart();
         }
         try {
             if (fromResult.newClause()) {
                 final Object registered = filterFromToRegisteredDate(optionfilteredFromDatecolumnDbName);
                 setupConditionValueAndRegisterWhereClause(fromKeyregisteredcvaluecolumnDbName);
             }
             if (toResult.newClause()) {
                 final Object registered = filterFromToRegisteredDate(optionfilteredToDatecolumnDbName);
                 setupConditionValueAndRegisterWhereClause(toKeyregisteredcvaluecolumnDbName);
             }
             if (fromResult.invalid() && toResult.invalid()) {
                 xhandleFromToBothSideInvalidQuery(fromDatetoDatecolumnDbNameoptionfromKeytoKey);
             } else if (fromResult.invalid() || toResult.invalid()) {
                 xhandleFromToOneSideInvalidQuery(fromDatetoDatecolumnDbNameoptionfromKeytoKey);
             }
         } finally {
             if (needsAndPart) {
                 xgetSqlClause().endOrScopeQueryAndPart();
             }
         }
     }
 
     protected void filterFromToOption(String columnDbNameFromToOption option) {
         // do nothing as default, basically for option default
     }
 
     protected void xhandleFromToOneSideInvalidQuery(Date fromDateDate toDateString columnDbNameFromToOption option,
             ConditionKey fromKeyConditionKey toKey) {
         if (!option.isOneSideAllowed()) { // not allowed (if both required)
             xdoHandleFromToInvalidQuery(fromDatetoDatecolumnDbNameoptionfromKeytoKey);
        }
    }
    protected void xhandleFromToBothSideInvalidQuery(Date fromDateDate toDateString columnDbNameFromToOption option,
            ConditionKey fromKeyConditionKey toKey) {
        xdoHandleFromToInvalidQuery(fromDatetoDatecolumnDbNameoptionfromKeytoKey);
    }
    protected void xdoHandleFromToInvalidQuery(Date fromDateDate toDateString columnDbNameFromToOption optionConditionKey fromKey,
            ConditionKey toKey) {
        final List<ConditionKeykeyList = newArrayList(fromKeytoKey);
        final List<DatevalueList = newArrayList(fromDatetoDate);
        handleInvalidQueryList(keyListvalueListcolumnDbName);
    }
    // -----------------------------------------------------
    //                                        from LocalDate
    //                                        --------------
    // for conversion
    protected Date xfFTHD(Object dateString columnDbNameFromToOption option) { // filterFromToHandlingDate()
        final ColumnInfo columnInfo = xgetLocalDBMeta().findColumnInfo(columnDbName);
        if (xisNextTimeLocalDate(columnInfo.getObjectNativeType())) {
            return xtoFromToUtilDate(datecolumnDbNameoption);
        } else if (xisNextTimeLocalDateTime(columnInfo.getObjectNativeType())) {
            return xtoFromToTimestamp(datecolumnDbNameoption);
        }
        return xtoFromToUtilDate(datecolumnDbNameoption); // basically no way (generator controls it)
    }
    protected Date xtoFromToUtilDate(Object dateString columnDbNameFromToOption option) {
        final TimeZone realZone = xchooseFromToRealTimeZone(columnDbNameoption);
        return DfTypeUtil.toDate(daterealZone);
    }
    protected Timestamp xtoFromToTimestamp(Object dateString columnDbNameFromToOption option) {
        final TimeZone realZone = xchooseFromToRealTimeZone(columnDbNameoption);
        return DfTypeUtil.toTimestamp(daterealZone);
    }
    // -----------------------------------------------------
    //                                          to LocalDate
    //                                          ------------
    protected Object filterFromToRegisteredDate(FromToOption optionDate dateString columnDbName) {
        final ColumnInfo columnInfo = xgetLocalDBMeta().findColumnInfo(columnDbName);
        if (xisNextTimeLocalDate(columnInfo.getObjectNativeType())) {
            return xtoFromToLocalDate(datecolumnDbNameoption);
        } else if (xisNextTimeLocalDateTime(columnInfo.getObjectNativeType())) {
            return xtoFromToLocalDateTime(datecolumnDbNameoption);
        }
        return date;
    }
    protected Object xtoFromToLocalDate(Object dateString columnDbNameFromToOption option) { // #date_parade
        final TimeZone realZone = xchooseFromToRealTimeZone(columnDbNameoption);
        return DfTypeUtil.toLocalDate(daterealZone);
    }
    protected Object xtoFromToLocalDateTime(Object dateString columnDbNameFromToOption option) {
        final TimeZone realZone = xchooseFromToRealTimeZone(columnDbNameoption);
        return DfTypeUtil.toLocalDateTime(daterealZone);
    }
    // -----------------------------------------------------
    //                                      LocalDate Assist
    //                                      ----------------
    protected boolean xisNextTimeLocalDate(Class<?> nativeType) {
        return LocalDate.class.isAssignableFrom(nativeType);
    }
    protected boolean xisNextTimeLocalDateTime(Class<?> nativeType) {
        return LocalDateTime.class.isAssignableFrom(nativeType);
    }
    protected TimeZone xchooseFromToRealTimeZone(String columnDbNameFromToOption option) {
        final