Search in sources :

Example 1 with DfCustomizeEntityMarkInvalidException

use of org.dbflute.exception.DfCustomizeEntityMarkInvalidException in project dbflute-core by dbflute.

the class OutsideSqlCheckerTest method test_check_customizeEntity.

public void test_check_customizeEntity() {
    // ## Arrange ##
    DfOutsideSqlChecker ker = new DfOutsideSqlChecker();
    String fn = "test.sql";
    // ## Act ##
    try {
        ker.check(fn, "-- #df;entity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
        // ## Assert ##
        fail();
    } catch (DfCustomizeEntityMarkInvalidException e) {
        // OK
        log(e.getMessage());
    }
    // ## Act ##
    try {
        ker.check(fn, "-- #df:pmb#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
        // ## Assert ##
        fail();
    } catch (DfCustomizeEntityMarkInvalidException e) {
        // OK
        log(e.getMessage());
    }
    // ## Act ##
    try {
        ker.check(fn, "-- #df:emtity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
        // ## Assert ##
        fail();
    } catch (DfCustomizeEntityMarkInvalidException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : DfOutsideSqlChecker(org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker) DfCustomizeEntityMarkInvalidException(org.dbflute.exception.DfCustomizeEntityMarkInvalidException)

Example 2 with DfCustomizeEntityMarkInvalidException

use of org.dbflute.exception.DfCustomizeEntityMarkInvalidException in project dbflute-core by dbflute.

the class DfSql2EntityTask method processDomainHandling.

// -----------------------------------------------------
// Result Handling
// ---------------
protected void processDomainHandling(DfCustomizeEntityInfo entityInfo, Table tbl) {
    final DfPmbMetaData pmbMetaData = entityInfo.getPmbMetaData();
    if (pmbMetaData == null || !pmbMetaData.isTypedReturnEntityPmb()) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("The 'domain' option was not related to a typed parameter-bean.");
        br.addItem("Advice");
        br.addElement("A 'domain' option should be defined with a typed parameter-bean");
        br.addElement("that is typed to things returning an entity.");
        br.addElement("For example:");
        br.addElement("  (x): selectDomainMember.sql");
        br.addElement("  (o): MemberBhv_selectDomainMember.sql");
        br.addElement("  (x):");
        br.addElement("    -- #df:entity#");
        br.addElement("    -- +domain+");
        br.addElement("");
        br.addElement("    select MEMBER_ID, MEMBER_NAME, ... from MEMBER");
        br.addElement("  (o):");
        br.addElement("    -- #df:entity#");
        br.addElement("    -- +domain+");
        br.addElement("");
        br.addElement("    -- !df:pmb!");
        br.addElement("");
        br.addElement("    select MEMBER_ID, MEMBER_NAME, ... from MEMBER");
        br.addItem("SQL File");
        br.addElement(entityInfo.getSqlFile());
        final String msg = br.buildExceptionMessage();
        throw new DfCustomizeEntityMarkInvalidException(msg);
    }
    final String entityClassName = pmbMetaData.getEntityClassName();
    if (Srl.is_Null_or_TrimmedEmpty(entityClassName)) {
        String msg = "The entity class name should not be null: " + entityInfo.getSqlFile();
        // no way
        throw new IllegalStateException(msg);
    }
    final Database database = _schemaData.getDatabase();
    Table domainTable = database.getTable(entityClassName);
    if (domainTable == null) {
        // retry without project-prefix for a class name
        final String projectPrefix = getBasicProperties().getProjectPrefix();
        domainTable = database.getTable(Srl.substringFirstFront(entityClassName, projectPrefix));
    }
    if (domainTable == null) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("The table of the behavior query was not found.");
        br.addItem("Advice");
        br.addElement("A 'domain' option should be defined under behavior query.");
        br.addElement("And behavior query should have an existing table.");
        br.addElement("For example:");
        br.addElement("  (x): MembooBhv_selectDomainMember.sql");
        br.addElement("  (o): MemberBhv_selectDomainMember.sql");
        br.addItem("SQL File");
        br.addElement(entityInfo.getSqlFile());
        final String msg = br.buildExceptionMessage();
        // basically no way
        throw new DfCustomizeEntityMarkInvalidException(msg);
    }
    final List<Column> columnList = tbl.getColumnList();
    for (Column column : columnList) {
        final Column found = domainTable.getColumn(column.getName());
        if (found == null) {
            final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
            br.addNotice("The selected column was not a column of domain table.");
            br.addItem("Advice");
            br.addElement("A selected column with a 'domain' option");
            br.addElement("should be one of domain table.");
            br.addElement("For example:");
            br.addElement("  (x):");
            br.addElement("    select MEMBER_ID, 'noexist' as NO_EXIST from MEMBER");
            br.addElement("  (o):");
            br.addElement("    select MEMBER_ID, MEMBER_NAME from MEMBER");
            br.addElement("  (o):");
            br.addElement("    select member.* from MEMBER member");
            br.addItem("SQL File");
            br.addElement(entityInfo.getSqlFile());
            br.addItem("Unknown Column");
            br.addElement(column.getName());
            br.addItem("Domain Table");
            br.addElement(domainTable.getTableDbName());
            final String msg = br.buildExceptionMessage();
            throw new DfCustomizeEntityMarkInvalidException(msg);
        }
    }
    entityInfo.setEntityClassName(domainTable.getExtendedEntityClassName());
    entityInfo.setEntityClassName(domainTable.getImmutableExtendedEntityClassName());
}
Also used : Table(org.apache.torque.engine.database.model.Table) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) Column(org.apache.torque.engine.database.model.Column) Database(org.apache.torque.engine.database.model.Database) DfPmbMetaData(org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData) DfCustomizeEntityMarkInvalidException(org.dbflute.exception.DfCustomizeEntityMarkInvalidException)

Example 3 with DfCustomizeEntityMarkInvalidException

use of org.dbflute.exception.DfCustomizeEntityMarkInvalidException in project dbflute-core by dbflute.

the class DfOutsideSqlChecker method throwCustomizeEntityMarkInvalidException.

protected void throwCustomizeEntityMarkInvalidException(String line, String fileName, String sql) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("The CustomizeEntity mark was invalid.");
    br.addItem("Advice");
    br.addElement("Please confirm your CustomizeEntity mark.");
    br.addElement("For example:");
    br.addElement("  (x): -- #df;entity#  *NOT semicolun");
    br.addElement("  (x): -- #df:pmb#     *NOT parameter bean");
    br.addElement("  (x): -- #df:emtity#  *NOT emtity ('entity' is right)");
    br.addElement("  (o): -- #df:entity#");
    br.addItem("CustomizeEntity Mark");
    br.addElement(line);
    br.addItem("SQL File");
    br.addElement(fileName);
    br.addItem("Your SQL");
    br.addElement(sql);
    final String msg = br.buildExceptionMessage();
    throw new DfCustomizeEntityMarkInvalidException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfCustomizeEntityMarkInvalidException(org.dbflute.exception.DfCustomizeEntityMarkInvalidException)

Example 4 with DfCustomizeEntityMarkInvalidException

use of org.dbflute.exception.DfCustomizeEntityMarkInvalidException 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)

Aggregations

DfCustomizeEntityMarkInvalidException (org.dbflute.exception.DfCustomizeEntityMarkInvalidException)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 Column (org.apache.torque.engine.database.model.Column)2 DfPmbMetaData (org.dbflute.logic.sql2entity.pmbean.DfPmbMetaData)2 Database (org.apache.torque.engine.database.model.Database)1 Table (org.apache.torque.engine.database.model.Table)1 DfOutsideSqlChecker (org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker)1