Example usage for javax.xml.registry Query toString

List of usage examples for javax.xml.registry Query toString

Introduction

In this page you can find the example usage for javax.xml.registry Query toString.

Prototype

public String toString();

Source Link

Document

Returns the String representing the query.

Usage

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

/**
 * Adds a predicate restricting query to service associated with specified
 * organization.// w w  w  .j  a v a2  s.co m
 *
 * @param query Existing query
 * @param orgKey Key of associated organization to which to restrict query
 *        result
 * @throws JAXRException if an error occurs
 * @return Updated query
 */
private Query addOrgKeyPredicate(Query query, Key orgKey) throws JAXRException {
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);

    if ((orgKey != null) && !orgKey.getId().equals("")) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append(
                PRIMARY_TABLE_NAME + ".id in (select s.id from service s, association a, organization o where "
                        + "s.id = a.targetobject and a.associationtype = '"
                        + BindingUtility.CANONICAL_ASSOCIATION_TYPE_ID_OffersService
                        + "' and a.sourceobject = '" + orgKey.getId() + "') ");
    } else {
        // No qualifiers are specified
    }

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

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

/**
 * Adds a predicate restricting query to service associated with specified
 * service./*  www .jav a2  s  .co m*/
 *
 * @param query Existing query
 * @param serviceKey Key of associated Service to which to restrict result
 * @throws JAXRException if an error occurs
 * @return Updated query
 */
private Query addServiceKeyPredicate(Query query, Key serviceKey) throws JAXRException {
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);

    if (serviceKey != null) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append("service = '" + serviceKey.getId() + "' ");
    } else {
        // No qualifiers are specified
    }

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

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// w w w . j  a va2s .c  o 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());
}

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

private Query addExternalIdentifiers(Query query, Collection<?> extIds, Collection<?> findQualifiers)
        throws JAXRException {
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);
    String expr = qu.getExternalIdentifiersPredicate((ArrayList<?>) extIds, PRIMARY_TABLE_NAME + ".id",
            findQualifiers);/*from   ww w  .ja v  a  2s .c o m*/

    if (expr != null) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append(expr);
    } else {
        // No qualifiers are specified
    }

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

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

private Query addExternalLinks(Query query, Collection<?> extLinks, Collection<?> findQualifiers)
        throws JAXRException {
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);
    String expr = qu.getExternalLinksPredicate(extLinks, PRIMARY_TABLE_NAME + ".id", findQualifiers);

    if (expr != null) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {//  ww w  .  j av a 2  s. c  om
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append(expr);
    } else {
        // No qualifiers are specified
    }

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

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

private Query addClassifications(Query query, Collection<?> classifications, Collection<?> findQualifiers)
        throws JAXRException {
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);
    String expr = qu.getClassificationsPredicate(classifications, PRIMARY_TABLE_NAME + ".id", findQualifiers);

    if (expr != null) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {/*from ww w. ja v a2  s. com*/
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append(expr);
    } else {
        // No qualifiers are specified
    }

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

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

private Query addSpecifications(Query query, Collection<?> specificationObjects, Collection<?> findQualifiers)
        throws JAXRException {
    // Don't bother changing query if no specifications specified.
    if (specificationObjects == null) {
        return query;
    }/*from w ww.j  a v a 2 s  .c  om*/

    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);
    String expr = qu.getSpecificationLinksPredicate(specificationObjects, PRIMARY_TABLE_NAME + ".id",
            findQualifiers);

    if (expr != null) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append(expr);
    } else {
        // No qualifiers are specified
    }

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

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

private Query addServiceSpecifications(Query query, Collection<?> specificationObjects,
        Collection<?> findQualifiers) throws JAXRException {
    // Don't bother changing query if no specifications specified.
    if (specificationObjects == null) {
        return query;
    }/*from w w w .  j a  v a  2  s  .  c  o  m*/

    // ptn.id in (select sb.service from servicebinding sb where
    String q = query.toString();
    StringBuffer qs = new StringBuffer(q);
    String expr = qu.getSpecificationLinksPredicate(specificationObjects, "sb.id", findQualifiers);

    if (expr != null) {
        if (q.indexOf(WHERE_KEYWORD) != -1) {
            // where clause already created
            qs.append(" AND ");
        } else {
            qs.append(" " + WHERE_KEYWORD + " ");
        }

        qs.append(PRIMARY_TABLE_NAME + ".id IN (SELECT sb.service FROM ServiceBinding sb WHERE ");
        qs.append(expr);
        qs.append(')');
    } else {
        // No qualifiers are specified
    }

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