Search in sources :

Example 1 with SimpleValidationFailure

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

the class DbGenerator method safeExecute.

/**
 * Builds and executes a SQL statement, catching and storing SQL exceptions
 * resulting from invalid SQL. Only non-recoverable exceptions are rethrown.
 *
 * @since 1.1
 */
protected boolean safeExecute(Connection connection, String sql) throws SQLException {
    try (Statement statement = connection.createStatement()) {
        jdbcEventLogger.log(sql);
        statement.execute(sql);
        return true;
    } catch (SQLException ex) {
        if (this.failures == null) {
            this.failures = new ValidationResult();
        }
        failures.addFailure(new SimpleValidationFailure(sql, ex.getMessage()));
        jdbcEventLogger.logQueryError(ex);
        return false;
    }
}
Also used : SQLException(java.sql.SQLException) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) Statement(java.sql.Statement) ValidationResult(org.apache.cayenne.validation.ValidationResult)

Example 2 with SimpleValidationFailure

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

the class GeneratorController method validateEntity.

protected ValidationFailure validateEntity(ObjEntity entity) {
    String name = entity.getName();
    if (entity.isGeneric()) {
        return new SimpleValidationFailure(name, "Generic class");
    }
    ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "className", entity.getClassName());
    if (emptyClass != null) {
        return emptyClass;
    }
    ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(name, "className", entity.getClassName());
    if (badClass != null) {
        return badClass;
    }
    if (entity.getSuperClassName() != null) {
        ValidationFailure badSuperClass = BeanValidationFailure.validateJavaClassName(name, "superClassName", entity.getSuperClassName());
        if (badSuperClass != null) {
            return badSuperClass;
        }
    }
    return null;
}
Also used : SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure)

Example 3 with SimpleValidationFailure

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

the class ConfigurationNodeValidator method addFailure.

public void addFailure(ValidationResult validationResult, Object source, String messageFormat, Object... messageParameters) {
    String message = String.format(messageFormat, messageParameters);
    validationResult.addFailure(new SimpleValidationFailure(source, message));
}
Also used : SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure)

Example 4 with SimpleValidationFailure

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

the class AbstractToDbToken method executeSql.

void executeSql(MergerContext mergerContext, String sql) {
    JdbcEventLogger logger = mergerContext.getDataNode().getJdbcEventLogger();
    logger.log(sql);
    try (Connection conn = mergerContext.getDataNode().getDataSource().getConnection()) {
        try (Statement st = conn.createStatement()) {
            st.execute(sql);
        }
    } catch (SQLException e) {
        mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(sql, e.getMessage()));
        logger.logQueryError(e);
    }
}
Also used : JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) SQLException(java.sql.SQLException) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 5 with SimpleValidationFailure

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

the class CreateTableToDb method execute.

@Override
public void execute(MergerContext mergerContext) {
    try {
        DataNode node = mergerContext.getDataNode();
        DbAdapter adapter = node.getAdapter();
        if (needAutoPkSupport()) {
            adapter.getPkGenerator().createAutoPk(node, Collections.singletonList(getEntity()));
        }
        executeSql(mergerContext, adapter.createTable(getEntity()));
    } catch (Exception e) {
        mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(this, e.getMessage()));
    }
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) DataNode(org.apache.cayenne.access.DataNode)

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