use of org.apache.cayenne.validation.ValidationResult 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.ValidationResult in project cayenne by apache.
the class ValidateAction method performAction.
/**
* Validates project for possible conflicts and incomplete mappings.
*/
public void performAction(ActionEvent e) {
ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
ValidationResult validationResult = projectValidator.validate(getCurrentProject().getRootNode());
// If there were errors or warnings at validation, display them
if (validationResult.getFailures().size() > 0) {
ValidatorDialog.showDialog(Application.getFrame(), validationResult.getFailures());
} else {
ValidatorDialog.showValidationSuccess(Application.getFrame());
}
}
use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.
the class ValidationResultBrowser method startupAction.
public void startupAction(String title, String message, Collection<ValidationResult> failures) {
this.view.setTitle(title);
this.view.getMessageLabel().setText(message);
for (ValidationResult failure : failures) {
if (failure != null) {
this.view.getErrorsDisplay().append(buildValidationText(failure) + " ");
}
}
view.pack();
view.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
view.setModal(true);
makeCloseableOnEscape();
centerView();
view.setVisible(true);
}
use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.
the class CayenneDataObjectValidationIT method testValidateForSaveAttributeTooLong.
@Test
public void testValidateForSaveAttributeTooLong() throws Exception {
Artist artist = context.newObject(Artist.class);
DbEntity entity = context.getEntityResolver().getObjEntity(artist).getDbEntity();
int len = entity.getAttribute("ARTIST_NAME").getMaxLength();
StringBuffer buf = new StringBuffer(len);
for (int i = 0; i < len + 1; i++) {
buf.append("c");
}
artist.setArtistName(buf.toString());
ValidationResult result = new ValidationResult();
artist.validateForSave(result);
assertTrue(result.hasFailures());
assertTrue(result.hasFailures(artist));
List<ValidationFailure> failures = result.getFailures();
assertEquals(1, failures.size());
BeanValidationFailure failure = (BeanValidationFailure) failures.get(0);
assertEquals(Artist.ARTIST_NAME.getName(), failure.getProperty());
// fix the problem and see if it goes away
artist.setArtistName("aa");
result = new ValidationResult();
artist.validateForSave(result);
assertFalse(result.hasFailures());
}
use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.
the class CayenneDataObjectValidationIT method testValidateForSaveMandatoryAttributeMissing.
@Test
public void testValidateForSaveMandatoryAttributeMissing() throws Exception {
Artist artist = context.newObject(Artist.class);
ValidationResult result = new ValidationResult();
artist.validateForSave(result);
assertTrue("Validation of 'artistName' should've failed.", result.hasFailures());
assertTrue(result.hasFailures(artist));
List<ValidationFailure> failures = result.getFailures();
assertEquals(1, failures.size());
BeanValidationFailure failure = (BeanValidationFailure) failures.get(0);
assertEquals(Artist.ARTIST_NAME.getName(), failure.getProperty());
// fix the problem and see if it goes away
artist.setArtistName("aa");
result = new ValidationResult();
artist.validateForSave(result);
assertFalse(result.hasFailures());
}
Aggregations