Package org.apache.cayenne.query

Examples of org.apache.cayenne.query.SelectQuery


            return "UntitledQuery";
        }

        @Override
        protected Object create(String name, Object namingContext) {
            SelectQuery query = new SelectQuery();
            query.setName(name);
            return query;
        }
View Full Code Here


    List<ColumnDescriptor> buildResultColumns() {

        this.defaultAttributesByColumn = new HashMap<ColumnDescriptor, ObjAttribute>();

        List<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
        SelectQuery query = getSelectQuery();

        // for query with custom attributes use a different strategy
        if (query.isFetchingCustomAttributes()) {
            appendCustomColumns(columns, query);
        }
        else {
            appendQueryColumns(columns, query);
        }
View Full Code Here

*/
public class SelectQueryValidator extends TreeNodeValidator {

    @Override
    public void validateObject(ProjectPath treeNodePath, Validator validator) {
        SelectQuery query = (SelectQuery) treeNodePath.getObject();

        validateName(query, treeNodePath, validator);

        // Resolve root to Entity for further validation
        Entity root = validateRoot(query, treeNodePath, validator);

        // validate path-based parts
        if (root != null) {
            validateQualifier(root, query.getQualifier(), treeNodePath, validator);

            for (final Ordering ordering : query.getOrderings()) {
                validateOrdering(
                        root,
                        ordering,
                        treeNodePath,
                        validator);
            }

            if (query.getPrefetchTree() != null) {
                for (final PrefetchTreeNode prefetchTreeNode : query.getPrefetchTree().nonPhantomNodes()) {
                    validatePrefetch(root, prefetchTreeNode.getPath(), treeNodePath, validator);
                }
            }
        }
    }
View Full Code Here

        this.rootEntity = metadata.getObjEntity();

        // create an internal query, it is a partial replica of
        // the original query and will serve as a value holder for
        // various parameters
        this.internalQuery = new SelectQuery(rootEntity);
        this.internalQuery.setFetchingDataRows(metadata.isFetchingDataRows());
        this.internalQuery.setResolvingInherited(metadata.isResolvingInherited());
        this.internalQuery.setPrefetchTree(metadata.getPrefetchTree());

        this.helper = createHelper(metadata);

        boolean resolvesFirstPage = true;

        if (!metadata.isFetchingDataRows() && (query instanceof SelectQuery)) {
            SelectQuery select = (SelectQuery) query;

            // optimize SelectQuery:
            // * just select ID columns - this gives a 5-10x speedup
            // * strip prefetches as they blow the iterated result, and are actually not
            // needed

            SelectQuery clone = select.queryWithParameters(Collections.EMPTY_MAP, true);
            clone.clearPrefetches();

            // I guess this check is redundant, as custom attributes warrant data rows
            if (!select.isFetchingCustomAttributes()) {
                for (DbAttribute attribute : rootEntity.getDbEntity().getPrimaryKeys()) {
                    clone.addCustomDbAttribute(attribute.getName());
                }
            }

            query = clone;
            resolvesFirstPage = false;
View Full Code Here

            boolean fetchesDataRows = internalQuery.isFetchingDataRows();
            List objects = new ArrayList(qualsSize);
            int fetchEnd = Math.min(qualsSize, maxFetchSize);
            int fetchBegin = 0;
            while (fetchBegin < qualsSize) {
                SelectQuery query = new SelectQuery(rootEntity, ExpressionFactory
                        .joinExp(Expression.OR, quals.subList(fetchBegin, fetchEnd)));

                query.setFetchingDataRows(fetchesDataRows);

                if (!query.isFetchingDataRows()) {
                    query.setPrefetchTree(internalQuery.getPrefetchTree());
                }

                objects.addAll(dataContext.performQuery(query));
                fetchBegin = fetchEnd;
                fetchEnd += Math.min(maxFetchSize, qualsSize - fetchEnd);
View Full Code Here

  @SuppressWarnings("unchecked")
  public DatabaseEditor(Class<T> clazz) throws Exception {
    context = DatabaseContext.getContext();
    if(context == null)
      throw new UnloggedException("No database is initialized");
    List<T> dataRows = context.performQuery(new SelectQuery(clazz));
    Collections.sort(dataRows);

    editorType = clazz.getSimpleName();
    jf.setTitle(editorType + " Editor");
    Box box = new Box(BoxLayout.X_AXIS);
View Full Code Here

      bNull = null;
      jp.add(new JLabel(), gbc);
    }

    final HashMap<String, T> theseOptions = new HashMap<String, T>();
    List<T> relTargets = context.performQuery(new SelectQuery(fieldType));
    Collections.sort(relTargets);
    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
    for(T v : relTargets) {
      String s = getDisplayString(v);
      model.addElement(s);
View Full Code Here

   * @return The Account or NULL
   */
  public static Account get(String name) {
    try {
      Expression expression = ExpressionFactory.likeIgnoreCaseExp(Account.NAME_PROPERTY, name);
      SelectQuery query = new SelectQuery(Account.class, expression);
      return (Account)DataObjectUtils.objectForQuery(DatabaseContext.getContext(), query);
    } catch(Exception e) {
      Out.exception(e);
      return null;
    }
View Full Code Here

   * @return A List&lt;Account> of users with at minimum access
   */
  @SuppressWarnings("unchecked")
  public static List<Account> getRanked(int rank) {
    Expression expression = ExpressionFactory.greaterOrEqualExp(Account.RANK_PROPERTY, rank);
    SelectQuery query = new SelectQuery(Account.class, expression);
    return DatabaseContext.getContext().performQuery(query);
  }
View Full Code Here

   * @return A List&lt;Account> of all users with trivia_correct>0, descending
   */
  @SuppressWarnings("unchecked")
  public static List<Account> getTriviaLeaders() {
    Expression expression = ExpressionFactory.greaterExp(Account.TRIVIA_CORRECT_PROPERTY, Integer.valueOf(0));
    SelectQuery query = new SelectQuery(Account.class, expression);
    query.addOrdering(Account.TRIVIA_CORRECT_PROPERTY, false);
    return DatabaseContext.getContext().performQuery(query);
  }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.query.SelectQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.