Search in sources :

Example 1 with DfSPolicyResult

use of org.dbflute.logic.doc.spolicy.result.DfSPolicyResult in project dbflute-core by dbflute.

the class DfSPolicyChecker method checkPolicyIfNeeds.

// ===================================================================================
// Check Policy
// ============
public DfSPolicyResult checkPolicyIfNeeds() {
    // null allowed if no policy
    if (_policyMap.isEmpty()) {
        return null;
    }
    _log.info("");
    _log.info("...Beginning schema policy check");
    // map:{
    // ; tableExceptList = list:{}
    // ; tableTargetList = list:{}
    // ; columnExceptMap = map:{}
    // ; isMainSchemaOnly = false
    // ; wholeMap = map:{
    // ; themeList = list:{ uniqueTableAlias ; sameColumnAliasIfSameColumnName }
    // }
    // ; tableMap = map:{
    // ; themeList = list:{ hasPK ; upperCaseBasis ; identityIfPureIDPK }
    // }
    // ; columnMap = map:{
    // ; themeList = list:{ upperCaseBasis }
    // ; statementList = list:{
    // ; if columnName is suffix:_FLAG then bad
    // ; if columnName is suffix:_FLG then notNull
    // ; if columnName is suffix:_FLG then dbType is INTEGER
    // }
    // }
    // }
    final long before = System.currentTimeMillis();
    final DfSPolicyParsedPolicy policy = parsePolicy();
    final String dispPolicy = showParsedPolicy(policy);
    final DfSPolicyResult result = createPolicyResult(policy);
    result.acceptPolicyMessage(dispPolicy);
    final List<Table> tableList = _database.getTableList();
    doCheckWhole(policy, result, tableList);
    for (Table table : tableList) {
        if (!isTargetTable(table)) {
            continue;
        }
        doCheckTableColumn(policy, result, table);
    }
    final String violationMessage = _logicalSecretary.buildSchemaPolicyCheckViolationMessage(result);
    result.acceptViolationMessage(violationMessage);
    result.acceptEndingHandler(() -> {
        // lazy handling for display of SchemaHTML
        _log.info("...Ending schema policy check: " + result);
        if (result.hasViolation()) {
            _logicalSecretary.throwSchemaPolicyCheckViolationException(violationMessage);
        } else {
            final long after = System.currentTimeMillis();
            // for tuning
            final String performanceView = DfTraceViewUtil.convertToPerformanceView(after - before);
            _log.info(" -> No violation of schema policy. Good DB design! [" + performanceView + "]");
            _log.info("");
        }
    });
    // not ending yet
    return result;
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfSPolicyResult(org.dbflute.logic.doc.spolicy.result.DfSPolicyResult) DfSPolicyParsedPolicy(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyParsedPolicy)

Example 2 with DfSPolicyResult

use of org.dbflute.logic.doc.spolicy.result.DfSPolicyResult in project dbflute-core by dbflute.

the class DfSPolicyInRepsChecker method checkSchemaPolicyInRepsIfNeeds.

// ===================================================================================
// Check
// =====
public boolean checkSchemaPolicyInRepsIfNeeds() {
    // returns check executed or not
    final DfReplaceSchemaProperties repsProp = getReplaceSchemaProperties();
    if (!repsProp.isCheckSchemaPolicyInReps()) {
        return false;
    }
    final DfSchemaPolicyProperties policyProp = getSchemaPolicyProperties();
    if (!policyProp.hasPolicy()) {
        return false;
    }
    _log.info("");
    _log.info("* * * * * * * * * * * *");
    _log.info("*                     *");
    _log.info("*    Schema Policy    *");
    _log.info("*                     *");
    _log.info("* * * * * * * * * * * *");
    final String schemaXml = repsProp.getSchemaPolicyInRepsSchemaXml();
    deleteTemporarySchemaXmlIfExists(schemaXml);
    final DfSchemaXmlSerializer serializer = createSchemaXmlSerializer(schemaXml);
    serializer.serialize();
    try {
        final DfSchemaXmlReader reader = createSchemaXmlReader(schemaXml);
        final AppData appData = reader.read();
        final Database database = appData.getDatabase();
        // for e.g. "then classification"
        initializeSupplementaryMetaData(database);
        final DfSPolicyChecker checker = createChecker(policyProp, database);
        final DfSPolicyResult policyResult = checker.checkPolicyIfNeeds();
        if (policyResult == null) {
            // no way already checked, just in case
            return false;
        }
        // immediately handles violation (may be throw)
        policyResult.ending();
    } finally {
        deleteTemporarySchemaXmlIfExists(schemaXml);
    }
    return true;
}
Also used : DfSPolicyChecker(org.dbflute.logic.doc.spolicy.DfSPolicyChecker) DfReplaceSchemaProperties(org.dbflute.properties.DfReplaceSchemaProperties) AppData(org.apache.torque.engine.database.model.AppData) DfSPolicyResult(org.dbflute.logic.doc.spolicy.result.DfSPolicyResult) Database(org.apache.torque.engine.database.model.Database) DfSchemaXmlSerializer(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlSerializer) DfSchemaPolicyProperties(org.dbflute.properties.DfSchemaPolicyProperties) DfSchemaXmlReader(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)

Aggregations

DfSPolicyResult (org.dbflute.logic.doc.spolicy.result.DfSPolicyResult)2 AppData (org.apache.torque.engine.database.model.AppData)1 Database (org.apache.torque.engine.database.model.Database)1 Table (org.apache.torque.engine.database.model.Table)1 DfSPolicyChecker (org.dbflute.logic.doc.spolicy.DfSPolicyChecker)1 DfSPolicyParsedPolicy (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyParsedPolicy)1 DfSchemaXmlReader (org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)1 DfSchemaXmlSerializer (org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlSerializer)1 DfReplaceSchemaProperties (org.dbflute.properties.DfReplaceSchemaProperties)1 DfSchemaPolicyProperties (org.dbflute.properties.DfSchemaPolicyProperties)1