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;
}
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());
}
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\""));
}
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);
}
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.");
}
}
Aggregations