Example usage for javax.xml.registry Query QUERY_TYPE_SQL

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

Introduction

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

Prototype

int QUERY_TYPE_SQL

To view the source code for javax.xml.registry Query QUERY_TYPE_SQL.

Click Source Link

Document

An SQL query type.

Usage

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

/**
 * Creates a Query object given a queryType (e.g. SQL)
 * that represents a query in the syntax appropriate for queryType.
 * No query string is passed to this method.  So, user must call
 * DeclarativeQueryManager.executeQuery(query, queryParams)
 * Must throw an InvalidRequestException if the sqlQuery is not valid.
 *
 *
 * <p><DL><DT><B>Capability Level: 0 (optional) </B></DL>
 *
 * @see Query#QUERY_TYPE_SQL/* w  ww  .jav  a  2s.com*/
 * @see Query#QUERY_TYPE_XQUERY
 * @see DeclarativeQueryManager#executeQuery(Query query, Map queryParams)
 */
public Query createQuery(int queryType) throws InvalidRequestException, JAXRException {
    if (queryType != Query.QUERY_TYPE_SQL) {
        throw new InvalidRequestException("Type must be Query.QUERY_TYPE_SQL");
    }

    return new QueryImpl(queryType);
}

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

/**
 * Creates a Query object given a queryType (e.g. SQL) and a String
 * that represents a query in the syntax appropriate for queryType.
 * Must throw and InvalidRequestException if the sqlQuery is not valid.
 *
 *
 * <p><DL><DT><B>Capability Level: 0 (optional) </B></DL>
 *
 * @see Query#QUERY_TYPE_SQL/*from  www .ja v a 2 s .  com*/
 * @see Query#QUERY_TYPE_XQUERY
 */
public Query createQuery(int queryType, String queryString) throws InvalidRequestException, JAXRException {
    if ((queryType != Query.QUERY_TYPE_SQL) && (queryType != Query.QUERY_TYPE_EBXML_FILTER_QUERY)) {
        throw new InvalidRequestException("Type must be Query.QUERY_TYPE_SQL or QUERY_TYPE_EBXML_FILTER_QUERY");
    }

    // TODO: check queryString syntax
    return new QueryImpl(queryType, queryString);
}

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

/**
 * This method is used to export a collection of selected objects from
 * the search results table./*from  w w w.  j a  v  a 2  s.c o  m*/
 * 
 * @return java.lang.String
 * Return status string: used by JSF for page navigation
 */
@SuppressWarnings("unchecked")
public String doExport() {
    String status = "failure";
    // Reset the zipFileName class member variable
    zipFileName = null;
    try {
        // Execute a compressed content filter query to get a zip file of content
        ArrayList<String> filterQueryIds = new ArrayList<String>();
        filterQueryIds.add(BindingUtility.FREEBXML_REGISTRY_FILTER_QUERY_COMPRESSCONTENT);
        queryParams.put("$queryFilterIds", filterQueryIds);
        queryParams.put(CanonicalConstants.CANONICAL_SEARCH_DEPTH_PARAMETER,
                SearchPanelBean.getInstance().getSearchDepth());
        Iterator<RegistryObjectBean> beanItr = getAllSelectedRegistryObjectBeans().iterator();
        List<String> ids = new ArrayList<String>();
        while (beanItr.hasNext()) {
            RegistryObjectBean rob = beanItr.next();
            if (rob.getObjectType().equalsIgnoreCase("ExtrinsicObject")) {
                ids.add(rob.getId());
            }
        }
        // Execute an arbitrary query with selected ids
        String queryId = CanonicalConstants.CANONICAL_QUERY_ArbitraryQuery;
        String sqlString = getExportSQLString(ids);
        queryParams.put(CanonicalConstants.CANONICAL_SLOT_QUERY_ID, queryId);
        queryParams.put("$query", sqlString);
        Query query = RegistryBrowser.getDQM().createQuery(Query.QUERY_TYPE_SQL);
        BulkResponse bResponse = RegistryBrowser.getDQM().executeQuery(query, queryParams);
        Collection<?> registryObjects = bResponse.getCollection();
        // There should just be one EO containing the zip file
        Iterator<?> roItr = registryObjects.iterator();
        if (roItr.hasNext()) {
            Object obj = roItr.next();
            if (obj instanceof ExtrinsicObjectImpl) {
                ExtrinsicObjectImpl eo = (ExtrinsicObjectImpl) obj;
                // Get the zip filename and set it to this.zipFileName
                Slot filenameSlot = eo
                        .getSlot(BindingUtility.FREEBXML_REGISTRY_FILTER_QUERY_COMPRESSCONTENT_FILENAME);
                if (filenameSlot != null) {
                    Iterator<?> filenameItr = filenameSlot.getValues().iterator();
                    if (filenameItr.hasNext()) {
                        zipFileName = (String) filenameItr.next();
                    }
                }
                status = "success";
            } else {
                String msg = WebUIResourceBundle.getInstance().getString("message.ExpectedExtrinsicObject",
                        new Object[] { obj });
                RegistryObjectCollectionBean.getInstance().append(msg);
                status = "showExportPage";
            }
        } else {
            String msg = WebUIResourceBundle.getInstance().getString("message.extrinsicObjectWithNoRI");
            RegistryObjectCollectionBean.getInstance().append(msg);
            status = "showExportPage";
        }
    } catch (Throwable t) {
        OutputExceptions.error(log, t);
    } finally {
        try {
            queryParams.clear();
        } catch (Throwable t) {
            OutputExceptions.warn(log, t);
        }
    }
    return status;
}

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;//www  .j  a  va2 s  .co m
    }

    return children;
}

From source file:it.cnr.icar.eric.client.ui.swing.JAXRClient.java

/**
 * Find classification schemes/*from   ww  w.  ja v  a 2 s. c  o  m*/
 *
 * @return DOCUMENT ME!
 */
@SuppressWarnings({ "static-access", "rawtypes" })
Collection<?> getClassificationSchemes() {
    Collection<?> schemes = null;

    String errMsg = "Error getting ClassificationSchemes";

    try {
        Map<String, String> queryParams = new HashMap<String, String>();
        queryParams.put(BindingUtility.getInstance().CANONICAL_SLOT_QUERY_ID,
                BindingUtility.getInstance().CANONICAL_QUERY_GetClassificationSchemesById);
        Query query = getDeclarativeQueryManager().createQuery(Query.QUERY_TYPE_SQL);
        BulkResponse response = getDeclarativeQueryManager().executeQuery(query, queryParams);
        checkBulkResponse(response);
        schemes = response.getCollection();
    } catch (JAXRException e) {
        RegistryBrowser.displayError(errMsg, e);
        schemes = new ArrayList();
    }

    return schemes;
}

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.
 * /* w  w w. j ava  2s.  c  o  m*/
 * 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.ui.thin.security.SecurityUtil.java

/**
 *
 * @param principalName/*w  w w. j a va  2  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.ui.thin.SearchPanelBean.java

public String doSearch() {
    String status = "unknown";
    RegistryBrowser.getInstance().setSessionExpired(false);
    try {/*  w  w  w .j  a  va2s .  c  o  m*/
        Map<String, String> parameters = getQueryComponent().getCurrentQuery().getQueryParameters();
        Query query = RegistryBrowser.getDQM().createQuery(Query.QUERY_TYPE_SQL);
        ((QueryImpl) query).setFederated(federatedQuery);
        int maxResults = RegistryObjectCollectionBean.getInstance().getScrollerBean()
                .getNumberOfSearchResults();
        BulkResponse br = null;
        if (!RegistryBrowser.getInstance().isExploreRendered()) {
            getExplorerGraphBean().loadRegistryObjects(RegistryObjectCollectionBean.getInstance().getNode());
        } else if (useIterQueries) {
            // The max results returned is the number of rows in the RegistryObjects
            // table times the number of pages that are displayed. Currently, 10
            // pages are displayed.  If the user scrolls past the tenth page, a new
            // iterative query is executed
            maxResults = maxResults * 10;
            IterativeQueryParams iqParams = new IterativeQueryParams(0, maxResults);
            br = executeQuery(query, parameters, iqParams);
            RegistryObjectCollectionBean.getInstance().handleRegistryObjects(br);
        } else {
            br = executeQuery(query, parameters);
            RegistryObjectCollectionBean.getInstance().handleRegistryObjects(br);
        }
        if (isCompressContent) {
            status = "compressContent";
        } else {
            status = "searchSuccessful";
        }
    } catch (JAXRException jaxre) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                WebUIResourceBundle.getInstance().getString("message.AnExceptionOccurredDuringTheSearch"),
                null));
        status = "searchFailed";
        String msg = WebUIResourceBundle.getInstance().getString("registrySupport");
        OutputExceptions.error(log, msg, jaxre);
    } catch (Throwable t) {
        log.error(WebUIResourceBundle.getInstance().getString("message.AnExceptionOccurredDuringTheSearch"), t);
        status = "searchFailed";
        t.printStackTrace();

        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                WebUIResourceBundle.getInstance().getString("message.AnExceptionOccurredDuringTheSearch"),
                null));
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                WebUIResourceBundle.getInstance().getString("checkLogForDetails"), null));
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "< " + t + " >", null));
    }
    return status;
}

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

public BulkResponse findCallerAssociations(@SuppressWarnings("rawtypes") Collection findQualifiers,
        Boolean confirmedByCaller, Boolean confirmedByOtherParty,
        @SuppressWarnings("rawtypes") Collection associationTypes) throws JAXRException {
    // TODO: implement findQualifiers support later
    if ((confirmedByCaller == null) && (confirmedByOtherParty == null) && (associationTypes == null)) {
        return new BulkResponseImpl();
    }/*from   w  w w . ja v a  2  s .c om*/

    // TODO: xxx pa 111228 findConceptByPath() dependency

    //Find all Associations owned by caller's user ($currentUser is resolved by registry automatically)
    String qs = "SELECT DISTINCT a.* FROM Association a, AuditableEvent e, AffectedObject o, Slot s1, Slot s2 WHERE "
            + "e.user_ = $currentUser AND ( e.eventType = '" + BindingUtility.CANONICAL_EVENT_TYPE_ID_Created
            + "' OR e.eventType = '" + BindingUtility.CANONICAL_EVENT_TYPE_ID_Versioned + "' OR e.eventType = '"
            + BindingUtility.CANONICAL_EVENT_TYPE_ID_Relocated
            + "') AND o.eventId = e.id AND (o.id = a.sourceObject OR o.id = a.targetObject)";

    if (associationTypes != null) {
        //Add predicate for associationType filter
        Iterator<?> iter = associationTypes.iterator();

        while (iter.hasNext()) {
            Object obj = iter.next();

            String assocTypeId = null;

            if (obj instanceof Concept) {
                assocTypeId = ((Concept) obj).getKey().getId();
            } else if (obj instanceof String) {
                String str = (String) obj;

                if (str.startsWith("urn:uuid")) {
                    //str is already the assocTypeId
                    assocTypeId = str;
                } else {
                    //Assume str is the code
                    Concept c = findConceptByPath("/"
                            + BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_ID_AssociationType + "%/" + str);
                    assocTypeId = (c).getKey().getId();
                }
            }

            if (assocTypeId != null) {
                qs += (" AND a.associationType = '" + assocTypeId + "'");
            }
        }
    }

    //Do further filtering based upon confirmedByCaller and confirmedByOtherParty if needed.
    if (confirmedByCaller != null) {
        if (confirmedByCaller.booleanValue()) {
            //ass is confirmed by caller
            qs += (" AND (s1.parent = a.id AND s1.sequenceId = 1 AND ((s1.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_SRC_OWNER
                    + "' AND s1.value = $currentUser)" + " OR (s1.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_TARGET_OWNER
                    + "' AND s1.value = $currentUser)))");
        } else {
            //ass is NOT confirmed by caller
            qs += (" AND NOT (s1.parent = a.id AND s1.sequenceId = 1 AND ((s1.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_SRC_OWNER
                    + "' AND s1.value = $currentUser)" + " OR (s1.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_TARGET_OWNER
                    + "' AND s1.value = $currentUser)))");
        }
    }

    if (confirmedByOtherParty != null) {
        if (confirmedByOtherParty.booleanValue()) {
            //ass is confirmed by other party
            qs += (" AND (s2.parent = a.id AND s2.sequenceId = 1 AND ((s2.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_SRC_OWNER
                    + "' AND s2.value != $currentUser)" + " OR (s2.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_TARGET_OWNER
                    + "' AND s2.value != $currentUser)))");
        } else {
            //ass is NOT confirmed by other party
            qs += (" AND NOT (s2.parent = a.id AND s2.sequenceId = 1 AND ((s2.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_SRC_OWNER
                    + "' AND s2.value != $currentUser)" + " OR (s2.name_ = '"
                    + BindingUtility.IMPL_SLOT_ASSOCIATION_IS_CONFIRMED_BY_TARGET_OWNER
                    + "' AND s2.value != $currentUser)))");
        }
    }

    Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs);
    BulkResponse br = dqm.executeQuery(query);

    return br;
}

From source file:it.cnr.icar.eric.client.ui.thin.jsf.ClassSchemeGraphBean.java

@SuppressWarnings({ "static-access", "unchecked" })
public Collection<?> getClassSchemes() {
    Collection<?> classSchemes = null;
    try {//from   w  w w .  j ava2  s. c o  m
        HashMap<String, String> queryParams = new HashMap<String, String>();
        queryParams.put(BindingUtility.getInstance().CANONICAL_SLOT_QUERY_ID,
                BindingUtility.getInstance().CANONICAL_QUERY_GetClassificationSchemesById);
        Query query = ((DeclarativeQueryManagerImpl) dqm).createQuery(Query.QUERY_TYPE_SQL);
        BulkResponse bResponse = ((DeclarativeQueryManagerImpl) dqm).executeQuery(query, queryParams);

        Collection<?> exceptions = bResponse.getExceptions();
        //TO DO: forward exceptions to an error JSP
        if (exceptions != null) {
            Iterator<?> iter = exceptions.iterator();
            Exception exception = null;
            @SuppressWarnings("unused")
            StringBuffer sb2 = new StringBuffer(WebUIResourceBundle.getInstance().getString("errorExecQuery"));
            while (iter.hasNext()) {
                exception = (Exception) iter.next();
            }
            log.error("\n" + exception.getMessage());
        }
        // Filter hidden schemes here.
        classSchemes = filterHiddenSchemes(bResponse.getCollection());
    } catch (Throwable t) {
        log.error(t.getMessage());
    }
    return classSchemes;
}