Search in sources :

Example 11 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfPmbPropertyOptionReference method getPmbMetaDataPropertyOptionReferenceColumn.

// ===================================================================================
// Reference Column
// ================
public Column getPmbMetaDataPropertyOptionReferenceColumn(AppData appData) {
    if (appData == null) {
        return null;
    }
    final Database database = appData.getDatabase();
    if (database == null) {
        return null;
    }
    final String refPrefix = OPTION_PREFIX;
    final String refSuffix = OPTION_SUFFIX;
    final String option;
    {
        final String optionExp = getPmbMetaDataPropertyOption();
        if (optionExp == null) {
            return null;
        }
        final List<String> splitOption = splitOption(optionExp);
        String firstOption = null;
        for (String element : splitOption) {
            if (element.startsWith(refPrefix) && element.endsWith(refSuffix)) {
                firstOption = element;
                break;
            }
        }
        if (firstOption == null) {
            return null;
        }
        option = firstOption;
    }
    final ScopeInfo scope = Srl.extractScopeFirst(option, refPrefix, refSuffix);
    final String content = scope.getContent().trim();
    final String delimiter = ".";
    final String tableName;
    final String columnName;
    if (content.contains(".")) {
        tableName = Srl.substringFirstFront(content, delimiter);
        columnName = Srl.substringFirstRear(content, delimiter);
    } else {
        tableName = content;
        columnName = null;
    }
    final Table table = database.getTable(tableName);
    if (table == null) {
        throwParameterBeanReferenceTableNotFoundException(option, tableName);
    }
    final String columnKeyName;
    if (columnName != null) {
        columnKeyName = columnName;
    } else {
        if (_pmbMetaData.isPropertyTypeList(_propertyName) && Srl.endsWith(_propertyName, "List")) {
            // e.g. statusList to status
            columnKeyName = Srl.substringLastFront(_propertyName, "List");
        } else {
            columnKeyName = _propertyName;
        }
    }
    final Column column = table.getColumn(columnKeyName);
    if (column == null) {
        throwParameterBeanReferenceColumnNotFoundException(option, tableName, columnName);
    }
    return column;
}
Also used : Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column) Database(org.apache.torque.engine.database.model.Database) List(java.util.List) ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 12 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfIncludeQueryProperties method extractColumnDrivenTranslatedMap.

protected Map<String, Map<String, Map<String, List<String>>>> extractColumnDrivenTranslatedMap(Map<String, Object> plainMap) {
    final Map<String, Map<String, List<String>>> interfaceMap = extractColumnDrivenInterfaceMap(plainMap);
    final Map<String, Map<String, Map<String, List<String>>>> translatedMap = newLinkedHashMap();
    for (Entry<String, Map<String, List<String>>> tableEntry : interfaceMap.entrySet()) {
        final String tableName = tableEntry.getKey();
        final Map<String, List<String>> columnTypeCKeyMap = tableEntry.getValue();
        for (Entry<String, List<String>> columnTypeCKeyEntry : columnTypeCKeyMap.entrySet()) {
            final String columnExp = columnTypeCKeyEntry.getKey();
            final String columnName = Srl.substringFirstFront(columnExp, "(").trim();
            final ScopeInfo scopeFirst = Srl.extractScopeFirst(columnExp, "(", ")");
            if (scopeFirst == null) {
                String msg = "The column expression should be e.g. Member(Date) but: " + columnExp;
                throw new DfIllegalPropertySettingException(msg);
            }
            // e.g. String, OrderBy
            final String propType = scopeFirst.getContent().trim();
            final List<String> ckeyList = columnTypeCKeyEntry.getValue();
            Map<String, Map<String, List<String>>> ckeyColumnMap = translatedMap.get(propType);
            if (ckeyColumnMap == null) {
                ckeyColumnMap = newLinkedHashMap();
                translatedMap.put(propType, ckeyColumnMap);
            }
            for (String ckey : ckeyList) {
                Map<String, List<String>> tableColumnMap = ckeyColumnMap.get(ckey);
                if (tableColumnMap == null) {
                    tableColumnMap = newLinkedHashMap();
                    ckeyColumnMap.put(ckey, tableColumnMap);
                }
                List<String> columnList = tableColumnMap.get(tableName);
                if (columnList == null) {
                    columnList = new ArrayList<String>();
                    tableColumnMap.put(tableName, columnList);
                }
                columnList.add(columnName);
            }
        }
    }
    return translatedMap;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 13 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfStringUtilTest method test_extractScopeList_replaceContentOnBaseString.

public void test_extractScopeList_replaceContentOnBaseString() {
    // ## Arrange ##
    String str = "/*foo*/foo/*bar*/bar/*foobarbaz*/";
    // ## Act ##
    List<ScopeInfo> list = extractScopeList(str, "/*", "*/");
    // ## Assert ##
    ScopeInfo scope = list.get(1);
    String baseString1 = scope.replaceContentOnBaseString("foo", "jflute");
    assertEquals("/*jflute*/foo/*bar*/bar/*jflutebarbaz*/", baseString1);
    String baseString2 = scope.replaceContentOnBaseString("*", "jflute");
    // marks no change
    assertEquals(str, baseString2);
    // no change
    assertEquals(str, scope.getBaseString());
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 14 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfStringUtilTest method test_extractScopeFirst_various.

public void test_extractScopeFirst_various() {
    ScopeInfo scope = extractScopeFirst("FOObeginBARendDODO", "begin", "end");
    log("baseString: " + scope.getBaseString());
    log("beginIndex: " + scope.getBeginIndex());
    log("endIndex: " + scope.getEndIndex());
    log("beginMark: " + scope.getBeginMark());
    log("endMark: " + scope.getEndMark());
    log("scope: " + scope.getScope());
    log("content: " + scope.getContent());
    log("previous: " + scope.getPrevious());
    log("next: " + scope.getNext());
    log("substringInterspaceToPrevious(): " + scope.substringInterspaceToPrevious());
    log("substringInterspaceToNext(): " + scope.substringInterspaceToNext());
    log("substringScopeToPrevious(): " + scope.substringScopeToPrevious());
    log("substringScopeToNext(): " + scope.substringScopeToNext());
    log("replaceContentOnBaseString(): " + scope.replaceContentOnBaseString("SEA"));
    log("replaceContentOnBaseString(): " + scope.replaceContentOnBaseString("A", "B"));
    log("replaceInterspaceOnBaseString(): " + scope.replaceInterspaceOnBaseString("O", "R"));
    assertEquals("FOObeginBARendDODO", scope.getBaseString());
    assertEquals("beginBARend", scope.getScope());
    assertEquals("BAR", scope.getContent());
    assertNull(scope.getPrevious());
    assertNull(scope.getNext());
    assertEquals("FOO", scope.substringInterspaceToPrevious());
    assertEquals("DODO", scope.substringInterspaceToNext());
    assertEquals("FOObeginBARend", scope.substringScopeToPrevious());
    assertEquals("beginBARendDODO", scope.substringScopeToNext());
    assertEquals("FOObeginSEAendDODO", scope.replaceContentOnBaseString("SEA"));
    assertEquals("FOObeginBBRendDODO", scope.replaceContentOnBaseString("A", "B"));
    assertEquals("FRRbeginBARendDRDR", scope.replaceInterspaceOnBaseString("O", "R"));
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 15 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfSPolicyLogicalSecretary method parseStatement.

// ===================================================================================
// Statement
// =========
public DfSPolicyStatement parseStatement(String statement) {
    if (!statement.startsWith("if ")) {
        String msg = "The element of statementList should start with 'if' for SchemaPolicyCheck: " + statement;
        throw new IllegalStateException(msg);
    }
    final ScopeInfo ifScope = Srl.extractScopeFirst(statement, "if ", " then ");
    if (ifScope == null) {
        final String additional = "The statement should start with 'if' and contain 'then'.";
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    final DfSPolicyIfClause ifClause = analyzeIfClause(statement, ifScope);
    final DfSPolicyThenClause thenClause = analyzeThenClause(statement, ifScope);
    return new DfSPolicyStatement(statement, ifClause, thenClause);
}
Also used : DfSPolicyStatement(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement) DfSPolicyThenClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Aggregations

ScopeInfo (org.dbflute.util.Srl.ScopeInfo)42 File (java.io.File)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 FileTextIO (org.dbflute.helper.filesystem.FileTextIO)6 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)4 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Set (java.util.Set)3 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 DfBuildProperties (org.dbflute.DfBuildProperties)2 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 FileHierarchyTracer (org.dbflute.helper.filesystem.FileHierarchyTracer)2