Search in sources :

Example 1 with ValidationException

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
    }
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ValidationException(org.apache.cayenne.validation.ValidationException) Test(org.junit.Test)

Example 2 with ValidationException

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);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) Preferences(java.util.prefs.Preferences) RenamedPreferences(org.apache.cayenne.pref.RenamedPreferences)

Example 3 with ValidationException

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);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with ValidationException

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.");
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 5 with ValidationException

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);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) CardLayout(java.awt.CardLayout) JPanel(javax.swing.JPanel) ValidationException(org.apache.cayenne.validation.ValidationException) TextAdapter(org.apache.cayenne.modeler.util.TextAdapter) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) JTextField(javax.swing.JTextField) ActionManager(org.apache.cayenne.modeler.action.ActionManager) BorderLayout(java.awt.BorderLayout) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Aggregations

ValidationException (org.apache.cayenne.validation.ValidationException)20 FormLayout (com.jgoodies.forms.layout.FormLayout)5 BorderLayout (java.awt.BorderLayout)5 JTextField (javax.swing.JTextField)5 TextAdapter (org.apache.cayenne.modeler.util.TextAdapter)5 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)4 DataMap (org.apache.cayenne.map.DataMap)4 JLabel (javax.swing.JLabel)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)3 Expression (org.apache.cayenne.exp.Expression)3 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)3 EntityEvent (org.apache.cayenne.map.event.EntityEvent)3 ExpressionConvertor (org.apache.cayenne.modeler.util.ExpressionConvertor)3 JCayenneCheckBox (org.apache.cayenne.swing.components.JCayenneCheckBox)3 Test (org.junit.Test)3 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 JToolBar (javax.swing.JToolBar)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2