Example usage for javax.xml.registry FindQualifier SORT_BY_NAME_ASC

List of usage examples for javax.xml.registry FindQualifier SORT_BY_NAME_ASC

Introduction

In this page you can find the example usage for javax.xml.registry FindQualifier SORT_BY_NAME_ASC.

Prototype

String SORT_BY_NAME_ASC

To view the source code for javax.xml.registry FindQualifier SORT_BY_NAME_ASC.

Click Source Link

Document

Specifies a hint to queries that they should sort results by Name in ascending alpha-numeric order.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.BusinessQueryManagerImpl.java

/**
 * Adds an "ORDER BY" clause based on specified parameters
 *
 * @param query Query to which to append clause
 * @param findQualifiers UDDI find qualifiers to apply
 * @throws JAXRException if an error occurs
 * @return Possibly-modified query/*from   ww w  .  j a v  a 2 s  . co  m*/
 */
private Query addOrderBy(Query query, Collection<?> findQualifiers) throws JAXRException {
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);

    if (findQualifiers != null && checkOrderBy) {
        boolean caseInsensitiveSort = false;

        if (findQualifiers.contains(CASE_INSENSITIVE_SORT)) {
            caseInsensitiveSort = true;
        }

        int sortByName = SORT_NONE;

        if (findQualifiers.contains(FindQualifier.SORT_BY_NAME_ASC)) {
            sortByName = SORT_ASC;
        } else if (findQualifiers.contains(FindQualifier.SORT_BY_NAME_DESC)) {
            sortByName = SORT_DESC;
        }

        StringBuffer orderBy = new StringBuffer("");

        if (sortByName != SORT_NONE) {
            if (caseInsensitiveSort) {
                orderBy.append(" ORDER BY UPPER('n.value')");
            } else {
                orderBy.append(" ORDER BY n.value");
            }

            if (sortByName == SORT_ASC) {
                orderBy.append(" ASC");
            } else {
                orderBy.append(" DESC");
            }
        }

        int sortByDate = SORT_NONE;

        if (findQualifiers.contains(FindQualifier.SORT_BY_DATE_ASC)) {
            sortByDate = SORT_ASC;
        } else if (findQualifiers.contains(FindQualifier.SORT_BY_DATE_DESC)) {
            sortByDate = SORT_DESC;
        }

        if (sortByDate != SORT_NONE) {
            //TODO: Need to handle sort by date which is harder as it involves getting AuditTrail.
            if (orderBy.length() > 0) {
                //orderBy += ", ";
            }
        }

        qs.append(orderBy);
    }

    return dqm.createQuery(Query.QUERY_TYPE_SQL, qs.toString());
}