Search in sources :

Example 1 with DfSql2EntityMarkAnalyzer

use of org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer in project dbflute-core by dbflute.

the class DfSql2EntityMarkAnalyzerTest method test_getSelectColumnCommentMap_real.

public void test_getSelectColumnCommentMap_real() {
    // ## Arrange ##
    DfSql2EntityMarkAnalyzer analyzer = new DfSql2EntityMarkAnalyzer();
    StringBuilder sb = new StringBuilder();
    sb.append("select member.MEMBER_ID");
    sb.append(ln()).append(" , member.MEMBER_NAME");
    sb.append(ln()).append(" , member.BIRTHDATE -- // select column comment here (no as)");
    sb.append(ln()).append(" , member.FORMALIZED_DATETIME as FORMALIZED_DATETIME -- // select column comment here (using as)");
    sb.append(ln()).append(" , member.MEMBER_STATUS_CODE -- for Classification Test of Sql2Entity");
    sb.append(ln()).append(" , memberStatus.MEMBER_STATUS_NAME");
    sb.append(ln()).append(" , memberStatus.DISPLAY_ORDER as STATUS_DISPLAY_ORDER -- for Alias Name Test");
    sb.append(ln()).append(" , 0 as DUMMY_FLG -- // for Classification Test of Sql2Entity");
    sb.append(ln()).append(" , 0 as DUMMY_NOFLG -- // for Classification Test of Sql2Entity");
    // ## Act ##
    Map<String, String> commentMap = analyzer.getSelectColumnCommentMap(sb.toString());
    // ## Assert ##
    log(commentMap);
    assertEquals("select column comment here (no as)", commentMap.get("BIRTHDATE"));
    assertEquals("select column comment here (using as)", commentMap.get("FORMALIZED_DATETIME"));
    assertEquals("for Classification Test of Sql2Entity", commentMap.get("DUMMY_FLG"));
    assertEquals("for Classification Test of Sql2Entity", commentMap.get("DUMMY_NOFLG"));
}
Also used : DfSql2EntityMarkAnalyzer(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer)

Example 2 with DfSql2EntityMarkAnalyzer

use of org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer in project dbflute-core by dbflute.

the class DfPmFileTableLoader method processSpecifiedDetect.

protected void processSpecifiedDetect(String fileText, Map<String, String> propertyNameTypeMap, Map<String, String> propertyNameOptionMap, Set<String> propertyNameSet) {
    final List<DfSql2EntityMark> propertyTypeList = new DfSql2EntityMarkAnalyzer().getParameterBeanPropertyTypeList(fileText);
    for (DfSql2EntityMark mark : propertyTypeList) {
        final String content = mark.getContent();
        final String propertyType = Srl.substringFirstFront(content, " ").trim();
        final String propertyName = Srl.substringFirstRear(content, " ").trim();
        propertyNameTypeMap.put(propertyName, resolvePackageName(propertyType));
        propertyNameSet.add(propertyName);
    }
}
Also used : DfSql2EntityMarkAnalyzer(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer) DfSql2EntityMark(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMark)

Example 3 with DfSql2EntityMarkAnalyzer

use of org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer in project dbflute-core by dbflute.

the class DfOutsideSqlChecker method checkRequiredTitle.

// -----------------------------------------------------
// Required Title
// --------------
protected void checkRequiredTitle(String fileName, String sql) {
    if (!_requiredTitleCheck) {
        return;
    }
    final DfSql2EntityMarkAnalyzer analyzer = new DfSql2EntityMarkAnalyzer();
    final String title = analyzer.getTitle(sql);
    if (isInvalidTitle(title)) {
        throwRequiredOutsideSqlTitleNotFoundException(title, fileName, sql);
    }
    if (!_suppressTitleUniqueCheck) {
        final String otherFileName = _outsideSqlTitleSet.get(title);
        if (otherFileName != null) {
            throwRequiredOutsideSqlTitleSameWithOtherSqlException(title, otherFileName, fileName, sql);
        }
        _outsideSqlTitleSet.put(title, fileName);
    }
}
Also used : DfSql2EntityMarkAnalyzer(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer)

Example 4 with DfSql2EntityMarkAnalyzer

use of org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer in project dbflute-core by dbflute.

the class DfBehaviorQueryPathSetupper method setupInfoInSqlFile.

protected void setupInfoInSqlFile(DfOutsideSqlFile outsideSqlFile, Map<String, String> elementMap) {
    final DfSql2EntityMarkAnalyzer analyzer = new DfSql2EntityMarkAnalyzer();
    final BufferedReader reader = new BufferedReader(newInputStreamReader(outsideSqlFile));
    final StringBuilder sb = new StringBuilder();
    try {
        while (true) {
            final String line = reader.readLine();
            if (line == null) {
                break;
            }
            sb.append(line).append(ln());
        }
    } catch (IOException e) {
        String msg = "Failed to read the SQL: " + outsideSqlFile;
        throw new IllegalStateException(msg, e);
    }
    final String sql = sb.toString();
    final String customizeEntity = analyzer.getCustomizeEntityName(sql);
    final String parameterBean = analyzer.getParameterBeanName(sql);
    elementMap.put("customizeEntity", customizeEntity);
    elementMap.put("parameterBean", parameterBean);
    elementMap.put("cursor", analyzer.isCursor(sql) ? "cursor" : null);
    elementMap.put(KEY_TITLE, analyzer.getTitle(sql));
    elementMap.put(KEY_DESCRIPTION, analyzer.getDescription(sql));
    elementMap.put(KEY_SQL, sql);
}
Also used : DfSql2EntityMarkAnalyzer(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 5 with DfSql2EntityMarkAnalyzer

use of org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer in project dbflute-core by dbflute.

the class DfSql2EntityMarkAnalyzerTest method test_getSelectColumnCommentMap_irregular.

public void test_getSelectColumnCommentMap_irregular() {
    // ## Arrange ##
    DfSql2EntityMarkAnalyzer analyzer = new DfSql2EntityMarkAnalyzer();
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT FOO_ID -- //Comment1");
    sb.append(ln()).append(" , foo.BAR_NAME -- abc //Comment2");
    sb.append(ln()).append(" BAZ_DATE -- // Comment3");
    sb.append(ln()).append(" QUX_DATE, -- // Comment4");
    sb.append(ln()).append(" , 0 as QUUX_DATE -- // Comment5");
    sb.append(ln()).append(" max(foo) as CORGE_DATE, -- // Comment6");
    // ## Act ##
    Map<String, String> commentMap = analyzer.getSelectColumnCommentMap(sb.toString());
    // ## Assert ##
    log(commentMap);
    assertEquals("Comment1", commentMap.get("FOO_ID"));
    assertEquals("Comment2", commentMap.get("BAR_NAME"));
    assertEquals("Comment3", commentMap.get("BAZ_DATE"));
    assertEquals("Comment4", commentMap.get("QUX_DATE"));
    assertEquals("Comment5", commentMap.get("QUUX_DATE"));
    assertEquals("Comment6", commentMap.get("CORGE_DATE"));
}
Also used : DfSql2EntityMarkAnalyzer(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer)

Aggregations

DfSql2EntityMarkAnalyzer (org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer)9 DfSql2EntityMark (org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMark)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1