Example usage for javax.xml.registry DeclarativeQueryManager executeQuery

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

Introduction

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

Prototype

public BulkResponse executeQuery(Query query) throws JAXRException;

Source Link

Document

Executes a query as specified by query parameter.

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 ww.j a va  2  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   ww  w . j a  va  2 s . com*/
    }

    return children;
}

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

/**
 *
 * @param principalName/*www .  j  a v  a2s.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

private void initializeObjectTypesMap() {
    try {//ww  w . jav  a  2 s.  co m
        DeclarativeQueryManager dqm = getRegistryService().getDeclarativeQueryManager();
        //         String queryStr = "SELECT children.* FROM ClassificationNode children, ClassificationNode parent where (parent.path LIKE '/"
        //               + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
        //               + "/RegistryObject%') AND (parent.path NOT LIKE '/"
        //               + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_LID_ObjectType
        //               + "/RegistryObject/ExtrinsicObject/%') AND parent.id = children.parent";
        //         Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr);

        Query query = SQLQueryProvider.initializeObjectTypesMap(dqm);

        BulkResponse resp = dqm.executeQuery(query);

        if ((resp != null) && (!(resp.getStatus() == JAXRResponse.STATUS_SUCCESS))) {
            Collection<?> exceptions = resp.getExceptions();

            if (exceptions != null) {
                Iterator<?> iter = exceptions.iterator();

                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    e.printStackTrace();
                }
            }

            return;
        }

        objectTypesMap = new HashMap<String, Concept>();

        Collection<?> concepts = resp.getCollection();
        Iterator<?> iter = concepts.iterator();

        while (iter.hasNext()) {
            Concept concept = (Concept) iter.next();
            String value = concept.getValue();

            if (value.equals("ClassificationNode")) {
                value = "Concept";
            }

            objectTypesMap.put(value, concept);
        }
    } catch (JAXRException e) {
        e.printStackTrace();
    }
}

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

/**
 * Changes the owner of one or more objects.
 * //from  www  .j av  a 2  s  . c o 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;
}