Search in sources :

Example 6 with DfSchemaXmlReader

use of org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader 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)

Example 7 with DfSchemaXmlReader

use of org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader in project dbflute-core by dbflute.

the class DfSchemaDiff method loadNextSchema.

public void loadNextSchema() {
    // }
    if (_previousDb == null) {
        // always exists after loadPreviousSchema() even if first time
        String msg = "You should not call this because of previous not loaded.";
        throw new IllegalStateException(msg);
    }
    final DfSchemaXmlReader reader = _nextReader;
    try {
        _nextDb = reader.read().getDatabase();
    } catch (RuntimeException e) {
        _loadingFailure = true;
        handleReadingException(e, reader);
    }
    _diffDate = DBFluteSystem.currentDate();
    final int nextTableCount = _nextDb.getTableList().size();
    _tableCountDiff = createNextPreviousDiff(nextTableCount, _previousTableCount);
    setupDocumentAuthorOfNextSchema();
}
Also used : DfSchemaXmlReader(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)

Example 8 with DfSchemaXmlReader

use of org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader in project dbflute-core by dbflute.

the class DfSchemaDiff method createAsAlterCheck.

public static DfSchemaDiff createAsAlterCheck(String previousXml, String nextXml) {
    final DfSchemaXmlReader previousReader = DfSchemaXmlReader.createAsFlexibleToManage(previousXml);
    final DfSchemaXmlReader nextReader = DfSchemaXmlReader.createAsFlexibleToManage(nextXml);
    return prepareDiffOption(newReader(previousReader, nextReader));
}
Also used : DfSchemaXmlReader(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)

Example 9 with DfSchemaXmlReader

use of org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader in project dbflute-core by dbflute.

the class DfSchemaDiff method loadPreviousSchema.

// ===================================================================================
// Load Schema
// ===========
public void loadPreviousSchema() {
    // before loading next schema
    final DfSchemaXmlReader reader = _previousReader;
    if (!reader.exists()) {
        _firstTime = true;
        // to make history of the first time @since 1.1.9
        // dummy database (has no object, can return empty)
        _previousDb = new Database();
        // fixedly no table
        _previousTableCount = 0;
        return;
    }
    try {
        _previousDb = reader.read().getDatabase();
    } catch (RuntimeException e) {
        _loadingFailure = true;
        handleReadingException(e, reader);
    }
    _previousTableCount = _previousDb.getTableList().size();
}
Also used : Database(org.apache.torque.engine.database.model.Database) DfSchemaXmlReader(org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)

Aggregations

DfSchemaXmlReader (org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlReader)9 AppData (org.apache.torque.engine.database.model.AppData)3 Database (org.apache.torque.engine.database.model.Database)3 DfSchemaXmlSerializer (org.dbflute.logic.jdbc.schemaxml.DfSchemaXmlSerializer)3 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)1 StringKeyMap (org.dbflute.helper.StringKeyMap)1 DfSPolicyChecker (org.dbflute.logic.doc.spolicy.DfSPolicyChecker)1 DfSPolicyResult (org.dbflute.logic.doc.spolicy.result.DfSPolicyResult)1 DfReplaceSchemaProperties (org.dbflute.properties.DfReplaceSchemaProperties)1 DfSchemaPolicyProperties (org.dbflute.properties.DfSchemaPolicyProperties)1