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;
}
}
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;
}
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));
}
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);
}
}
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()));
}
}
Aggregations