Search in sources :

Example 1 with BindVariableNode

use of org.dbflute.twowaysql.node.BindVariableNode in project dbflute-core by dbflute.

the class DfParameterAutoDetectForNode method analyzeForNodeElementType.

protected DfForNodeDetectedPropertyInfo analyzeForNodeElementType(Node node, String propertyName) {
    if (isPmCommentNestedProperty(propertyName) || isPmCommentMethodCall(propertyName)) {
        return null;
    }
    final DfLanguageGrammar grammar = getLanguageGrammar();
    DfForNodeDetectedPropertyInfo detected = null;
    for (int i = 0; i < node.getChildSize(); i++) {
        final Node childNode = node.getChild(i);
        if (childNode instanceof BindVariableNode) {
            final BindVariableNode bindNode = (BindVariableNode) childNode;
            final String expression = bindNode.getExpression();
            if (!isPmCommentEqualsCurrent(expression)) {
                continue;
            }
            if (isPmCommentNestedProperty(expression) || isPmCommentMethodCall(expression)) {
                continue;
            }
            // /*#current*/ here
            final String testValue = bindNode.getTestValue();
            if (testValue == null) {
                continue;
            }
            final String propertyType = derivePropertyTypeFromTestValue(testValue);
            final String propertyOption = derivePropertyOptionFromTestValue(testValue);
            if (Srl.is_NotNull_and_NotTrimmedEmpty(propertyType)) {
                detected = new DfForNodeDetectedPropertyInfo();
                final String generic = grammar.buildGenericOneClassHint(propertyType);
                detected.setPropertyType("List" + generic);
                detected.setPropertyOption(propertyOption);
            }
        } else if (childNode instanceof ForNode) {
            final ForNode nestedNode = (ForNode) childNode;
            final String expression = nestedNode.getExpression();
            if (!isPmCommentStartsWithCurrent(expression)) {
                continue;
            }
            // /*FOR #current.xxx*/ here
            final String nestedForPropName = substringPmCommentCurrentRear(expression);
            // recursive call
            detected = analyzeForNodeElementType(nestedNode, nestedForPropName);
            if (detected != null) {
                final String generic = grammar.buildGenericOneClassHint(detected.getPropertyType());
                detected.setPropertyType("List" + generic);
            }
        } else if (childNode instanceof ScopeNode) {
            // IF, Begin, First, ...
            // recursive call
            detected = analyzeForNodeElementType(childNode, propertyName);
        }
        if (detected != null) {
            break;
        }
    }
    if (detected == null) {
        return null;
    }
    return detected;
}
Also used : ForNode(org.dbflute.twowaysql.node.ForNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode) ScopeNode(org.dbflute.twowaysql.node.ScopeNode) Node(org.dbflute.twowaysql.node.Node) ForNode(org.dbflute.twowaysql.node.ForNode) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) ScopeNode(org.dbflute.twowaysql.node.ScopeNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode)

Example 2 with BindVariableNode

use of org.dbflute.twowaysql.node.BindVariableNode in project dbflute-core by dbflute.

the class DfParameterAutoDetectProcess method doProcessAutoDetect.

protected void doProcessAutoDetect(String sql, Map<String, String> propertyNameTypeMap, Map<String, String> propertyNameOptionMap, Set<String> autoDetectedPropertyNameSet, Node node) {
    // because simple specification is very important here
    if (node instanceof BindVariableNode) {
        final BindVariableNode bindNode = (BindVariableNode) node;
        processAutoDetectBindNode(sql, propertyNameTypeMap, propertyNameOptionMap, autoDetectedPropertyNameSet, bindNode);
    } else if (node instanceof IfNode) {
        final IfNode ifNode = (IfNode) node;
        processAutoDetectIfNode(sql, propertyNameTypeMap, propertyNameOptionMap, ifNode);
        // process alternate boolean methods, supported with auto-detect
        processAlternateBooleanMethodIfNode(sql, ifNode);
    } else if (node instanceof ForNode) {
        processAutoDetectForNode(sql, propertyNameTypeMap, propertyNameOptionMap, (ForNode) node);
    }
    for (int i = 0; i < node.getChildSize(); i++) {
        final Node childNode = node.getChild(i);
        // recursive call
        doProcessAutoDetect(sql, propertyNameTypeMap, propertyNameOptionMap, autoDetectedPropertyNameSet, childNode);
    }
}
Also used : ForNode(org.dbflute.twowaysql.node.ForNode) IfNode(org.dbflute.twowaysql.node.IfNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode) Node(org.dbflute.twowaysql.node.Node) ForNode(org.dbflute.twowaysql.node.ForNode) IfNode(org.dbflute.twowaysql.node.IfNode) BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode)

Example 3 with BindVariableNode

use of org.dbflute.twowaysql.node.BindVariableNode in project dbflute-core by dbflute.

the class SqlAnalyzer method parseCommentBindVariable.

protected void parseCommentBindVariable() {
    // main binding on DBFlute
    final String expr = _tokenizer.getToken();
    final String testValue = _tokenizer.skipToken(true);
    if (expr.startsWith(EmbeddedVariableNode.PREFIX_NORMAL)) {
        if (expr.startsWith(EmbeddedVariableNode.PREFIX_REPLACE_ONLY)) {
            // replaceOnly
            peek().addChild(prepareReplaceOnlyEmbeddedVariableNode(expr, testValue, /*removePrefix*/
            true));
        } else if (expr.startsWith(EmbeddedVariableNode.PREFIX_TERMINAL_DOT)) {
            // terminalDot
            peek().addChild(prepareTerminalDotEmbeddedVariableNode(expr, testValue));
        } else {
            // normal
            peek().addChild(prepareNormalEmbeddedVariableNode(expr, testValue));
        }
    } else {
        final Node bindVariableNode;
        if (_switchBindingToReplaceOnlyEmbedded) {
            // false on DBFlute, for general purpose
            bindVariableNode = prepareReplaceOnlyEmbeddedVariableNode(expr, testValue, /*removePrefix*/
            false);
        } else {
            // always here on DBFlute
            bindVariableNode = createBindVariableNode(expr, testValue);
        }
        peek().addChild(bindVariableNode);
    }
}
Also used : BindVariableNode(org.dbflute.twowaysql.node.BindVariableNode) LoopFirstNode(org.dbflute.twowaysql.node.LoopFirstNode) ForNode(org.dbflute.twowaysql.node.ForNode) BeginNode(org.dbflute.twowaysql.node.BeginNode) SqlPartsNode(org.dbflute.twowaysql.node.SqlPartsNode) EmbeddedVariableNode(org.dbflute.twowaysql.node.EmbeddedVariableNode) SqlConnectorNode(org.dbflute.twowaysql.node.SqlConnectorNode) LoopNextNode(org.dbflute.twowaysql.node.LoopNextNode) ElseNode(org.dbflute.twowaysql.node.ElseNode) LoopLastNode(org.dbflute.twowaysql.node.LoopLastNode) LoopAbstractNode(org.dbflute.twowaysql.node.LoopAbstractNode) RootNode(org.dbflute.twowaysql.node.RootNode) IfNode(org.dbflute.twowaysql.node.IfNode) Node(org.dbflute.twowaysql.node.Node)

Aggregations

BindVariableNode (org.dbflute.twowaysql.node.BindVariableNode)3 ForNode (org.dbflute.twowaysql.node.ForNode)3 Node (org.dbflute.twowaysql.node.Node)3 IfNode (org.dbflute.twowaysql.node.IfNode)2 DfLanguageGrammar (org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)1 BeginNode (org.dbflute.twowaysql.node.BeginNode)1 ElseNode (org.dbflute.twowaysql.node.ElseNode)1 EmbeddedVariableNode (org.dbflute.twowaysql.node.EmbeddedVariableNode)1 LoopAbstractNode (org.dbflute.twowaysql.node.LoopAbstractNode)1 LoopFirstNode (org.dbflute.twowaysql.node.LoopFirstNode)1 LoopLastNode (org.dbflute.twowaysql.node.LoopLastNode)1 LoopNextNode (org.dbflute.twowaysql.node.LoopNextNode)1 RootNode (org.dbflute.twowaysql.node.RootNode)1 ScopeNode (org.dbflute.twowaysql.node.ScopeNode)1 SqlConnectorNode (org.dbflute.twowaysql.node.SqlConnectorNode)1 SqlPartsNode (org.dbflute.twowaysql.node.SqlPartsNode)1