Search in sources :

Example 21 with Procedure

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

the class NameBuilderTest method testName_ProcedureContext.

@Test
public void testName_ProcedureContext() {
    Procedure procedure = new Procedure();
    ProcedureParameter p0 = new ProcedureParameter();
    p0.setName(NameBuilder.builder(p0).in(procedure).name());
    assertEquals("UntitledProcedureParameter", p0.getName());
    procedure.addCallParameter(p0);
    ProcedureParameter p1 = new ProcedureParameter();
    p1.setName(NameBuilder.builder(p1).in(procedure).name());
    assertEquals("UntitledProcedureParameter1", p1.getName());
    procedure.addCallParameter(p1);
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) Procedure(org.apache.cayenne.map.Procedure) Test(org.junit.Test)

Example 22 with Procedure

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

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

the class ProcedureQueryValidator method validateRoot.

void validateRoot(ProcedureQueryDescriptor query, ValidationResult validationResult) {
    DataMap map = query.getDataMap();
    Object root = query.getRoot();
    if (root == null && map != null) {
        addFailure(validationResult, query, "ProcedureQuery '%s' has no root", query.getName());
    }
    // procedure query only supports procedure root
    if (root instanceof Procedure) {
        Procedure procedure = (Procedure) root;
        // procedure may have been deleted...
        if (map != null && map.getProcedure(procedure.getName()) != procedure) {
            addFailure(validationResult, query, "ProcedureQuery '%s' has invalid Procedure root: %s", query.getName(), procedure.getName());
        }
        return;
    }
    if (root instanceof String) {
        if (map != null && map.getProcedure(root.toString()) == null) {
            addFailure(validationResult, query, "ProcedureQuery '%s' has invalid Procedure root: %s", query.getName(), root);
        }
    }
}
Also used : Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 24 with Procedure

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

the class ProcedureHandler method addProcedure.

private void addProcedure(Attributes attributes) throws SAXException {
    String name = attributes.getValue("name");
    String returningValue = attributes.getValue("returningValue");
    if (null == name) {
        throw new SAXException("ProcedureHandler::addProcedure() - no procedure name.");
    }
    procedure = new Procedure(name);
    procedure.setReturningValue(returningValue != null && returningValue.equalsIgnoreCase(DataMapHandler.TRUE));
    procedure.setSchema(attributes.getValue("schema"));
    procedure.setCatalog(attributes.getValue("catalog"));
    map.addProcedure(procedure);
}
Also used : Procedure(org.apache.cayenne.map.Procedure) SAXException(org.xml.sax.SAXException)

Example 25 with Procedure

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

the class DbLoadDataStore method addProcedureSafe.

void addProcedureSafe(Procedure procedure) {
    Procedure old = getProcedure(procedure.getName());
    if (old != null) {
        removeProcedure(old.getName());
    }
    addProcedure(procedure);
}
Also used : Procedure(org.apache.cayenne.map.Procedure)

Aggregations

Procedure (org.apache.cayenne.map.Procedure)38 DataMap (org.apache.cayenne.map.DataMap)14 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)8 DbEntity (org.apache.cayenne.map.DbEntity)7 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)7 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)6 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)6 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)5 Embeddable (org.apache.cayenne.map.Embeddable)5 ObjEntity (org.apache.cayenne.map.ObjEntity)5 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)5 Test (org.junit.Test)4 ProjectController (org.apache.cayenne.modeler.ProjectController)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DataRow (org.apache.cayenne.DataRow)2 DataNode (org.apache.cayenne.access.DataNode)2 PatternFilter (org.apache.cayenne.dbsync.reverse.filters.PatternFilter)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2