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.sqlclause.subquery;
 
 import java.util.List;
 

Author(s):
jflute
Since:
0.9.7.2 (2010/06/20 Sunday)
 
 public class QueryDerivedReferrer extends DerivedReferrer {
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     protected final String _operand;
     protected final Object _value// null allowed: when IsNull or IsNotNull
     protected final String _parameterPath;
 
     // ===================================================================================
     //                                                                         Constructor
     //                                                                         ===========
     public QueryDerivedReferrer(SubQueryPath subQueryPathColumnRealNameProvider localRealNameProvider,
             ColumnSqlNameProvider subQuerySqlNameProviderint subQueryLevelSqlClause subQuerySqlClauseString subQueryIdentity,
             DBMeta subQueryDBMetaGearedCipherManager cipherManagerString mainSubQueryIdentityString operandObject value,
             String parameterPath) {
         super(subQueryPathlocalRealNameProvidersubQuerySqlNameProvidersubQueryLevelsubQuerySqlClausesubQueryIdentity,
                 subQueryDBMetacipherManagermainSubQueryIdentity);
          = operand;
          = value;
          = parameterPath;
     }
 
     // ===================================================================================
     //                                                                        Build Clause
     //                                                                        ============
     @Override
     protected String doBuildDerivedReferrer(String functionColumnRealName columnRealNameColumnSqlName relatedColumnSqlName,
             String subQueryClauseString beginMarkString endMarkString endIndent) {
         return buildCompleteClause(subQueryClausebeginMarkendMarkendIndent);
     }
 
     @Override
     protected String doBuildDerivedReferrer(String functionColumnRealName[] correlatedColumnRealNames,
             ColumnSqlName[] relatedColumnSqlNamesString subQueryClauseString beginMarkString endMarkString endIndent) {
         return buildCompleteClause(subQueryClausebeginMarkendMarkendIndent);
     }
 
     protected String buildCompleteClause(String subQueryClauseString beginMarkString endMarkString endIndent) {
         final StringBuilder sb = new StringBuilder();
         sb.append("(").append(beginMark).append(subQueryClause);
         sb.append(ln()).append(endIndent).append(") ");
         sb.append(); // e.g. "(select max(...) from ...) >"
         if ( != null) {
             sb.append(" "); // e.g. "(select max(...) from ...) > "
             if ( instanceof SpecifiedColumn) { // DreamCruise
                 // e.g. "(select max(...) from ...) > ZAMBINI_PRICE"
                 buildRightClauseDreamCruiseExp(sb);
             } else { // normally here
                 // e.g. "(select max(...) from ...) > 3"
                 buildRightClauseNormalValue(sb);
             }
         }
         sb.append(endMark);
         return sb.toString();
     }
 
     protected void buildRightClauseDreamCruiseExp(StringBuilder sb) {
         final SpecifiedColumn specifiedColumn = (SpecifiedColumn;
         final String columnExp = specifiedColumn.toColumnRealName().toString();
         final String appended;
         if (specifiedColumn.hasSpecifyCalculation()) {
             specifiedColumn.xinitSpecifyCalculation();
             final HpCalcSpecification<ConditionBeancalcSpecification = specifiedColumn.getSpecifyCalculation();
             appended = calcSpecification.buildStatementToSpecifidName(columnExp);
        } else {
            appended = columnExp;
        }
        sb.append(appended);
    }
    protected void buildRightClauseNormalValue(final StringBuilder sb) {
        final String prefix = "/*pmb.";
        final String suffix = "*/null";
        final String parameter;
        if (isOperandBetween() && isValueListType()) {
            final String fromParameter = buildListParameter(prefix, 0, suffix);
            final String toParameter = buildListParameter(prefix, 1, suffix);
            parameter = fromParameter + " and " + toParameter;
        } else {
            parameter = prefix +  + suffix;
        }
        sb.append(parameter);
    }
    protected boolean isOperandBetween() {
        return "between".equalsIgnoreCase();
    }
    protected boolean isValueListType() {
        return  instanceof List<?>;
    }
    protected String buildListParameter(String prefixint indexString suffix) {
        return prefix +  + ".get(" + index + ")" + suffix;
    }
    @Override
    }
    @Override
    protected void doAssertDerivedReferrerColumnType(String functionString derivedColumnDbNameClass<?> derivedColumnType) {
        final Object value = ;
        if ("sum".equalsIgnoreCase(function) || "avg".equalsIgnoreCase(function)) {
            if (!Number.class.isAssignableFrom(derivedColumnType)) {
                throwQueryDerivedReferrerUnmatchedColumnTypeException(functionderivedColumnDbNamederivedColumnType);
            }
        }
        if (value != null) {
            final Class<?> parameterType = value.getClass();
            if (String.class.isAssignableFrom(derivedColumnType)) {
                if (!String.class.isAssignableFrom(parameterType)) {
                    throwQueryDerivedReferrerUnmatchedColumnTypeException(functionderivedColumnDbNamederivedColumnType);
                }
            }
            if (Number.class.isAssignableFrom(derivedColumnType)) {
                if (!Number.class.isAssignableFrom(parameterType)) {
                    throwQueryDerivedReferrerUnmatchedColumnTypeException(functionderivedColumnDbNamederivedColumnType);
                }
            }
            if (java.util.Date.class.isAssignableFrom(derivedColumnType)) {
                if (!java.util.Date.class.isAssignableFrom(parameterType)) {
                    throwQueryDerivedReferrerUnmatchedColumnTypeException(functionderivedColumnDbNamederivedColumnType);
                }
            }
        }
    }
    protected void throwQueryDerivedReferrerUnmatchedColumnTypeException(String functionString derivedColumnDbName,
            Class<?> derivedColumnType) {
        createCBExThrower().throwQueryDerivedReferrerUnmatchedColumnTypeException(functionderivedColumnDbNamederivedColumnType);
    }
New to GrepCode? Check out our FAQ X