Example usage for javax.xml.registry RegistryException RegistryException

List of usage examples for javax.xml.registry RegistryException RegistryException

Introduction

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

Prototype

public RegistryException(Throwable cause) 

Source Link

Document

Constructs a JAXRException object initialized with the given Throwable object.

Usage

From source file:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java

/**
 * Sets the owner on the specified objects based upon RequestContext.
 *///w w  w . j  a  v  a 2  s .  c  o m
@SuppressWarnings({ "rawtypes", "unchecked" })
public void changeOwner(ServerRequestContext context, List objects) throws RegistryException {
    try {
        ObjectRefListType ebObjectRefListType = bu.rimFac.createObjectRefListType();
        ebObjectRefListType.getObjectRef().addAll(bu.getObjectRefTypeListFromRegistryObjects(objects));
        context.getRelocateEvent().setAffectedObjects(ebObjectRefListType);
    } catch (JAXRException e) {
        throw new RegistryException(e);
    }
}

From source file:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java

/**
 * Updates the idToLidMap in context entries with RegistryObject id as Key
 * and RegistryObject lid as value for each object that matches specified
 * id.//from  w w w  . j  a v a  2  s  . co  m
 * 
 */
public void updateIdToLidMap(ServerRequestContext context, Set<String> ids, String tableName)
        throws RegistryException {
    if ((ids != null) && (ids.size() >= 0)) {

        Iterator<String> iter = ids.iterator();
        Statement stmt = null;

        try {
            stmt = context.getConnection().createStatement();

            StringBuffer sql = new StringBuffer("SELECT id, lid FROM " + tableName + " WHERE id IN (");
            @SuppressWarnings("unused")
            List<String> existingIdList = new ArrayList<String>();

            /*
             * We need to count the number of item in "IN" list. We need to
             * split the a single SQL Strings if it is too long. Some
             * database such as Oracle, does not allow the IN list is too
             * long
             */
            int listCounter = 0;

            while (iter.hasNext()) {
                String id = iter.next();

                if (iter.hasNext() && (listCounter < IdentifiableDAO.identifiableExistsBatchCount)) {
                    sql.append("'" + id + "',");
                } else {
                    sql.append("'" + id + "')");

                    // log.info("sql string=" + sql.toString());
                    ResultSet rs = stmt.executeQuery(sql.toString());

                    while (rs.next()) {
                        String _id = rs.getString(1);
                        String lid = rs.getString(2);
                        context.getIdToLidMap().put(_id, lid);
                    }

                    sql = new StringBuffer("SELECT id, lid FROM " + tableName + " WHERE id IN (");
                    listCounter = 0;
                }

                listCounter++;
            }
        } catch (SQLException e) {
            throw new RegistryException(e);
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException sqle) {
                log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), sqle);
            }
        }
    }
}

From source file:it.cnr.icar.eric.server.persistence.rdb.SQLPersistenceManagerImpl.java

/**
 * Checks each object being deleted to make sure that it does not have any
 * currently existing references. Objects must be fetched from the Cache or
 * Server and not from the RequestContext??
 * //from   w  w w.j av  a 2s  .  c o m
 * @throws ReferencesExistException
 *             if references exist to any of the RegistryObject ids
 *             specified in roIds
 * 
 */
@SuppressWarnings("static-access")
public void checkIfReferencesExist(ServerRequestContext context, List<String> roIds) throws RegistryException {
    if (skipReferenceCheckOnRemove) {
        return;
    }

    Iterator<String> iter = roIds.iterator();

    HashMap<String, ArrayList<String>> idToReferenceSourceMap = new HashMap<String, ArrayList<String>>();
    while (iter.hasNext()) {
        String id = iter.next();

        StringBuffer query = new StringBuffer();
        query.append("SELECT id FROM RegistryObject WHERE objectType = ? UNION ");
        query.append("SELECT id FROM ClassificationNode WHERE parent = ? UNION ");
        query.append(
                "SELECT id FROM Classification WHERE classificationNode = ? OR classificationScheme = ? OR classifiedObject = ? UNION ");
        query.append(
                "SELECT id FROM ExternalIdentifier WHERE identificationScheme = ? OR registryObject = ? UNION ");
        query.append(
                "SELECT id FROM Association WHERE associationType = ? OR sourceObject = ? OR targetObject= ?  UNION ");
        query.append("SELECT id FROM AuditableEvent WHERE user_ = ? OR requestId = ? UNION ");
        query.append("SELECT id FROM Organization WHERE parent = ? UNION ");
        query.append("SELECT id FROM Registry where operator = ? UNION ");
        query.append("SELECT id FROM ServiceBinding WHERE service = ? OR targetBinding = ? UNION ");
        query.append(
                "SELECT id FROM SpecificationLink WHERE serviceBinding = ? OR specificationObject = ? UNION ");
        query.append("SELECT id FROM Subscription WHERE selector = ?  UNION ");
        query.append("SELECT s.parent FROM Slot s WHERE s.slotType = '" + bu.CANONICAL_DATA_TYPE_ID_ObjectRef
                + "' AND s.value = ?");

        PreparedStatement stmt = null;
        try {
            stmt = context.getConnection().prepareStatement(query.toString());
            stmt.setString(1, id);
            stmt.setString(2, id);
            stmt.setString(3, id);
            stmt.setString(4, id);
            stmt.setString(5, id);
            stmt.setString(6, id);
            stmt.setString(7, id);
            stmt.setString(8, id);
            stmt.setString(9, id);
            stmt.setString(10, id);
            stmt.setString(11, id);
            stmt.setString(12, id);
            stmt.setString(13, id);
            stmt.setString(14, id);
            stmt.setString(15, id);
            stmt.setString(16, id);
            stmt.setString(17, id);
            stmt.setString(18, id);
            stmt.setString(19, id);
            stmt.setString(20, id);

            ResultSet rs = stmt.executeQuery();
            @SuppressWarnings("unused")
            boolean result = false;

            ArrayList<String> referenceSourceIds = new ArrayList<String>();
            while (rs.next()) {
                String referenceSourceId = rs.getString(1);
                if (!roIds.contains(referenceSourceId)) {
                    referenceSourceIds.add(referenceSourceId);
                }
            }

            if (!referenceSourceIds.isEmpty()) {
                idToReferenceSourceMap.put(id, referenceSourceIds);
            }
        } catch (SQLException e) {
            throw new RegistryException(e);
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException sqle) {
                log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), sqle);
            }
        }
    }

    if (!idToReferenceSourceMap.isEmpty()) {
        // At least one ref exists to at least one object so throw exception
        String msg = ServerResourceBundle.getInstance().getString("message.referencesExist");
        msg += "\n" + idToReferenceSourceMap.toString();

        throw new ReferencesExistException(msg);
    }
}

From source file:org.freebxml.omar.server.cache.AbstractCache.java

protected RegistryObjectType getRegistryObjectInternal(ServerRequestContext context, String id, String typeName)
        throws RegistryException {

    RegistryObjectType ro = null;/*from   w w  w.ja  v a 2 s.  c o m*/

    typeName = bu.mapJAXRNameToEbXMLName(typeName);
    String tableName = Utility.getInstance().mapTableName(typeName);

    try {
        if (id != null) {
            // COMMENT 1:
            // HIEOS/AMS: Commented the following lines of code. No need to convert 'id' to upper case
            // and subsequently compare using SQL's UPPER function (Using this prevents
            /// evaluation of indices on 'id').
            // String sqlQuery = "Select * from " + tableName + " WHERE UPPER(id) = ?";
            String sqlQuery = "Select * from " + tableName + " WHERE id = ?";
            ArrayList queryParams = new ArrayList();

            // HIEOS/AMS: See COMMENT 1.
            //queryParams.add(id.toUpperCase());
            queryParams.add(id);
            List results = executeQueryInternal(context, sqlQuery, queryParams, tableName);

            if (results.size() > 0) {
                ro = (RegistryObjectType) results.get(0);
            } else {
                ro = null;
            }
        }
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        //e.printStackTrace();
        throw new RegistryException(e);
    }

    return ro;
}

From source file:org.freebxml.omar.server.cache.AbstractCache.java

protected List executeQueryInternal(ServerRequestContext context, String sqlQuery, List queryParams,
        String tableName) throws RegistryException {

    List results = null;//from   www  .j  a  v  a  2s.  com
    initializeQueryVars(false);

    try {
        ResponseOption responseOption = bu.queryFac.createResponseOption();
        responseOption.setReturnComposedObjects(true);
        responseOption.setReturnType(ReturnType.LEAF_CLASS);

        List objectRefs = new ArrayList();
        results = pm.executeSQLQuery(context, sqlQuery, queryParams, responseOption, tableName, objectRefs);
    } catch (JAXBException e) {
        throw new RegistryException(e);
    }

    return results;
}

From source file:org.freebxml.omar.server.cache.ClassificationSchemeCache.java

/**
 * Gets all schemes.  Note that descendent nodes of schemes up to the
 * depth level that is configured for the cache may also be loaded into
 * the object cache./*from w  ww . jav a  2s  .  c  o  m*/
 */
public List getAllClassificationSchemes(ServerRequestContext context) throws RegistryException {

    List result = null;

    try {
        primeCacheOnFirstUse(context);

        synchronized (internalCache) {
            if (cacheIsPrimed) {
                result = getAllClassificationSchemesFromCache();
            }
        }
        // If not, we mostly update the cache outside the lock.
        if (null == result) {
            result = updateScheme(context, "%", true /* false */);
        }
    } catch (CacheException e) {
        throw new RegistryException(e);
    }

    return result;
}

From source file:org.freebxml.omar.server.cache.ClassificationSchemeCache.java

/**
 * Gets schemes that match id pattern.  Note that descendent nodes of
 * schemes up to the depth level that is configured for the cache may
 * also be loaded into the object cache.
 *///from   w  ww. j  a  v a 2s  .co m
public List getClassificationSchemesById(ServerRequestContext context, String idPattern)
        throws RegistryException {

    List matchedSchemes = null;

    try {
        primeCacheOnFirstUse(context);

        if (Utility.getInstance().isValidRegistryId(idPattern)) {
            //Valid id: check if it is in cache
            Element elem = internalCache.get(idPattern);
            if (null == elem) {
                //Cache miss. Get from dB
                matchedSchemes = updateScheme(context, idPattern, true /* false */ );
            } else {
                ClassificationSchemeType scheme = (ClassificationSchemeType) elem.getValue();
                //Cache hit
                matchedSchemes = Collections.singletonList(scheme);
            }
        } else {
            //Not a valid id: must be a pattern
            List schemes = getAllClassificationSchemes(context);
            if (idPattern.equals("%")) {
                matchedSchemes = schemes;
            } else {
                matchedSchemes = new ArrayList();
                Iterator iter = schemes.iterator();
                while (iter.hasNext()) {
                    ClassificationSchemeType scheme = (ClassificationSchemeType) iter.next();
                    String schemeId = scheme.getId();
                    if (idPattern.equalsIgnoreCase(schemeId)) {
                        matchedSchemes.add(scheme);
                    } else if (schemeId.matches(idPattern)) {
                        matchedSchemes.add(scheme);
                    }
                }
            }
        }
    } catch (CacheException e) {
        throw new RegistryException(e);
    }

    return matchedSchemes;
}

From source file:org.freebxml.omar.server.cache.ClassificationSchemeCache.java

protected void updateCacheEntry(ServerRequestContext context, RegistryObjectType ro) throws RegistryException {

    // ??? i18n//from  w  ww . ja  v  a 2  s  .  co m
    throw new RegistryException("Internal error. Unimplemented function should not have been called.");
    /*
    RegistryObjectType scheme = null;
    ClassificationSchemeType schemeParent = null;
    ClassificationNodeType nodeParent = null;
    if (ro instanceof ClassificationSchemeType) {
    scheme = ro;
    } else if (ro instanceof ClassificationNodeType) {
    scheme = ((ClassificationNodeType)ro).;
    children = nodeParent.getClassificationNode();
    }
    */
}

From source file:org.freebxml.omar.server.cache.ClassificationSchemeCache.java

/**
 * This method is used to retrieve a ClassificationNode based on its path.
 * Note: if an invalid path is passed to this method, this method will
 * return null//from  ww  w.j  a  va  2  s .c  o  m
 * 
 * @param path
 * A String containing the ClassificationNodeType path
 * @return
 * A ClassificationNodeType instance that matches the path
 */
public ClassificationNodeType getClassificationNodeByPath(String path) throws RegistryException {
    ClassificationNodeType cn = null;
    ServerRequestContext context = null;
    try {
        Element elem = getPathToNodeCache().get(path);
        if (elem == null) {
            String likeOrEqual = "=";
            if (path.indexOf('%') != -1) {
                likeOrEqual = "LIKE";
            }
            String tableName = "ClassificationNode";

            // COMMENT 1:
            // HIEOS/AMS: Commented the following lines of code. No need to convert 'path' to upper case
            // and subsequently compare using SQL's UPPER function (Using this prevents
            // evaluation of indices on 'cn.path').
            // String sqlQuery = "SELECT cn.* from ClassificationNode cn WHERE UPPER(cn.path) " +
            // likeOrEqual + " ? ORDER BY cn.path ASC";
            String sqlQuery = "SELECT cn.* from ClassificationNode cn WHERE cn.path " + likeOrEqual
                    + " ? ORDER BY cn.path ASC";
            ArrayList queryParams = new ArrayList();

            // HIEOS/AMS: See COMMENT 1
            // queryParams.add(path.toUpperCase());
            queryParams.add(path);

            context = new ServerRequestContext("ClassificationSchemeCache.getClassificationNodeByPath", null);
            List results = executeQueryInternal(context, sqlQuery, queryParams, tableName);
            if (results.size() == 0) {
                return null;
            }
            cn = (ClassificationNodeType) results.get(0);
            elem = new Element((Serializable) path, (Serializable) cn);
            getPathToNodeCache().put(elem);
        } else {
            cn = (ClassificationNodeType) elem.getValue();
        }
    } catch (RegistryException re) {
        throw re;
    } catch (Throwable t) {
        throw new RegistryException(t);
    } finally {
        if (context != null) {
            context.rollback();
        }
    }
    return cn;
}

From source file:org.freebxml.omar.server.cache.ObjectCache.java

private void cacheStoredQueries(ServerRequestContext context) throws RegistryException {

    try {//from   www.j  av  a  2  s  . c  om
        String sqlQuery = "Select q.* from AdhocQuery q";
        List results = executeQueryInternal(context, sqlQuery, null, "AdhocQuery");

        Iterator iter = results.iterator();
        while (iter.hasNext()) {
            RegistryObjectType ro = (RegistryObjectType) iter.next();
            putRegistryObject(ro);
        }
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    }
}