use of org.apache.cayenne.map.SelectQueryDescriptor in project cayenne by apache.
the class SelectQueryOrderingTab method initFromModel.
protected void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.SELECT_QUERY.equals(query.getType())) {
processInvalidModel("Unknown query.");
return;
}
if (!(query.getRoot() instanceof Entity)) {
processInvalidModel("SelectQuery has no root set.");
return;
}
this.selectQuery = (SelectQueryDescriptor) query;
browser.setModel(createBrowserModel((Entity) selectQuery.getRoot()));
table.setModel(createTableModel());
// init column sizes
table.getColumnModel().getColumn(0).setPreferredWidth(250);
cardLayout.show(this, REAL_PANEL);
}
use of org.apache.cayenne.map.SelectQueryDescriptor in project cayenne by apache.
the class PrefetchTypeForSelectQueryHandlerTest method testLoad.
@Test
public void testLoad() throws Exception {
final DataMap map = new DataMap();
parse("query", new HandlerFactory() {
@Override
public NamespaceAwareNestedTagHandler createHandler(NamespaceAwareNestedTagHandler parent) {
return new QueryDescriptorHandler(parent, map);
}
});
SelectQueryDescriptor selectQueryDescriptor = (SelectQueryDescriptor) map.getQueryDescriptor("query");
assertEquals(3, selectQueryDescriptor.getPrefetchesMap().size());
assertEquals(1, (int) selectQueryDescriptor.getPrefetchesMap().get("paintings"));
assertEquals(2, (int) selectQueryDescriptor.getPrefetchesMap().get("paintings.artist"));
assertEquals(3, (int) selectQueryDescriptor.getPrefetchesMap().get("paintings.gallery"));
}
use of org.apache.cayenne.map.SelectQueryDescriptor in project cayenne by apache.
the class EOModelProcessor method makeEOQueryDescriptor.
protected QueryDescriptor makeEOQueryDescriptor(ObjEntity root, Map plistMap) {
SelectQueryDescriptor descriptor = QueryDescriptor.selectQueryDescriptor();
descriptor.setRoot(root);
descriptor.setDistinct("YES".equalsIgnoreCase((String) plistMap.get("usesDistinct")));
Object fetchLimit = plistMap.get("fetchLimit");
if (fetchLimit != null) {
try {
if (fetchLimit instanceof Number) {
descriptor.setProperty(QueryMetadata.FETCH_LIMIT_PROPERTY, String.valueOf(((Number) fetchLimit).intValue()));
} else if (isNumeric(fetchLimit.toString())) {
descriptor.setProperty(QueryMetadata.FETCH_LIMIT_PROPERTY, fetchLimit.toString());
}
} catch (NumberFormatException nfex) {
// ignoring...
}
}
// sort orderings
List<Map<String, String>> orderings = (List<Map<String, String>>) plistMap.get("sortOrderings");
if (orderings != null && !orderings.isEmpty()) {
for (Map<String, String> ordering : orderings) {
boolean asc = !"compareDescending:".equals(ordering.get("selectorName"));
String key = ordering.get("key");
if (key != null) {
descriptor.addOrdering(new Ordering(key, asc ? SortOrder.ASCENDING : SortOrder.DESCENDING));
}
}
}
// qualifiers
Map<String, ?> qualifierMap = (Map<String, ?>) plistMap.get("qualifier");
if (qualifierMap != null && !qualifierMap.isEmpty()) {
descriptor.setQualifier(EOQuery.EOFetchSpecificationParser.makeQualifier((EOObjEntity) root, qualifierMap));
}
// prefetches
List prefetches = (List) plistMap.get("prefetchingRelationshipKeyPaths");
if (prefetches != null && !prefetches.isEmpty()) {
Iterator it = prefetches.iterator();
while (it.hasNext()) {
descriptor.addPrefetch((String) it.next());
}
}
// modeler...
if (plistMap.containsKey("rawRowKeyPaths")) {
descriptor.setProperty(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY, String.valueOf(true));
}
return descriptor;
}
use of org.apache.cayenne.map.SelectQueryDescriptor 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.SelectQueryDescriptor in project cayenne by apache.
the class SelectQueryMainTab method createQualifier.
/**
* Method to create and check an expression
* @param text String to be converted as Expression
* @return Expression if a new expression was created, null otherwise.
* @throws ValidationException if <code>text</code> can't be converted
*/
Expression createQualifier(String text) throws ValidationException {
SelectQueryDescriptor query = getQuery();
if (query == null) {
return null;
}
ExpressionConvertor convertor = new ExpressionConvertor();
try {
String oldQualifier = convertor.valueAsString(query.getQualifier());
if (!Util.nullSafeEquals(oldQualifier, text)) {
Expression exp = (Expression) convertor.stringAsValue(text);
/*
* Advanced checking. See CAY-888 #1
*/
if (query.getRoot() instanceof Entity) {
checkExpression((Entity) query.getRoot(), exp);
}
return exp;
}
return null;
} catch (IllegalArgumentException ex) {
// unparsable qualifier
throw new ValidationException(ex.getMessage());
}
}
Aggregations