Package org.xorm.query

Examples of org.xorm.query.Selector$Ordering


                // Having to explicitly check this here is a bit kludgy
                boolean outerJoin = false;
                if (condition instanceof SimpleCondition) {
                    Object operand = ((SimpleCondition) condition).getValue();
                    if (operand instanceof Selector) {
                        Selector next = (Selector) operand;
                        outerJoin = next.isOuterJoin();
                    }
                }

                if (!outerJoin && (whereClause.length() > 0)) {
                    whereClause.append(" AND ");
View Full Code Here


        Column column = condition.getColumn();
        Object operand = condition.getValue();
        boolean wasOuter = false;
        StringBuffer buffer = whereClause;
        if (operand instanceof Selector) {
            Selector next = (Selector) operand;
            Alias nextAlias = makeAlias(next);
            if (next.isOuterJoin()) {
                if (next.getCondition() instanceof SimpleCondition) {
                    parseSimple(nextAlias, (SimpleCondition) next.getCondition());
                } else {
                    wasOuter = true;
                }
                fromClause.append(" LEFT OUTER JOIN ")
                    .append(nextAlias.getTable().getName())
                    .append(" ")
                    .append(nextAlias.getName())
                    .append(" ON ");
                buffer = fromClause;
            } else {
                buffer.append("(");
            }
            buffer.append(alias.getName())
                .append(".")
                .append(column.getName())
                .append(" = ");

            // In the usual case this should be nextAlias.primaryKey,
            // but in the case of CONTAINS it should be nextAlias.foreignKey.
            buffer.append(nextAlias.getName())
                .append(".")
                .append(nextAlias.getJoinColumn().getName());

            // Because Many-to-Many operations can cause multiple
            // copies, set the distinct flag.
            if (condition.getOperator() == Operator.CONTAINS) {
                distinct = true;
            }

            if (!next.isOuterJoin()) {
                parse(nextAlias, next);
                buffer.append(")");
            }
        } else {
            whereClause.append("(");
View Full Code Here

            // How did we get here?  An exception should have been
            // thrown in ModelMapping.parseRelationship
            throw new JDOFatalUserException(I18N.msg("E_collection_no_source"));
        }
 
        Selector selector = new Selector
            (columnToUse.getTable(),
             new SimpleCondition(columnToUse, Operator.EQUAL, ownerPKey));
       
        if (mapping.getFilter() != null) {
            logger.fine("Filter: " + mapping.getFilter());
            logger.fine("Imports: " + mapping.getImports());
            logger.fine("Parameters: " + mapping.getParameters());
            logger.fine("Variables: " + mapping.getVariables());
            if (mapping.getParameters() != null &&
                !mapping.getParameters().equals("") &&
                (args == null || args.length == 0)) {
                throw new NullPointerException(I18N.msg("E_missing_arguments"));
            }

            //logger.fine("Class Mapping Table: " + classMapping.getTable().getName());
            Class filterTargetClass = classMapping.getMappedClass();
            //logger.fine("Filter Target Class: " + filterTargetClass.getName());
           
            QueryImpl query = new QueryImpl(mgr);
            query.setClass(filterTargetClass);
            query.setFilter(mapping.getFilter());

            // We support the implicit "owner" parameter in filters.
            // The owner refers to the object instance off which the
            // collection field getter is being called.  We need to add
            // it to the parameters that we set on the query.
            String parameters = mapping.getParameters();
            ClassMapping ownerClassMapping = owner.getClassMapping();
            Class ownerClass = ownerClassMapping.getMappedClass();
            String ownerClassName = ownerClass.getName();
            //ownerClassName = ownerClassName.substring(ownerClassName.lastIndexOf('.') + 1);
            //logger.fine("OwnerClassName: " + ownerClassName);

            if (mapping.getImports() != null) {
                query.declareImports(mapping.getImports());
            }
            if (parameters == null || parameters.equals("")) {
                // No parameters, just this owner param
                parameters = ownerClassName + " owner";
            }
            else {
                // Append this owner param to the existing parameters
                parameters += ", " + ownerClassName + " owner";
            }
            logger.fine("Modified Parameters: " + parameters);
            query.declareParameters(parameters);

            if (mapping.getVariables() != null) {
                query.declareVariables(mapping.getVariables());
            }

            if (mapping.getOrdering() != null) {
                query.setOrdering(mapping.getOrdering());
            }

            query.compile();
            //logger.fine("Filter Query: " + query);

            BoundExpression bound = query.getBoundExpression();
            int paramCount = 0;
            if (args != null) {
                while (paramCount < args.length) {
                    bound.bindParameter(paramCount, args[paramCount]);
                    ++paramCount;
                }
            }

            // Always bind the implicit "owner" parameter
            bound.bindParameter(paramCount++, owner.getProxy());

            //logger.fine(paramCount + " parameter(s) bound");

            /*
            logger.info("Main Selector Table Before: " +
                        selector.getTable().getName());
            logger.info("Main Selector Before: " + selector);
            */

            Selector filterSelector = bound.getSelector();

            /*
            logger.info("Filter Selector Table: " +
                        filterSelector.getTable().getName());
            logger.info("Filter Selector: " + filterSelector);
View Full Code Here

                     Object[] args) {
  super(mgr, mapping, owner, classMapping, args);
    }
   
    protected Selector getSelector() {
  Selector selector = super.getSelector();
  if (selector == null) { return null; }

  // Modify the basic selector by ordering by the index
  Selector.Ordering[] ordering = new Selector.Ordering[1];
  ordering[0] = new Selector.Ordering(mapping.getIndexColumn(), Selector.Ordering.ASCENDING);
  selector.setOrdering(ordering);

  // Ensure that the index column gets fetched
  selector.getFetchColumns().add(mapping.getIndexColumn());
  return selector;
    }
View Full Code Here

            // 2. Look in datastore

            // Get the DataFetchGroup to use.
            DataFetchGroup dfg = factory.getFetchGroupManager()
                .getDataFetchGroup(classMapping);
            Selector selector = new Selector
                (table,
                 new SimpleCondition(table.getPrimaryKey(),
                                     Operator.EQUAL,
                                     primaryKey));
            selector.require(dfg);
            Collection rows = selectRows(selector);
            if (!rows.isEmpty()) {
                row = (Row) rows.iterator().next();
            } else {
                throw new JDOObjectNotFoundException();
View Full Code Here

        try {
            if (useNontrans) {
                ((TransactionImpl) currentTransaction()).begin(true);
            }
            Object primaryKey = row.getPrimaryKeyValue();
            Selector selector = new Selector
                (table,
                 new SimpleCondition(table.getPrimaryKey(),
                                     Operator.EQUAL,
                                     primaryKey));
            selector.require(dfg);
            Set extraRows = new HashSet();
            rows = ((TransactionImpl) currentTransaction()).getDriver()
                .select(selector, extraRows);
            if (!rows.isEmpty()) {
                Row newFields = (Row) rows.iterator().next();
View Full Code Here

        // Look in datastore
        Row row = null;

        DataFetchGroup dfg = new DataFetchGroup(table.getColumns());
        Selector selector = new Selector
            (table,
             new SimpleCondition(table.getPrimaryKey(),
                                 Operator.EQUAL,
                                 handler.getObjectId()));
        selector.require(dfg);
        Collection rows = selectRows(selector);
        if (!rows.isEmpty()) {
            row = (Row) rows.iterator().next();
        } else {
            throw new JDODataStoreException(I18N.msg("E_row_deleted"));
View Full Code Here

TOP

Related Classes of org.xorm.query.Selector$Ordering

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.