Search in sources :

Example 6 with SimpleValidationFailure

use of org.apache.cayenne.validation.SimpleValidationFailure in project cayenne by apache.

the class DefaultDbImportAction method applyTokens.

private boolean applyTokens(DataMap targetDataMap, Collection<MergerToken> tokens, DbImportConfiguration config) {
    if (tokens.isEmpty()) {
        logger.info("");
        logger.info("Detected changes: No changes to import.");
        return false;
    }
    final Collection<ObjEntity> loadedObjEntities = new LinkedList<>();
    ModelMergeDelegate mergeDelegate = new ProxyModelMergeDelegate(config.createMergeDelegate()) {

        @Override
        public void objEntityAdded(ObjEntity ent) {
            loadedObjEntities.add(ent);
            super.objEntityAdded(ent);
        }
    };
    ObjectNameGenerator nameGenerator = config.createNameGenerator();
    MergerContext mergerContext = MergerContext.builder(targetDataMap).delegate(mergeDelegate).nameGenerator(nameGenerator).usingPrimitives(config.isUsePrimitives()).usingJava7Types(config.isUseJava7Types()).meaningfulPKFilter(config.createMeaningfulPKFilter()).build();
    for (MergerToken token : tokens) {
        try {
            token.execute(mergerContext);
        } catch (Throwable th) {
            String message = "Migration Error. Can't apply changes from token: " + token.getTokenName() + " (" + token.getTokenValue() + ")";
            logger.error(message, th);
            mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(th, message));
        }
    }
    ValidationResult failures = mergerContext.getValidationResult();
    if (failures.hasFailures()) {
        logger.info("Migration Complete.");
        logger.warn("Migration finished. The following problem(s) were encountered and ignored.");
        for (ValidationFailure failure : failures.getFailures()) {
            logger.warn(failure.toString());
        }
    } else {
        logger.info("Migration Complete Successfully.");
    }
    flattenManyToManyRelationships(targetDataMap, loadedObjEntities, nameGenerator);
    relationshipsSanity(targetDataMap);
    return true;
}
Also used : ObjectNameGenerator(org.apache.cayenne.dbsync.naming.ObjectNameGenerator) ModelMergeDelegate(org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate) ProxyModelMergeDelegate(org.apache.cayenne.dbsync.reverse.dbload.ProxyModelMergeDelegate) ValidationResult(org.apache.cayenne.validation.ValidationResult) MergerContext(org.apache.cayenne.dbsync.merge.context.MergerContext) LinkedList(java.util.LinkedList) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) ObjEntity(org.apache.cayenne.map.ObjEntity) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) ProxyModelMergeDelegate(org.apache.cayenne.dbsync.reverse.dbload.ProxyModelMergeDelegate)

Aggregations

SimpleValidationFailure (org.apache.cayenne.validation.SimpleValidationFailure)6 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ValidationFailure (org.apache.cayenne.validation.ValidationFailure)2 ValidationResult (org.apache.cayenne.validation.ValidationResult)2 Connection (java.sql.Connection)1 LinkedList (java.util.LinkedList)1 DataNode (org.apache.cayenne.access.DataNode)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 MergerContext (org.apache.cayenne.dbsync.merge.context.MergerContext)1 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)1 ObjectNameGenerator (org.apache.cayenne.dbsync.naming.ObjectNameGenerator)1 ModelMergeDelegate (org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate)1 ProxyModelMergeDelegate (org.apache.cayenne.dbsync.reverse.dbload.ProxyModelMergeDelegate)1 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 BeanValidationFailure (org.apache.cayenne.validation.BeanValidationFailure)1