Search in sources :

Example 16 with QueryDescriptor

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

the class EOModelProcessor method makeQuery.

/**
 * Creates a Cayenne query out of EOFetchSpecification data.
 *
 * @since 1.1
 */
protected QueryDescriptor makeQuery(EOModelHelper helper, EOObjEntity entity, String queryName) {
    DataMap dataMap = helper.getDataMap();
    Map queryPlist = helper.queryPListMap(entity.getName(), queryName);
    if (queryPlist == null) {
        return null;
    }
    QueryDescriptor query;
    if (queryPlist.containsKey("hints")) {
        // just a predefined SQL query
        query = makeEOSQLQueryDescriptor(entity, queryPlist);
    } else {
        query = makeEOQueryDescriptor(entity, queryPlist);
    }
    query.setName(entity.qualifiedQueryName(queryName));
    dataMap.addQueryDescriptor(query);
    return query;
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) Map(java.util.Map) DataMap(org.apache.cayenne.map.DataMap) DataMap(org.apache.cayenne.map.DataMap)

Example 17 with QueryDescriptor

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

the class EOModelProcessorTest method assertLoadedQueries.

protected void assertLoadedQueries(DataMap map) throws Exception {
    // queries
    QueryDescriptor query = map.getQueryDescriptor("ExhibitType_TestQuery");
    assertNotNull(query);
    assertEquals(QueryDescriptor.SELECT_QUERY, query.getType());
    assertTrue(query instanceof SelectQueryDescriptor);
    assertSame(map.getObjEntity("ExhibitType"), query.getRoot());
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor)

Example 18 with QueryDescriptor

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

the class ClassGenerationActionTest method runDataMapTest.

private void runDataMapTest(boolean client) throws Exception {
    QueryDescriptor descriptor = QueryDescriptor.selectQueryDescriptor();
    descriptor.setName("TestQuery");
    DataMap map = new DataMap();
    map.addQueryDescriptor(descriptor);
    map.setName("testmap");
    List<String> generated;
    if (client) {
        map.setDefaultClientPackage("testpackage");
        generated = execute(new ClientDataMapArtifact(map, map.getQueryDescriptors()));
    } else {
        map.setDefaultPackage("testpackage");
        generated = execute(new DataMapArtifact(map, map.getQueryDescriptors()));
    }
    assertEquals(2, generated.size());
    assertTrue(generated.get(0).contains("public static final String TEST_QUERY_QUERYNAME = \"TestQuery\""));
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 19 with QueryDescriptor

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

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

the class ProcedureQueryView method setQueryName.

/**
 * Initializes Query name from string.
 */
void setQueryName(String newName) {
    if (newName != null && newName.trim().length() == 0) {
        newName = null;
    }
    QueryDescriptor query = mediator.getCurrentQuery();
    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(), map);
        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) ProcedureQueryDescriptor(org.apache.cayenne.map.ProcedureQueryDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)37 DataMap (org.apache.cayenne.map.DataMap)16 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)12 ObjEntity (org.apache.cayenne.map.ObjEntity)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)8 DbEntity (org.apache.cayenne.map.DbEntity)7 Embeddable (org.apache.cayenne.map.Embeddable)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureQueryDescriptor (org.apache.cayenne.map.ProcedureQueryDescriptor)6 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)6 Entity (org.apache.cayenne.map.Entity)5 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)4 ValidationException (org.apache.cayenne.validation.ValidationException)4 DbAttribute (org.apache.cayenne.map.DbAttribute)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 ProjectController (org.apache.cayenne.modeler.ProjectController)3