Search in sources :

Example 61 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class DataMapValidator method validateNodeLinks.

private void validateNodeLinks(DataMap map, ValidationResult validationResult) {
    DataChannelDescriptor domain = map.getDataChannelDescriptor();
    if (domain == null) {
        return;
    }
    boolean unlinked = true;
    int nodeCount = 0;
    for (DataNodeDescriptor node : domain.getNodeDescriptors()) {
        nodeCount++;
        if (node.getDataMapNames().contains(map.getName())) {
            unlinked = false;
            break;
        }
    }
    if (unlinked && nodeCount > 0) {
        addFailure(validationResult, map, "DataMap is not linked to any DataNodes");
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 62 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class DataNodeValidator method validateName.

void validateName(DataNodeDescriptor node, ValidationResult validationResult) {
    String name = node.getName();
    if (Util.isEmptyString(name)) {
        addFailure(validationResult, node, "Unnamed DataNode");
        return;
    }
    DataChannelDescriptor dataChannelDescriptor = node.getDataChannelDescriptor();
    // check for duplicate names in the parent context
    for (DataNodeDescriptor otherNode : dataChannelDescriptor.getNodeDescriptors()) {
        if (otherNode == node) {
            continue;
        }
        if (name.equals(otherNode.getName())) {
            addFailure(validationResult, node, "Duplicate DataNode name: %s", name);
            break;
        }
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 63 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class EmbeddableValidator method validate.

void validate(Embeddable embeddable, ValidationResult validationResult) {
    String name = embeddable.getClassName();
    // Must have name
    if (Util.isEmptyString(name)) {
        addFailure(validationResult, embeddable, "Unnamed Embeddable");
        return;
    }
    DataMap map = embeddable.getDataMap();
    if (map == null) {
        return;
    }
    // check for duplicate names in the parent context
    for (Embeddable otherEmb : map.getEmbeddables()) {
        if (otherEmb == embeddable) {
            continue;
        }
        if (name.equals(otherEmb.getClassName())) {
            addFailure(validationResult, embeddable, "Duplicate Embeddable class name: %s", name);
            break;
        }
    }
    // check for duplicates in other DataMaps
    DataChannelDescriptor domain = map.getDataChannelDescriptor();
    if (domain != null) {
        for (DataMap nextMap : domain.getDataMaps()) {
            if (nextMap == map) {
                continue;
            }
            // note that lookuo below will return the same embeddable due to the
            // shared namespace if not conflicts exist
            Embeddable conflictingEmbeddable = nextMap.getEmbeddable(name);
            if (conflictingEmbeddable != null && conflictingEmbeddable != embeddable) {
                addFailure(validationResult, embeddable, "Duplicate Embeddable name in another DataMap: %s", name);
                break;
            }
        }
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Example 64 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class ObjEntityValidator method validateName.

void validateName(ObjEntity entity, ValidationResult validationResult) {
    String name = entity.getName();
    // Must have name
    if (Util.isEmptyString(name)) {
        addFailure(validationResult, entity, "Unnamed ObjEntity");
        return;
    }
    DataMap map = entity.getDataMap();
    if (map == null) {
        return;
    }
    // check for duplicate names in the parent context
    for (ObjEntity otherEnt : map.getObjEntities()) {
        if (otherEnt == entity) {
            continue;
        }
        if (name.equals(otherEnt.getName())) {
            addFailure(validationResult, entity, "Duplicate ObjEntity name: '%s'", name);
            break;
        }
    }
    // check for duplicates in other DataMaps
    DataChannelDescriptor domain = entity.getDataMap().getDataChannelDescriptor();
    if (domain != null) {
        for (DataMap nextMap : domain.getDataMaps()) {
            if (nextMap == map) {
                continue;
            }
            ObjEntity conflictingEntity = nextMap.getObjEntity(name);
            if (conflictingEntity != null) {
                if (!Util.nullSafeEquals(conflictingEntity.getClassName(), entity.getClassName())) {
                    addFailure(validationResult, entity, "Duplicate ObjEntity name in another DataMap: '%s'", name);
                    break;
                }
            }
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 65 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class FileProjectSaverTest method testSaveAs_Sorted.

@Test
public void testSaveAs_Sorted() throws Exception {
    File testFolder = setupTestDirectory("testSaveAs_Sorted");
    DataChannelDescriptor rootNode = new DataChannelDescriptor();
    rootNode.setName("test");
    // add maps and nodes in reverse alpha order. Check that they are saved in alpha
    // order
    rootNode.getDataMaps().add(new DataMap("C"));
    rootNode.getDataMaps().add(new DataMap("B"));
    rootNode.getDataMaps().add(new DataMap("A"));
    DataNodeDescriptor[] nodes = new DataNodeDescriptor[3];
    nodes[0] = new DataNodeDescriptor("Z");
    nodes[1] = new DataNodeDescriptor("Y");
    nodes[2] = new DataNodeDescriptor("X");
    nodes[0].getDataMapNames().add("C");
    nodes[0].getDataMapNames().add("B");
    nodes[0].getDataMapNames().add("A");
    rootNode.getNodeDescriptors().addAll(Arrays.asList(nodes));
    Project project = new Project(new ConfigurationTree<DataChannelDescriptor>(rootNode));
    saver.saveAs(project, new URLResource(testFolder.toURI().toURL()));
    File target = new File(testFolder, "cayenne-test.xml");
    assertTrue(target.isFile());
    assertSaveAs_Sorted(target);
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) File(java.io.File) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)100 DataMap (org.apache.cayenne.map.DataMap)50 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)28 Test (org.junit.Test)20 ObjEntity (org.apache.cayenne.map.ObjEntity)18 DbEntity (org.apache.cayenne.map.DbEntity)12 ProjectController (org.apache.cayenne.modeler.ProjectController)12 URL (java.net.URL)11 Embeddable (org.apache.cayenne.map.Embeddable)11 ArrayList (java.util.ArrayList)10 URLResource (org.apache.cayenne.resource.URLResource)10 ObjAttribute (org.apache.cayenne.map.ObjAttribute)8 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)8 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)6 Injector (org.apache.cayenne.di.Injector)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)6 Resource (org.apache.cayenne.resource.Resource)6