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.twowaysql.node;
 
 import java.util.List;
 

Author(s):
jflute
 
 public abstract class VariableNode extends AbstractNode implements LoopAcceptable {
 
     // ===================================================================================
     //                                                                          Definition
     //                                                                          ==========
     protected static final String INLOOP_OPTION_LIKE_PREFIX = "likePrefix";
     protected static final String INLOOP_OPTION_LIKE_SUFFIX = "likeSuffix";
     protected static final String INLOOP_OPTION_LIKE_CONTAIN = "likeContain";
     protected static final String INLOOP_OPTION_NOT_LIKE = "notLike";
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     protected final String _expression;
     protected final String _testValue;
     protected final String _optionDef;
     protected final List<String_nameList;
     protected final String _specifiedSql;
     protected final boolean _blockNullParameter;
     protected final NodeAdviceFactory _nodeAdviceFactory;
 
     // ===================================================================================
     //                                                                         Constructor
     //                                                                         ===========
     public VariableNode(String expressionString testValueString specifiedSqlboolean blockNullParameter,
             NodeAdviceFactory nodeAdviceFactory) {
         if (expression.contains(":")) {
              = Srl.substringFirstFront(expression":").trim();
              = Srl.substringFirstRear(expression":").trim();
         } else {
              = expression;
              = null;
         }
          = testValue;
          = Srl.splitList(".");
          = specifiedSql;
          = blockNullParameter;
          = nodeAdviceFactory;
     }
 
     // ===================================================================================
     //                                                                              Accept
     //                                                                              ======
     public void accept(CommandContext ctx) {
         doAccept(ctxnull);
     }
 
     public void accept(CommandContext ctxLoopInfo loopInfo) { // for FOR comment
         final String firstName = .get(0);
         if (firstName.equals(.)) { // use loop element
             final Object parameter = loopInfo.getCurrentParameter();
             final Class<?> parameterType = loopInfo.getCurrentParameterType();
             doAccept(ctxparameterparameterTypeloopInfotrue);
         } else { // normal
             doAccept(ctxloopInfo);
         }
     }
 
     protected void doAccept(CommandContext ctxLoopInfo loopInfo) {
         final String firstName = .get(0);
         assertFirstNameAsNormal(ctxfirstName);
         final Object firstValue = ctx.getArg(firstName);
         final Class<?> firstType = ctx.getArgType(firstName);
         doAccept(ctxfirstValuefirstTypeloopInfofalse);
     }
 
     protected void doAccept(CommandContext ctxObject firstValueClass<?> firstTypeLoopInfo loopInfoboolean inheritLoop) {
         assertInLoopOnlyOptionInLoop(loopInfo);
         final BoundValue boundValue = new BoundValue();
         boundValue.setFirstValue(firstValue);
         boundValue.setFirstType(firstType);
         setupBoundValue(boundValue);
         processLikeSearch(boundValueloopInfoinheritLoop);
        if ( && boundValue.getTargetValue() == null) {
        }
        doProcess(ctxboundValueloopInfo);
    }
    protected abstract void doProcess(CommandContext ctxBoundValue boundValueLoopInfo loopInfo);
    protected void assertFirstNameAsNormal(CommandContext ctxString firstName) {
        if (NodeChecker.isCurrentVariableOutOfScope(firstNamefalse)) {
        }
        if (NodeChecker.isWrongParameterBeanName(firstNamectx)) {
        }
    }
    }
    protected void setupBoundValue(BoundValue boundValue) {
        final ParameterCommentType commentType = getCommentType();
        final BoundValueTracer tracer = createBoundValueTracer(commentType);
        tracer.trace(boundValue);
    }
    }
    protected abstract ParameterCommentType getCommentType();
    // ===================================================================================
    //                                                                   LikeSearch Helper
    //                                                                   =================
    protected void processLikeSearch(BoundValue boundValueLoopInfo loopInfoboolean inheritLoop) {
        if (!isAcceptableLikeSearch(loopInfo)) {
            return;
        }
        final FilteringBindOption inLoopForcedLikeSearchOption = getInLoopForcedLikeSearchOption(loopInfo);
        if (inLoopForcedLikeSearchOption != null) { // forced option
            boundValue.setFilteringBindOption(inLoopForcedLikeSearchOption);
        } else {
            if (inheritLoop) {
                boundValue.inheritLikeSearchOptionIfNeeds(loopInfo);
            }
        }
        boundValue.filterValueByOptionIfNeeds();
    }
    protected boolean isAcceptableLikeSearch(LoopInfo loopInfo) {
        if (loopInfo != null && Srl.is_NotNull_and_NotTrimmedEmpty()) {
            final List<StringoptionList = Srl.splitListTrimmed("|");
            if (optionList.contains()) {
                return false// specified not-like in loop
            }
        }
        return true// basically true
    }
        if (Srl.is_NotNull_and_NotTrimmedEmpty()) {
            final List<StringoptionList = Srl.splitListTrimmed("|");
            for (String option : optionList) {
                return createLikeSearchOption(option);
            }
        }
        return null;
    }
    protected FilteringBindOption createLikeSearchOption(String likeDirection) {
        return .createInLoopLikeSearchOption(likeDirection);
    }
    protected void assertInLoopOnlyOptionInLoop(LoopInfo loopInfo) {
        if (loopInfo == null && Srl.is_NotNull_and_NotTrimmedEmpty()) {
            final String onlyInLoop = ;
            final List<StringoptionList = Srl.splitListTrimmed("|");
            for (String option : optionList) {
                if (onlyInLoop.equals(option)) {
                    // means 'notLike' is specified at out of loop
                    throwInLoopOptionOutOfLoopException();
                }
            }
        }
    }
    protected void setupRearOption(CommandContext ctxBoundValue boundValue) { // for sub-class
        final String rearOption = boundValue.buildRearOptionOnSql();
        if (Srl.is_NotNull_and_NotTrimmedEmpty(rearOption)) {
            ctx.addSql(rearOption);
        }
    }
    // ===================================================================================
    //                                                                      InScope Helper
    //                                                                      ==============
    protected boolean isInScope() {
        if ( == null) {
            return false;
        }
        return .startsWith("(") && .endsWith(")");
    }
    // ===================================================================================
    //                                                                           Exception
    //                                                                           =========
        final Class<?> targetType = boundValue.getTargetType();
    }
    protected void throwBindOrEmbeddedCommentInScopeNotListException(BoundValue boundValue) {
        final Class<?> targetType = boundValue.getTargetType();
    }
    }
    }
    }
    protected void throwInLoopOptionOutOfLoopException() {
    }
    protected boolean isBind() {
    }
    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
    public String getExpression() {
        return ;
    }
    public String getTestValue() {
        return ;
    }
    public String getOptionDef() {
        return ;
    }
    public boolean isBlockNullParameter() {
        return ;
    }
New to GrepCode? Check out our FAQ X