Search in sources :

Example 6 with DfPmbMetaData

use of org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData in project dbflute-core by dbflute.

the class DfSql2EntityTask method processScalarHandling.

protected void processScalarHandling(DfCustomizeEntityInfo entityInfo, Table tbl) {
    // for check only
    final DfPmbMetaData pmbMetaData = entityInfo.getPmbMetaData();
    if (pmbMetaData == null || !pmbMetaData.isTypedSelectPmb()) {
        // not pinpoint (but enough)
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("The 'scalar' option was not related to a typed parameter-bean.");
        br.addItem("Advice");
        br.addElement("A 'scalar' option should be defined with a typed parameter-bean");
        br.addElement("that is typed to things returning an scalar value.");
        br.addElement("For example:");
        br.addElement("  (x): selectMemberName.sql");
        br.addElement("  (o): MemberBhv_selectMemberName.sql");
        br.addElement("  (x):");
        br.addElement("    -- #df:entity#");
        br.addElement("    -- +scalar+");
        br.addElement("");
        br.addElement("    select MEMBER_NAME from MEMBER");
        br.addElement("  (o):");
        br.addElement("    -- #df:entity#");
        br.addElement("    -- +scalar+");
        br.addElement("");
        br.addElement("    -- !df:pmb!");
        br.addElement("");
        br.addElement("    select MEMBER_NAME from MEMBER");
        br.addItem("SQL File");
        br.addElement(entityInfo.getSqlFile());
        final String msg = br.buildExceptionMessage();
        throw new DfCustomizeEntityMarkInvalidException(msg);
    }
    final List<Column> columnList = tbl.getColumnList();
    if (columnList.size() != 1) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("The 'scalar' option was related to non-only-one-column SQL.");
        br.addItem("Advice");
        br.addElement("A 'scalar' option should be defined on only-one-column SQL.");
        br.addElement("For example:");
        br.addElement("  (x):");
        br.addElement("    -- #df:entity#");
        br.addElement("    -- +scalar+");
        br.addElement("  ");
        br.addElement("    -- !df:pmb!");
        br.addElement("  ");
        br.addElement("    select MEMBER_NAME, BIRTHDATE from MEMBER");
        br.addElement("  (o):");
        br.addElement("    -- #df:entity#");
        br.addElement("    -- +scalar+");
        br.addElement("");
        br.addElement("    -- !df:pmb!");
        br.addElement("");
        br.addElement("    select BIRTHDATE from MEMBER");
        br.addItem("SQL File");
        br.addElement(entityInfo.getSqlFile());
        br.addItem("Selected Column");
        if (!columnList.isEmpty()) {
            for (Column column : columnList) {
                br.addElement(column.getName());
            }
        } else {
            br.addElement("(empty)");
        }
        final String msg = br.buildExceptionMessage();
        throw new DfCustomizeEntityMarkInvalidException(msg);
    }
    final Column column = columnList.get(0);
    entityInfo.setScalarJavaNative(column.getJavaNative());
    entityInfo.setScalarColumnDisp(column.getColumnDefinitionLineDisp());
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) Column(org.apache.torque.engine.database.model.Column) DfPmbMetaData(org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData) DfCustomizeEntityMarkInvalidException(org.dbflute.exception.DfCustomizeEntityMarkInvalidException)

Example 7 with DfPmbMetaData

use of org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData in project dbflute-core by dbflute.

the class DfSql2EntityTask method showParameterBean.

protected void showParameterBean() {
    _log.info("* * * * * * * * *");
    _log.info("* ParameterBean *");
    _log.info("* * * * * * * * *");
    final StringBuilder logSb = new StringBuilder();
    final Map<String, DfPmbMetaData> pmbMetaDataMap = _sql2entityMeta.getPmbMetaDataMap();
    for (Entry<String, DfPmbMetaData> pmbEntry : pmbMetaDataMap.entrySet()) {
        final DfPmbMetaData pmbMetaData = pmbEntry.getValue();
        logSb.append(pmbMetaData.getClassName());
        if (pmbMetaData.hasSuperClassDefinition()) {
            logSb.append(" extends ").append(pmbMetaData.getSuperClassName());
        }
        if (pmbMetaData.isRelatedToProcedure()) {
            logSb.append(" (procedure");
            if (pmbMetaData.isProcedureRefCustomizeEntity()) {
                logSb.append(" with customize-entity");
            }
            logSb.append(")").append(ln());
            final Map<String, DfProcedureColumnMeta> propertyNameColumnInfoMap = pmbMetaData.getPropertyNameColumnInfoMap();
            for (Entry<String, DfProcedureColumnMeta> columnEntry : propertyNameColumnInfoMap.entrySet()) {
                final DfProcedureColumnMeta columnInfo = columnEntry.getValue();
                logSb.append("  ").append(columnInfo.getColumnNameDisp());
                logSb.append(ln());
            }
        } else {
            if (pmbMetaData.isTypedParameterBean()) {
                logSb.append(" ").append(pmbMetaData.buildTypedDisp());
            }
            logSb.append(ln());
            final Map<String, String> propertyNameTypeMap = pmbMetaData.getPropertyNameTypeMap();
            final Map<String, String> propertyOptionMap = pmbMetaData.getPropertyNameOptionMap();
            for (Entry<String, String> propEntry : propertyNameTypeMap.entrySet()) {
                final String propertyName = propEntry.getKey();
                final String propertyType = propEntry.getValue();
                logSb.append("  ").append(propertyType).append(" ").append(propertyName);
                final String optionDef = propertyOptionMap.get(propertyName);
                if (Srl.is_NotNull_and_NotTrimmedEmpty(optionDef)) {
                    logSb.append(":").append(optionDef);
                }
                logSb.append(ln());
            }
        }
        logSb.append(ln());
    }
    if (logSb.length() > 0) {
        _log.info(ln() + logSb.toString().trim());
    }
}
Also used : DfProcedureColumnMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureColumnMeta) DfPmbMetaData(org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData)

Aggregations

DfPmbMetaData (org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData)7 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 Column (org.apache.torque.engine.database.model.Column)2 DfCustomizeEntityMarkInvalidException (org.dbflute.exception.DfCustomizeEntityMarkInvalidException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Database (org.apache.torque.engine.database.model.Database)1 Table (org.apache.torque.engine.database.model.Table)1 DfParameterBeanDuplicateException (org.dbflute.exception.DfParameterBeanDuplicateException)1 DfProcedureColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureColumnMeta)1