Search in sources :

Example 11 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class NameBuilderTest method testName_DataMapContext.

@Test
public void testName_DataMapContext() {
    DataMap map = new DataMap();
    map.setDefaultPackage("com.foo");
    DbEntity de0 = new DbEntity();
    de0.setName(NameBuilder.builder(de0).in(map).name());
    assertEquals("db_entity", de0.getName());
    map.addDbEntity(de0);
    DbEntity de1 = new DbEntity();
    de1.setName(NameBuilder.builder(de1).in(map).name());
    assertEquals("db_entity1", de1.getName());
    map.addDbEntity(de1);
    ObjEntity oe0 = new ObjEntity();
    oe0.setName(NameBuilder.builder(oe0).in(map).name());
    assertEquals("ObjEntity", oe0.getName());
    map.addObjEntity(oe0);
    ObjEntity oe1 = new ObjEntity();
    oe1.setName(NameBuilder.builder(oe1).in(map).name());
    assertEquals("ObjEntity1", oe1.getName());
    map.addObjEntity(oe1);
    ObjEntity oe2 = new ObjEntity();
    oe2.setName(NameBuilder.builder(oe0).in(map).baseName("db_entity").name());
    assertEquals("Should not conflict with similarly named DbEntity", "Db_entity", oe2.getName());
    map.addObjEntity(oe2);
    Procedure p0 = new Procedure();
    p0.setName(NameBuilder.builder(p0).in(map).name());
    assertEquals("procedure", p0.getName());
    map.addProcedure(p0);
    Procedure p1 = new Procedure();
    p1.setName(NameBuilder.builder(p1).in(map).name());
    assertEquals("procedure1", p1.getName());
    map.addProcedure(p1);
    Procedure p2 = new Procedure();
    p2.setName(NameBuilder.builder(p1).in(map).baseName("db_enity").name());
    assertEquals("Should not conflict with similarly named DbEntity", "db_enity", p2.getName());
    map.addProcedure(p2);
    QueryDescriptor q0 = QueryDescriptor.selectQueryDescriptor();
    q0.setName(NameBuilder.builder(q0).in(map).name());
    assertEquals("query", q0.getName());
    map.addQueryDescriptor(q0);
    QueryDescriptor q1 = QueryDescriptor.ejbqlQueryDescriptor();
    q1.setName(NameBuilder.builder(q1).in(map).name());
    assertEquals("query1", q1.getName());
    map.addQueryDescriptor(q1);
    Embeddable e0 = new Embeddable();
    e0.setClassName("com.foo." + NameBuilder.builder(e0).in(map).name());
    assertEquals("com.foo.Embeddable", e0.getClassName());
    map.addEmbeddable(e0);
    Embeddable e1 = new Embeddable();
    e1.setClassName("com.foo." + NameBuilder.builder(e1).in(map).name());
    assertEquals("com.foo.Embeddable1", e1.getClassName());
    map.addEmbeddable(e1);
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) Test(org.junit.Test)

Example 12 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class NameBuilderTest method testName_EmbeddableContext.

@Test
public void testName_EmbeddableContext() {
    Embeddable embeddable = new Embeddable();
    EmbeddableAttribute ea0 = new EmbeddableAttribute();
    ea0.setName(NameBuilder.builder(ea0).in(embeddable).name());
    assertEquals("untitledAttr", ea0.getName());
    embeddable.addAttribute(ea0);
    EmbeddableAttribute ea1 = new EmbeddableAttribute();
    ea1.setName(NameBuilder.builder(ea1).in(embeddable).name());
    assertEquals("untitledAttr1", ea1.getName());
    embeddable.addAttribute(ea1);
}
Also used : EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable) Test(org.junit.Test)

Example 13 with Embeddable

use of org.apache.cayenne.map.Embeddable 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 14 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class ObjAttributeValidator method validateEmbeddable.

private void validateEmbeddable(EmbeddedAttribute attribute, ValidationResult validationResult) {
    Embeddable embeddable = attribute.getEmbeddable();
    if (embeddable == null) {
        String msg = attribute.getType() == null ? "EmbeddedAttribute '%s' has no Embeddable" : "EmbeddedAttribute '%s' has incorrect Embeddable";
        addFailure(validationResult, attribute, msg, attribute.getName());
        return;
    }
    Map<String, String> attrOverrides = attribute.getAttributeOverrides();
    for (EmbeddableAttribute embeddableAttribute : embeddable.getAttributes()) {
        String dbAttributeName;
        if (!attrOverrides.isEmpty() && attrOverrides.containsKey(embeddableAttribute.getName())) {
            dbAttributeName = attrOverrides.get(embeddableAttribute.getName());
        } else {
            dbAttributeName = embeddableAttribute.getDbAttributeName();
        }
        if (Util.isEmptyString(dbAttributeName)) {
            addFailure(validationResult, attribute, "EmbeddedAttribute '%s' has no DbAttribute mapping", attribute.getName());
        } else if (attribute.getEntity().getDbEntity().getAttribute(dbAttributeName) == null) {
            addFailure(validationResult, attribute, "EmbeddedAttribute '%s' has incorrect DbAttribute mapping", attribute.getName());
        }
    }
}
Also used : EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable)

Example 15 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class EmbeddableHandler method createEmbeddable.

private void createEmbeddable(Attributes attributes) {
    embeddable = new Embeddable(attributes.getValue("className"));
    map.addEmbeddable(embeddable);
}
Also used : Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

Embeddable (org.apache.cayenne.map.Embeddable)33 DataMap (org.apache.cayenne.map.DataMap)14 ObjEntity (org.apache.cayenne.map.ObjEntity)14 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)11 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)11 DbEntity (org.apache.cayenne.map.DbEntity)8 ArrayList (java.util.ArrayList)7 ObjAttribute (org.apache.cayenne.map.ObjAttribute)7 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)6 DbAttribute (org.apache.cayenne.map.DbAttribute)5 Procedure (org.apache.cayenne.map.Procedure)5 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 ProjectController (org.apache.cayenne.modeler.ProjectController)4 HashMap (java.util.HashMap)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)3 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)3 File (java.io.File)2 LinkedList (java.util.LinkedList)2