use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class CayenneContextValidationIT method testValidate.
@Test
public void testValidate() throws Exception {
ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("G1");
o1.resetValidation(false);
// this one is not validating
ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
o2.setTable1(o1);
context.commitChanges();
assertTrue(o1.isValidatedForInsert());
assertFalse(o1.isValidatedForDelete());
assertFalse(o1.isValidatedForUpdate());
o1.resetValidation(false);
o1.setGlobalAttribute1("G2");
context.commitChanges();
assertFalse(o1.isValidatedForInsert());
assertFalse(o1.isValidatedForDelete());
assertTrue(o1.isValidatedForUpdate());
o1.resetValidation(false);
context.deleteObjects(o1);
context.deleteObjects(o2);
context.commitChanges();
assertFalse(o1.isValidatedForInsert());
assertTrue(o1.isValidatedForDelete());
assertFalse(o1.isValidatedForUpdate());
ClientMtTable1 o11 = context.newObject(ClientMtTable1.class);
o11.setGlobalAttribute1("G1");
o11.resetValidation(true);
try {
context.commitChanges();
fail("Validation failure must have prevented commit");
} catch (ValidationException e) {
// expected
}
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class DataDomainView method setDomainName.
void setDomainName(String newName) {
DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
if (Util.nullSafeEquals(dataChannelDescriptor.getName(), newName)) {
return;
}
if (newName == null || newName.trim().length() == 0) {
throw new ValidationException("Enter name for DataDomain");
}
Preferences prefs = projectController.getPreferenceForDataDomain();
DomainEvent e = new DomainEvent(this, dataChannelDescriptor, dataChannelDescriptor.getName());
dataChannelDescriptor.setName(newName);
RenamedPreferences.copyPreferences(newName, prefs);
projectController.fireDomainEvent(e);
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class DataMapView method setDataMapName.
void setDataMapName(String newName) {
if (newName == null || newName.trim().length() == 0) {
throw new ValidationException("Enter name for DataMap");
}
DataMap map = eventController.getCurrentDataMap();
// search for matching map name across domains, as currently they have to be
// unique globally
DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
DataMap matchingMap = dataChannelDescriptor.getDataMap(newName);
if (matchingMap != null && !matchingMap.equals(map)) {
// there is an entity with the same name
throw new ValidationException("There is another DataMap named '" + newName + "'. Use a different name.");
}
String oldName = map.getName();
if (Util.nullSafeEquals(newName, oldName)) {
return;
}
// completely new name, set new name for domain
DataMapDefaults pref = eventController.getDataMapPreferences("");
DataMapEvent e = new DataMapEvent(this, map, map.getName());
ProjectUtil.setDataMapName((DataChannelDescriptor) eventController.getProject().getRootNode(), map, newName);
pref.copyPreferences(newName);
eventController.fireDataMapEvent(e);
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class EjbqlQueryMainTab method setQueryName.
/**
* Initializes Query name from string.
*/
void setQueryName(String newName) {
if (newName != null && newName.trim().length() == 0) {
newName = null;
}
QueryDescriptor query = getQuery();
if (query == null) {
return;
}
if (Util.nullSafeEquals(newName, query.getName())) {
return;
}
if (newName == null) {
throw new ValidationException("Query name is required.");
}
DataMap map = mediator.getCurrentDataMap();
if (map.getQueryDescriptor(newName) == null) {
// completely new name, set new name for entity
QueryEvent e = new QueryEvent(this, query, query.getName());
ProjectUtil.setQueryName(map, query, newName);
mediator.fireQueryEvent(e);
} else {
// there is a query with the same name
throw new ValidationException("There is another query named '" + newName + "'. Use a different name.");
}
}
use of org.apache.cayenne.validation.ValidationException in project cayenne by apache.
the class DbEntityTab method initView.
private void initView() {
toolBar = new JToolBar();
toolBar.setBorder(BorderFactory.createEmptyBorder());
toolBar.setFloatable(false);
ActionManager actionManager = Application.getInstance().getActionManager();
toolBar.add(actionManager.getAction(CreateAttributeAction.class).buildButton(1));
toolBar.add(actionManager.getAction(CreateRelationshipAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(actionManager.getAction(CreateObjEntityFromDbAction.class).buildButton(1));
toolBar.add(actionManager.getAction(DbEntitySyncAction.class).buildButton(2));
toolBar.add(actionManager.getAction(DbEntityCounterpartAction.class).buildButton(3));
toolBar.addSeparator();
toolBar.add(actionManager.getAction(ShowGraphEntityAction.class).buildButton());
// create widgets
name = new TextAdapter(new JTextField()) {
protected void updateModel(String text) {
setEntityName(text);
}
};
catalogLabel = new JLabel("Catalog:");
catalog = new TextAdapter(new JTextField()) {
protected void updateModel(String text) throws ValidationException {
setCatalog(text);
}
};
schemaLabel = new JLabel("Schema:");
schema = new TextAdapter(new JTextField()) {
protected void updateModel(String text) throws ValidationException {
setSchema(text);
}
};
qualifier = new TextAdapter(new JTextField()) {
protected void updateModel(String qualifier) {
setQualifier(qualifier);
}
};
comment = new TextAdapter(new JTextField()) {
@Override
protected void updateModel(String text) throws ValidationException {
setComment(text);
}
};
pkGeneratorType = new JComboBox<>();
pkGeneratorType.setEditable(false);
pkGeneratorType.setModel(new DefaultComboBoxModel<>(PK_GENERATOR_TYPES));
pkGeneratorDetailLayout = new CardLayout();
pkGeneratorDetail = new JPanel(pkGeneratorDetailLayout);
pkGeneratorDetail.add(new PKDefaultGeneratorPanel(mediator), PK_DEFAULT_GENERATOR);
pkGeneratorDetail.add(new PKDBGeneratorPanel(mediator), PK_DB_GENERATOR);
pkGeneratorDetail.add(new PKCustomSequenceGeneratorPanel(mediator), PK_CUSTOM_SEQUENCE_GENERATOR);
// assemble
FormLayout layout = new FormLayout("right:pref, 3dlu, fill:200dlu", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder();
builder.appendSeparator("DbEntity Configuration");
builder.append("DbEntity Name:", name.getComponent());
builder.append(catalogLabel, catalog.getComponent());
builder.append(schemaLabel, schema.getComponent());
builder.append("Qualifier:", qualifier.getComponent());
builder.append("Comment:", comment.getComponent());
builder.appendSeparator("Primary Key");
builder.append("PK Generation Strategy:", pkGeneratorType);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(builder.getPanel(), BorderLayout.NORTH);
mainPanel.add(pkGeneratorDetail, BorderLayout.CENTER);
setLayout(new BorderLayout());
add(toolBar, BorderLayout.NORTH);
add(mainPanel, BorderLayout.CENTER);
}
Aggregations