Prepare order by clause.

@param metadata
the metadata
@return order by clause.
961541
private BasicDBObject getOrderByClause(final EntityMetadata metadata)
    {

        BasicDBObject orderByClause = null;
        Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
        EntityType entityType = metaModel.entity(metadata.getEntityClazz());

        AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(metadata.getEntityClazz());

        List<SortOrdering> orders = kunderaQuery.getOrdering();
        if (orders != null)
        {
            orderByClause = new BasicDBObject();
            if (!managedType.hasLobAttribute())
            {
                for (SortOrdering order : orders)
                {
                    orderByClause.append(getColumnName(metadata, entityType, order.getColumnName()),
                            order.getOrder().equals(SortOrder.ASC) ? 1 : -1);
                }
            }
            else
            {
                for (SortOrdering order : orders)
                {
                    orderByClause.append("metadata." + getColumnName(metadata, entityType, order.getColumnName()),
                            order.getOrder().equals(SortOrder.ASC) ? 1 : -1);
                }
            }
        }

        return orderByClause;
    }
1064994
public JdbcMapperBuilder<T> addMapping(final ResultSetMetaData metaData) throws SQLException {
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            addMapping(metaData.getColumnLabel(i), i, metaData.getColumnType(i));
        }

        return this;
    }
9128
public org.grails.datastore.mapping.query.api.Criteria order(String propertyName) {
        if (criteria == null) {
            throwRuntimeException(new IllegalArgumentException("Call to [order] with propertyName [" +
                    propertyName + "]not allowed here."));
        }
        propertyName = calculatePropertyName(propertyName);
        Order o = Order.asc(propertyName);
        addOrderInternal(this.criteria, o);
        return this;
    }
681715
public static ContextId fromMetaData(Map<String, String> metaData) {
        return new ContextId(metaData.get(META_KEY_ID));
    }
234027
public OrderDirection BY(String attributeName) {
		OrderBy ob = this.orderExpression.getCreateOrderCriteriaFor(attributeName);
		OrderDirection ret = new OrderDirection(ob);
		QueryRecorder.recordInvocation(this, "BY", ret, QueryRecorder.literal(attributeName));
		return ret;
	}
405702
public SqlBuilder orderBy(final List<Order> orders) {
    if (null != orders) {
      this.orders.addAll(orders);
    }
    return this;
  }
932949
@Override
    public void orderRows(final OrderBy ob) {
        if (ob != null) {
            ob.setMetaData(getMetaData());
            ob.setParser(parser);
            Collections.sort(rows, ob);
            goTop();
        }
    }
1328817
public BeanQuery<T> orderBy(String orderByProperty, Comparator propertyValueComparator) {
    this.comparator = new DelegatedSortOrderableComparator(new PropertyComparator(orderByProperty,
        propertyValueComparator));
    return this;
  }
540513
private void processOrderByClause(TermsBuilder termsBuilder, Expression orderByExpression,
            Expression groupByClause, EntityMetadata entityMetadata)
    {
        Expression orderByClause = (OrderByClause) orderByExpression;
        OrderByItem orderByItems = (OrderByItem) ((OrderByClause) orderByClause).getOrderByItems();

        if (orderByClause instanceof CollectionExpression
                || !(orderByItems.getExpression().toParsedText().equalsIgnoreCase(groupByClause.toParsedText())))
        {
            logger.error("Order by and group by on different field are not supported simultaneously");
            throw new UnsupportedOperationException(
                    "Order by and group by on different field are not supported simultaneously");
        }

        String ordering = orderByItems.getOrdering().toString();
        termsBuilder.order(Terms.Order.term(!ordering.equalsIgnoreCase(Expression.DESC)));
    }
1283488
public Map<String, Object> getRawMetadata() {
        Map<String,Object> copy = new TreeMap<String,Object>(String.CASE_INSENSITIVE_ORDER);
        copy.putAll(metadata);
        return Collections.unmodifiableMap(copy);
    }
1063362
public QueryBuilder<T, ID> orderByRaw(String rawSql) {
		addOrderBy(new OrderBy(rawSql, (ArgumentHolder[]) null));
		return this;
	}
1200859
public Application withMetadata(java.util.Map<String, String> metadata) {
        setMetadata(metadata);
        return this;
    }
271743
public org.grails.datastore.mapping.query.api.Criteria order(Order o) {
        final Criteria criteria = this.criteria;
        addOrderInternal(criteria, o);
        return this;
    }
1098076
public AnimaQuery<T> order(String order) {
        if (this.orderBySQL.length() > 0) {
            this.orderBySQL.append(',');
        }
        this.orderBySQL.append(' ').append(order);
        return this;
    }
143800
public static final <T extends Comparable<T>> Ordering<Scored<T>> ByScoreThenByItem(
      Ordering<T> itemOrdering) {
    final Ordering<Scored<T>> byItem = itemOrdering.onResultOf(Scoreds.<T>itemsOnly());
    final Ordering<Scored<T>> byScore = Scoreds.<T>ByScoreOnly();

    return Ordering.compound(ImmutableList.of(byScore, byItem));
  }
548327
public CompletableFuture<MetadataResponse> metadata(MetadataRequest request) {
    CompletableFuture<MetadataResponse> future = new CompletableFuture<>();
    if (context.isCurrentContext()) {
      sendRequest(request, protocol::metadata, future);
    } else {
      context.execute(() -> sendRequest(request, protocol::metadata, future));
    }
    return future;
  }
240605
protected function _prepareOrderByQuery($query = null)
    {
        // sorting
        $sortFields = $this->getListSorting();

        if (is_array($sortFields) && count($sortFields)) {
            // only add order by at full sql not for count(*)
            $query .= ' order by ';
            $addSeparator = false;

            $listItem = $this->getItemListBaseObject();
            $languageId = $listItem->isMultilang() ? $listItem->getLanguage() : \OxidEsales\Eshop\Core\Registry::getLang()->getBaseLanguage();

            $descending = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('adminorder');
            $descending = $descending !== null ? (bool)$descending : $this->_blDesc;

            foreach ($sortFields as $table => $fieldData) {
                $table = $table ? (getViewName($table, $languageId) . '.') : '';
                foreach ($fieldData as $column => $sortDirectory) {
                    $field = $table . $column;

                    //add table name to column name if no table name found attached to column name
                    $query .= ((($addSeparator) ? ', ' : '')) . \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quoteIdentifier($field);

                    //V oxActive field search always DESC
                    if ($descending || $column == "oxactive" || strcasecmp($sortDirectory, 'desc') == 0) {
                        $query .= ' desc ';
                    }

                    $addSeparator = true;
                }
            }
        }

        return $query;
    }