Search in sources :

Example 1 with DfSPolicyIfPart

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart in project dbflute-core by dbflute.

the class DfSPolicyLogicalSecretaryTest method createMockStatement.

protected DfSPolicyStatement createMockStatement() {
    List<DfSPolicyIfPart> ifPartList = newArrayList(new DfSPolicyIfPart("columnName", "$$ALL$$", false));
    DfSPolicyIfClause ifClause = new DfSPolicyIfClause(ifPartList, false);
    DfSPolicyThenClause thenClause = new DfSPolicyThenClause("bad", false, DfCollectionUtil.emptyList(), false, null);
    return new DfSPolicyStatement("if columnName is $$ALL$$ then bad", ifClause, thenClause);
}
Also used : DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) DfSPolicyStatement(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement) DfSPolicyThenClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Example 2 with DfSPolicyIfPart

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart in project dbflute-core by dbflute.

the class DfSPolicyLogicalSecretary method analyzeIfClause.

// -----------------------------------------------------
// If Clause
// ---------
protected DfSPolicyIfClause analyzeIfClause(String statement, ScopeInfo ifScope) {
    final String ifWhole = ifScope.getContent().trim();
    if (!ifWhole.contains(EQUALS_DELIMITER)) {
        final String additional = "The if-clause should contain 'is': " + ifWhole;
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    // e.g. if tableName is sea and alias is land and piari and tableName is bonvo then ...
    boolean connectedByOr = false;
    List<String> ifPartStrList = splitClauseByConnector(ifWhole, " and ");
    if (ifPartStrList.size() == 1) {
        ifPartStrList = splitClauseByConnector(ifWhole, " or ");
        if (ifPartStrList.size() >= 2) {
            connectedByOr = true;
        }
    }
    final List<DfSPolicyIfPart> ifPartList = new ArrayList<DfSPolicyIfPart>();
    for (String ifPartStr : ifPartStrList) {
        final String ifItem = Srl.substringFirstFront(ifPartStr, EQUALS_DELIMITER).trim();
        final String ifValueCandidate = Srl.substringFirstRear(ifPartStr, EQUALS_DELIMITER).trim();
        final boolean notIfValue = ifValueCandidate.startsWith(NOT_PREFIX);
        final String ifValue = notIfValue ? Srl.substringFirstRear(ifValueCandidate, NOT_PREFIX).trim() : ifValueCandidate;
        final DfSPolicyIfPart part = new DfSPolicyIfPart(ifItem, ifValue, notIfValue);
        ifPartList.add(part);
    }
    return new DfSPolicyIfClause(Collections.unmodifiableList(ifPartList), connectedByOr);
}
Also used : DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) ArrayList(java.util.ArrayList) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Example 3 with DfSPolicyIfPart

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart in project dbflute-core by dbflute.

the class DfSPolicyMiscSecretary method analyzeIfClause.

// -----------------------------------------------------
// If Clause
// ---------
protected DfSPolicyIfClause analyzeIfClause(String statement, ScopeInfo ifScope) {
    final String ifWhole = ifScope.getContent().trim();
    if (!ifWhole.contains(EQUALS_DELIMITER)) {
        final String additional = "The if-clause should contain 'is': " + ifWhole;
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    // e.g. if tableName is sea and alias is land and piari and tableName is bonvo then ...
    boolean connectedByOr = false;
    List<String> ifPartStrList = splitClauseByConnector(ifWhole, " and ");
    if (ifPartStrList.size() == 1) {
        ifPartStrList = splitClauseByConnector(ifWhole, " or ");
        if (ifPartStrList.size() >= 2) {
            connectedByOr = true;
        }
    }
    final List<DfSPolicyIfPart> ifPartList = new ArrayList<DfSPolicyIfPart>();
    for (String ifPartStr : ifPartStrList) {
        final String ifItem = Srl.substringFirstFront(ifPartStr, EQUALS_DELIMITER).trim();
        final String ifValueCandidate = Srl.substringFirstRear(ifPartStr, EQUALS_DELIMITER).trim();
        final boolean notIfValue = ifValueCandidate.startsWith(NOT_PREFIX);
        final String ifValue = notIfValue ? Srl.substringFirstRear(ifValueCandidate, NOT_PREFIX).trim() : ifValueCandidate;
        final DfSPolicyIfPart part = new DfSPolicyIfPart(ifItem, ifValue, notIfValue);
        ifPartList.add(part);
    }
    return new DfSPolicyIfClause(Collections.unmodifiableList(ifPartList), connectedByOr);
}
Also used : DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) ArrayList(java.util.ArrayList) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Aggregations

DfSPolicyIfClause (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)3 DfSPolicyIfPart (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart)3 ArrayList (java.util.ArrayList)2 DfSPolicyStatement (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement)1 DfSPolicyThenClause (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause)1