Search in sources :

Example 1 with SelectQueryDescriptor

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);
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) Entity(org.apache.cayenne.map.Entity)

Example 2 with SelectQueryDescriptor

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"));
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 3 with SelectQueryDescriptor

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;
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) Ordering(org.apache.cayenne.query.Ordering) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with SelectQueryDescriptor

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());
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor)

Example 5 with SelectQueryDescriptor

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());
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ValidationException(org.apache.cayenne.validation.ValidationException) Expression(org.apache.cayenne.exp.Expression) SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) ExpressionConvertor(org.apache.cayenne.modeler.util.ExpressionConvertor)

Aggregations

SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)6 DataMap (org.apache.cayenne.map.DataMap)3 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)3 Entity (org.apache.cayenne.map.Entity)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 Expression (org.apache.cayenne.exp.Expression)1 ExpressionConvertor (org.apache.cayenne.modeler.util.ExpressionConvertor)1 Ordering (org.apache.cayenne.query.Ordering)1 ValidationException (org.apache.cayenne.validation.ValidationException)1 Test (org.junit.Test)1