Example usage for javax.xml.registry DeclarativeQueryManager createQuery

List of usage examples for javax.xml.registry DeclarativeQueryManager createQuery

Introduction

In this page you can find the example usage for javax.xml.registry DeclarativeQueryManager createQuery.

Prototype

Query createQuery(int queryType, String queryString) throws InvalidRequestException, JAXRException;

Source Link

Document

Creates a Query object given a queryType (for example, QUERY_TYPE_SQL) and a String that represents a query in the syntax appropriate for queryType.

Usage

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

/**
 * Gets child concepts in their original order.
 * This should really be behavior of getChildrenConcepts()
 * method and a separate method should allow ORBER BY 
 * to be specified. Keeping it safe and simple for now.
 * /*from w  w w.j  ava2 s  . com*/
 * Not yet planned for JAXR 2.0.
 *
 * @return the Set of child concepts in the default order. 
 *   Current implementation returns then in order of creation.
 */
@SuppressWarnings("unchecked")
public Collection<Concept> getChildrenConceptsUnordered() throws JAXRException {
    if (!childrenLoaded) {
        DeclarativeQueryManager dqm = lcm.getRegistryService().getDeclarativeQueryManager();
        String qs = "SELECT * FROM ClassificationNode WHERE parent = '" + getKey().getId() + "' ";
        Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs);
        children.addAll(dqm.executeQuery(query).getCollection());
        childrenLoaded = true;
    }

    return children;
}

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

@SuppressWarnings("unchecked")
public Collection<Concept> getChildrenConcepts() throws JAXRException {
    if (!childrenLoaded) {
        DeclarativeQueryManager dqm = lcm.getRegistryService().getDeclarativeQueryManager();
        String qs = "SELECT * FROM ClassificationNode WHERE parent = '" + getKey().getId() + "' ORDER BY CODE";
        Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs);
        children.addAll(dqm.executeQuery(query).getCollection());
        childrenLoaded = true;/*from w w  w .  j  av a  2s  . co m*/
    }

    return children;
}

From source file:it.cnr.icar.eric.client.ui.thin.security.SecurityUtil.java

/**
 *
 * @param principalName/*from w  w  w  .j  a va2  s.  c o  m*/
 * @throws JAXRException
 * @return
 */
public User findUserByPrincipalName(Connection connection, String principalName) throws JAXRException {
    User user = null;
    DeclarativeQueryManager dqm = connection.getRegistryService().getDeclarativeQueryManager();
    String queryString = "SELECT * " + "FROM user_ u, slot s " + "WHERE u.id = s.parent AND s.name_='"
            + CanonicalConstants.CANONICAL_PRINCIPAL_NAME_URI + "' AND value='" + principalName + "'";
    Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryString);
    BulkResponse br = dqm.executeQuery(query);
    Iterator<?> results = br.getCollection().iterator();
    while (results.hasNext()) {
        user = (User) results.next();
        break;
    }
    return user;
}

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

/**
 * Changes the owner of one or more objects.
 * //from   w w  w.  ja v a 2s  .  co  m
 * @param keys
 *            a Collection of keys for the objects to be
 * @param newOwner
 *            a Collection of keys for the objects to be deprecated
 * 
 * @return a BulkResponse containing the Collection of keys for those
 *         objects that had their owner changed successfully and any
 *         JAXRException that was encountered in case of partial commit
 * 
 * @throws JAXRException
 *             if the JAXR provider encounters an internal error
 */
public BulkResponse changeObjectsOwner(Collection<?> keys, AdhocQueryImpl query1, String newOwner)
        throws JAXRException {
    BulkResponseImpl response = null;
    @SuppressWarnings("unused")
    List<ObjectRefType> orl = createObjectRefList(keys);

    try {
        DeclarativeQueryManager dqm = getRegistryService().getDeclarativeQueryManager();

        org.oasis.ebxml.registry.bindings.lcm.RelocateObjectsRequest req = lcmFac
                .createRelocateObjectsRequest();
        ClientRequestContext context = new ClientRequestContext(
                "it.cnr.icar.eric.client.xml.registry.LifeCycleManagerImpl:changeObjectsOwner", req);

        // Create and set query
        String queryStr = "SELECT ro.* from RegistryObject ro WHERE ";

        Iterator<?> iter = keys.iterator();

        while (iter.hasNext()) {
            String roID = ((Key) iter.next()).getId();
            queryStr += "ro.id = '" + roID + "'";
            if (iter.hasNext()) {
                queryStr += " OR ";
            }
        }

        AdhocQueryType ebAdhocQueryType = bu.createAdhocQueryType(queryStr);
        req.setAdhocQuery(ebAdhocQueryType);

        // Set owner at source
        ObjectRefType sourceOwnerRef = rimFac.createObjectRefType();
        sourceOwnerRef.setId(it.cnr.icar.eric.common.Utility.getInstance().createId()); // Just
        // a
        // dummy
        // id
        // for
        // now
        // will
        // do.
        req.setOwnerAtSource(sourceOwnerRef);

        // Set owner at destination
        ObjectRefType newOwnerObj = rimFac.createObjectRefType();
        newOwnerObj.setId(newOwner);
        req.setOwnerAtDestination(newOwnerObj);

        // Get registry
        String registryQueryStr = "SELECT r.* from Registry r ";

        Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, registryQueryStr);

        // make JAXR request
        javax.xml.registry.BulkResponse registryResponse = dqm.executeQuery(query);

        JAXRUtility.checkBulkResponse(registryResponse);

        // TODOD: Following is dangerous assumption as there may be replica
        // Registry instances
        // representing other registries. SHould iterate over all and find
        // the first one
        // where home attribute is undefined.
        RegistryObject registry = (RegistryObject) JAXRUtility.getFirstObject(registryResponse.getCollection());

        ObjectRefType registryRef = rimFac.createObjectRefType();
        registryRef.setId(registry.getKey().getId());
        req.setSourceRegistry(registryRef);
        req.setDestinationRegistry(registryRef);

        JAXRUtility.addCreateSessionSlot(req, regService.getConnection());
        // Submit the request
        RegistryResponseType ebResp = serverLCM.relocateObjects(context);
        response = new BulkResponseImpl(this, ebResp, null);

        // Now setCollection with ids of objects saved
        setKeysOnBulkResponse(context, response);
    } catch (javax.xml.bind.JAXBException e) {
        log.debug(e);
        throw new JAXRException(e);
    }

    return response;
}