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.RegistryObjectDAO.java

private void getRegistryObjectsIdsFromResultSet(ResultSet rs, int startIndex, int maxResults,
        StringBuffer adhocQuerys, StringBuffer associations, StringBuffer auEvents,
        StringBuffer classifications, StringBuffer schemes, StringBuffer classificationNodes,
        StringBuffer externalIds, StringBuffer externalLinks, StringBuffer extrinsicObjects,
        StringBuffer federations, StringBuffer organizations, StringBuffer registrys, StringBuffer packages,
        StringBuffer serviceBindings, StringBuffer services, StringBuffer specificationLinks,
        StringBuffer subscriptions, StringBuffer users, StringBuffer persons)
        throws SQLException, RegistryException {
    HashSet<String> processed = new HashSet<String>();

    if (startIndex > 0) {
        // calling rs.next() is a workaround for some drivers, such
        // as Derby's, that do not set the cursor during call to
        // rs.relative(...)
        rs.next();//from  w  ww .  java2  s .c  om
        @SuppressWarnings("unused")
        boolean onRow = rs.relative(startIndex - 1);
    }

    int cnt = 0;
    while (rs.next()) {
        String id = rs.getString("id");

        // Only process if not already processed
        // This avoid OutOfMemoryError when huge number of objects match
        // Currently this happens when name and desc are null and their
        // predicates get pruned but the tablename stays.
        // TODO: Fix query pruning so tableName is pruned if not used.
        if (!(processed.contains(id))) {
            cnt++;
            String type = rs.getString("objectType");
            // System.err.println("id=" + id + " objectType=" + type +
            // " extrinsicObjects=" + extrinsicObjects);

            // log.info(ServerResourceBundle.getInstance().getString("message.objectType=''",
            // new Object[]{type}));
            if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_AdhocQuery)) {
                if (adhocQuerys.length() == 0) {
                    adhocQuerys.append("'" + id + "'");
                } else {
                    adhocQuerys.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Association)) {
                if (associations.length() == 0) {
                    associations.append("'" + id + "'");
                } else {
                    associations.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_AuditableEvent)) {
                if (auEvents.length() == 0) {
                    auEvents.append("'" + id + "'");
                } else {
                    auEvents.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Classification)) {
                if (classifications.length() == 0) {
                    classifications.append("'" + id + "'");
                } else {
                    classifications.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ClassificationNode)) {
                if (classificationNodes.length() == 0) {
                    classificationNodes.append("'" + id + "'");
                } else {
                    classificationNodes.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ClassificationScheme)) {
                if (schemes.length() == 0) {
                    schemes.append("'" + id + "'");
                } else {
                    schemes.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ExternalIdentifier)) {
                if (externalIds.length() == 0) {
                    externalIds.append("'" + id + "'");
                } else {
                    externalIds.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ExternalLink)) {
                if (externalLinks.length() == 0) {
                    externalLinks.append("'" + id + "'");
                } else {
                    externalLinks.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ExtrinsicObject)) {
                if (extrinsicObjects.length() == 0) {
                    extrinsicObjects.append("'" + id + "'");
                } else {
                    extrinsicObjects.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Federation)) {
                if (federations.length() == 0) {
                    federations.append("'" + id + "'");
                } else {
                    federations.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Organization)) {
                if (organizations.length() == 0) {
                    organizations.append("'" + id + "'");
                } else {
                    organizations.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Registry)) {
                if (registrys.length() == 0) {
                    registrys.append("'" + id + "'");
                } else {
                    registrys.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_RegistryPackage)) {
                if (packages.length() == 0) {
                    packages.append("'" + id + "'");
                } else {
                    packages.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_ServiceBinding)) {
                if (serviceBindings.length() == 0) {
                    serviceBindings.append("'" + id + "'");
                } else {
                    serviceBindings.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Service)) {
                if (services.length() == 0) {
                    services.append("'" + id + "'");
                } else {
                    services.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_SpecificationLink)) {
                if (specificationLinks.length() == 0) {
                    specificationLinks.append("'" + id + "'");
                } else {
                    specificationLinks.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Subscription)) {
                if (subscriptions.length() == 0) {
                    subscriptions.append("'" + id + "'");
                } else {
                    subscriptions.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_User)) {
                if (users.length() == 0) {
                    users.append("'" + id + "'");
                } else {
                    users.append(",'" + id + "'");
                }
            } else if (type.equalsIgnoreCase(BindingUtility.CANONICAL_OBJECT_TYPE_ID_Person)) {
                if (persons.length() == 0) {
                    persons.append("'" + id + "'");
                } else {
                    persons.append(",'" + id + "'");
                }
            } else {
                // Type is user defined. Table could be either
                // ExtrinsicObject or ExternalLink
                SQLPersistenceManagerImpl pm = SQLPersistenceManagerImpl.getInstance();

                ArrayList<String> queryParams = new ArrayList<String>();
                queryParams.add(id.toUpperCase());
                ExtrinsicObjectType eo = (ExtrinsicObjectType) pm.getRegistryObjectMatchingQuery(context,
                        "SELECT * from ExtrinsicObject where UPPER(id) = ?", queryParams, "ExtrinsicObject");

                if (eo != null) {
                    if (extrinsicObjects.length() == 0) {
                        extrinsicObjects.append("'" + id + "'");
                    } else {
                        extrinsicObjects.append(",'" + id + "'");
                    }
                } else {
                    ExternalLinkType el = (ExternalLinkType) pm.getRegistryObjectMatchingQuery(context,
                            "SELECT * from ExternalLink where UPPER(id) = ?", queryParams, "ExternalLink");

                    if (el != null) {
                        if (externalLinks.length() == 0) {
                            externalLinks.append("'" + id + "'");
                        } else {
                            externalLinks.append(",'" + id + "'");
                        }
                    } else {
                        throw new RegistryException(ServerResourceBundle.getInstance()
                                .getString("message.unknownObjectType", new Object[] { type }));
                    }
                }
            }
            processed.add(id);

            if (cnt == maxResults) {
                break;
            }
        }
    }

    if (cnt > 1000) {
        log.warn(ServerResourceBundle.getInstance().getString("message.WarningExcessiveResultSetSizeQUery",
                new Object[] { new Integer(cnt) }));
    }
}

From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java

/**
 * Removes one or more previously submitted objects from the registry. If
 * the deletionScope is "DeleteRepositoryItemOnly", it will assume all the
 * ObjectRef under ObjectRefList is referencing repository items. If the
 * deletionScope is "DeleteAll", the reference may be either RegistryObject
 * or repository item. In both case, if the referenced object cannot be
 * found, RegistryResponse with errors list will be returned.
 *///from  w w  w .ja  v  a  2 s .c  o  m
@SuppressWarnings({ "unused", "unchecked" })
public RegistryResponseType removeObjects(RequestContext context) throws RegistryException {
    context = ServerRequestContext.convert(context);
    ServerRequestContext _context = (ServerRequestContext) context;
    RegistryResponseType ebRegistryResponseType = null;
    RemoveObjectsRequest req = (RemoveObjectsRequest) _context.getCurrentRegistryRequest();
    HashMap<String, Object> idToRepositoryMap = _context.getRepositoryItemsMap();
    UserType user = _context.getUser();

    // This request option instructs the server to delete objects even if
    // references exist to them
    boolean forceDelete = false;

    // This request option instructs the server to also delete the network
    // of objects reachable by
    // reference from the objects being deleted. This option is not
    // implemented yet.
    boolean cascadeDelete = false;

    try {
        // Get relevant request slots if any
        HashMap<String, Object> requestSlots = bu.getSlotsFromRequest(req);

        if (requestSlots.containsKey(CanonicalConstants.CANONICAL_SLOT_DELETE_MODE_FORCE)) {
            String val = (String) requestSlots.get(CanonicalConstants.CANONICAL_SLOT_DELETE_MODE_FORCE);
            if (val.trim().equalsIgnoreCase("true")) {
                forceDelete = true;
            }
        }

        if (requestSlots.containsKey(CanonicalConstants.CANONICAL_SLOT_DELETE_MODE_CASCADE)) {
            String val = (String) requestSlots.get(CanonicalConstants.CANONICAL_SLOT_DELETE_MODE_CASCADE);
            if (val.trim().equalsIgnoreCase("true")) {
                cascadeDelete = true;
            }
        }

        List<ObjectRefType> ebObjectRefTypeList = null;
        if (req.getObjectRefList() == null) {
            ObjectRefListType ebObjectRefListType = bu.rimFac.createObjectRefListType();
            req.setObjectRefList(ebObjectRefListType);
        }

        // Add explicitly specified oref params
        ebObjectRefTypeList = bu.getObjectRefTypeListFromObjectRefListType(req.getObjectRefList());

        // Append those orefs specified via ad hoc query param
        ebObjectRefTypeList.addAll(
                (List<ObjectRefType>) _context.getObjectsRefTypeListFromQueryResults(req.getAdhocQuery()));

        Iterator<ObjectRefType> ebObjectRefTypeIter = ebObjectRefTypeList.iterator();

        while (ebObjectRefTypeIter.hasNext()) {
            ObjectRefType ebObjectRefType = ebObjectRefTypeIter.next();
            _context.getObjectRefTypeMap().put(ebObjectRefType.getId(), ebObjectRefType);
        }

        List<String> idList = new ArrayList<String>(_context.getObjectRefTypeMap().keySet());
        pm.updateIdToLidMap(_context, _context.getObjectRefTypeMap().keySet(), "RegistryObject");
        Set<String> idsNotInRegistry = _context.getIdsNotInRegistry(_context.getObjectRefTypeMap().keySet());
        if (idsNotInRegistry.size() > 0) {
            throw new ObjectsNotFoundException(new ArrayList<String>(idsNotInRegistry));
        }
        checkAuthorizedAll(_context);

        String deletionScope = BindingUtility.CANONICAL_DELETION_SCOPE_TYPE_ID_DeleteAll;

        if (req.getDeletionScope() != null) {
            deletionScope = req.getDeletionScope();
        }

        // DeletionScope=DeleteRepositoryItemOnly. If any repository item
        // does not exist, it will stop
        if (deletionScope.equals(BindingUtility.CANONICAL_DELETION_SCOPE_TYPE_ID_DeleteRepositoryItemOnly)) {
            List<String> notExist = rm.itemsExist(idList);

            if (notExist.size() > 0) {
                throw new ObjectsNotFoundException(notExist);
            }

            // Should RepositoryItem be deleted even when referencesExist??
            // if (!forceDelete) {
            // pm.checkIfReferencesExist((ServerRequestContext) context,
            // idList);
            // }
            rm.delete(idList);
        } else if (deletionScope.equals(BindingUtility.CANONICAL_DELETION_SCOPE_TYPE_ID_DeleteAll)) {
            // find out which id is not an id of a repository item (i.e.
            // referencing RO only
            List<String> nonItemsIds = rm.itemsExist(idList);

            // find out which id is an id of a repository item
            List<String> itemsIds = new java.util.ArrayList<String>();
            Iterator<String> idListIt = idList.iterator();

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

                if (!nonItemsIds.contains(id)) {
                    itemsIds.add(id);
                }
            }

            if (!forceDelete) {
                pm.checkIfReferencesExist((ServerRequestContext) context, idList);
            }

            // Delete the repository items
            rm.delete(itemsIds);

            // Delete all ROs with the ids
            pm.delete(_context, ebObjectRefTypeList);
        } else {
            throw new RegistryException(
                    ServerResourceBundle.getInstance().getString("message.undefinedDeletionScope"));
        }

        ebRegistryResponseType = bu.rsFac.createRegistryResponseType();
        ebRegistryResponseType.setStatus(BindingUtility.CANONICAL_RESPONSE_STATUS_TYPE_ID_Success);
    } catch (RegistryException e) {
        ((ServerRequestContext) context).rollback();
        throw e;
    } catch (Exception e) {
        ((ServerRequestContext) context).rollback();
        throw new RegistryException(e);
    }

    ((ServerRequestContext) context).commit();
    return ebRegistryResponseType;
}

From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java

/** Sends an impl specific protocol extension request. */
public RegistryResponseHolder extensionRequest(RequestContext context) throws RegistryException {
    context = ServerRequestContext.convert(context);
    RegistryResponseHolder respHolder = null;
    RegistryRequestType ebRegistryRequestType = ((ServerRequestContext) context).getCurrentRegistryRequest();
    HashMap<String, Object> idToRepositoryMap = ((ServerRequestContext) context).getRepositoryItemsMap();
    UserType ebUserType = ((ServerRequestContext) context).getUser();

    try {/* w  ww .ja  v a 2  s . c  om*/
        HashMap<String, Object> slotsMap = bu.getSlotsFromRequest(ebRegistryRequestType);
        String signCertProtocol = (String) slotsMap.get(BindingUtility.FREEBXML_REGISTRY_PROTOCOL_SIGNCERT);

        if ("true".equalsIgnoreCase(signCertProtocol)) {
            respHolder = CertificateAuthority.getInstance().signCertificateRequest(ebUserType,
                    ebRegistryRequestType, idToRepositoryMap);
        } else {
            throw new RegistryException("Unknown extensionRequest");
        }

    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return respHolder;
}

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

/**
 * Executes an SQL Query.//from  ww w . j a va  2 s.c o m
 */
@SuppressWarnings({ "static-access", "unchecked" })
public List<IdentifiableType> executeSQLQuery(ServerRequestContext context, String sqlQuery,
        List<String> queryParams, ResponseOptionType ebResponseOptionType, String tableName, List<?> objectRefs,
        IterativeQueryParams paramHolder) throws RegistryException {
    @SuppressWarnings("rawtypes")
    List ebIdentifiableTypeResultList = null;
    Connection connection = null;
    int startIndex = paramHolder.startIndex;
    int maxResults = paramHolder.maxResults;
    int totalResultCount = -1;
    Statement stmt = null;

    try {
        connection = context.getConnection();

        java.sql.ResultSet rs = null;

        tableName = Utility.getInstance().mapTableName(tableName);

        ReturnType returnType = ebResponseOptionType.getReturnType();
        @SuppressWarnings("unused")
        boolean returnComposedObjects = ebResponseOptionType.isReturnComposedObjects();

        if (maxResults < 0) {
            if (queryParams == null) {
                stmt = connection.createStatement();
            } else {
                stmt = connection.prepareStatement(sqlQuery);
            }
        } else {
            if (queryParams == null) {
                stmt = connection.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
                        java.sql.ResultSet.CONCUR_READ_ONLY);
            } else {
                stmt = connection.prepareStatement(sqlQuery, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
                        java.sql.ResultSet.CONCUR_READ_ONLY);
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("Executing query: '" + sqlQuery + "'");
            if (dumpStackOnQuery) {
                Thread.currentThread().dumpStack();
            }
        }

        if (queryParams == null) {
            rs = stmt.executeQuery(sqlQuery);
        } else {
            Iterator<String> iter = queryParams.iterator();
            int paramCount = 0;
            while (iter.hasNext()) {
                Object param = iter.next();
                ((PreparedStatement) stmt).setObject(++paramCount, param);
            }
            rs = ((PreparedStatement) stmt).executeQuery();
        }
        if (maxResults >= 0) {
            rs.last();
            totalResultCount = rs.getRow();
            // Reset back to before first row so that DAO can correctly
            // scroll
            // through the result set
            rs.beforeFirst();
        }
        @SuppressWarnings("unused")
        Iterator<?> iter = null;

        log.debug("::3:: SQL result ReturnType" + returnType.toString());

        if (returnType == ReturnType.OBJECT_REF) {

            ebIdentifiableTypeResultList = new ArrayList<Object>();

            if (startIndex > 0) {
                rs.last();
                totalResultCount = rs.getRow();
                rs.beforeFirst();
                // calling rs.next() is a workaround for some drivers, such
                // as Derby's, that do not set the cursor during call to
                // rs.relative(...)
                rs.next();
                @SuppressWarnings("unused")
                boolean onRow = rs.relative(startIndex - 1);
            }

            int cnt = 0;
            while (rs.next()) {

                ObjectRefType ebObjectRefType = bu.rimFac.createObjectRefType();
                // TODO: JAXBElement

                String id = rs.getString(1);
                ebObjectRefType.setId(id);
                ebIdentifiableTypeResultList.add(ebObjectRefType);

                if (++cnt == maxResults) {
                    break;
                }
            }
        } else if (returnType == ReturnType.REGISTRY_OBJECT) {
            context.setResponseOption(ebResponseOptionType);
            RegistryObjectDAO roDAO = new RegistryObjectDAO(context);
            ebIdentifiableTypeResultList = roDAO.getObjects(rs, startIndex, maxResults);

        } else if ((returnType == ReturnType.LEAF_CLASS)
                || (returnType == ReturnType.LEAF_CLASS_WITH_REPOSITORY_ITEM)) {
            ebIdentifiableTypeResultList = getObjects(context, connection, rs, tableName, ebResponseOptionType,
                    objectRefs, startIndex, maxResults);

        } else {
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.invalidReturnType", new Object[] { returnType }));
        }

    } 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);
        }
    }

    paramHolder.totalResultCount = totalResultCount;

    return ebIdentifiableTypeResultList;
}

From source file:it.cnr.icar.eric.server.common.ServerRequestContext.java

public Set<?> getReferenceInfos() throws RegistryException {
    if (referencedInfos == null) {
        try {//from   w w w  .j av  a2s  .  c o  m
            referencedInfos = new HashSet<Object>();

            Iterator<Entry<String, Object>> iter = getSubmittedObjectsMap().entrySet().iterator();
            while (iter.hasNext()) {
                Object o = (iter.next()).getValue();

                if (o instanceof RegistryObjectType) {
                    RegistryObjectType ro = (RegistryObjectType) o;
                    //Get Set of ids for objects referenced from obj
                    Set<ReferenceInfo> refInfos = bu.getObjectRefsInRegistryObject(ro, getIdMap(),
                            new HashSet<RegistryObjectType>(), -1);

                    Iterator<ReferenceInfo> refInfosIter = refInfos.iterator();
                    while (refInfosIter.hasNext()) {
                        referencedInfos.add(refInfosIter.next());
                    }
                }
            }
        } catch (JAXRException e) {
            throw new RegistryException(e);
        }
    }

    return referencedInfos;
}

From source file:it.cnr.icar.eric.server.common.ServerRequestContext.java

public void checkClassificationNodeRefConstraint(String nodeId, String expectedSchemeId, String attributeName)
        throws RegistryException {
    ClassificationSchemeType expectedScheme = null;
    try {//from w  w w  .  j ava2  s .c om
        //Check that objectType is the id of a ClassificationNode in ObjectType scheme
        expectedScheme = (ClassificationSchemeType) ServerCache.getInstance().getRegistryObject(this,
                expectedSchemeId, "ClassScheme");

        ClassificationNodeType node = (ClassificationNodeType) this.getRegistryObject(nodeId,
                "ClassificationNode");
        String path = node.getPath();
        String schemePath = "/" + expectedScheme.getId();

        if ((path != null) && (path.length() > 0)) {
            if (!path.startsWith(schemePath)) {
                throw new RegistryException(
                        ServerResourceBundle.getInstance().getString("message.notTheExpectedTypeOfNode",
                                new Object[] { attributeName, expectedScheme.getId(), nodeId }));
            }
        }
    } catch (ObjectNotFoundException e) {
        throw new RegistryException(
                ServerResourceBundle.getInstance().getString("message.notTheExpectedTypeOfNode",
                        new Object[] { attributeName, expectedScheme.getId(), nodeId }));

    }
}

From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java

@SuppressWarnings("unused")
public RegistryResponseType relocateObjects(RequestContext context) throws RegistryException {
    context = ServerRequestContext.convert(context);
    RegistryResponseType ebRegistryResponseType = null;
    RelocateObjectsRequest ebRelocateObjectsRequest = (RelocateObjectsRequest) ((ServerRequestContext) context)
            .getCurrentRegistryRequest();
    HashMap<String, Object> idToRepositoryMap = ((ServerRequestContext) context).getRepositoryItemsMap();
    UserType ebUserType = ((ServerRequestContext) context).getUser();

    try {/* w w  w .  j  a  va2 s .  co  m*/
        RelocationProcessor relocationMgr = new RelocationProcessor(((ServerRequestContext) context));
        ebRegistryResponseType = relocationMgr.relocateObjects();
    } catch (Exception e) {
        ((ServerRequestContext) context).rollback();
        throw new RegistryException(e);
    }

    ((ServerRequestContext) context).commit();
    return ebRegistryResponseType;

}

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

/**
 * Gets the List of binding objects for specified ResultSet. This method
 * return leaf object types while the base class version returns
 * RegistryObjects./* w  w w .  ja  v a 2  s  .com*/
 * 
 */
public List<?> getObjectsHetero(ResultSet rs, int startIndex, int maxResults) throws RegistryException {
    ArrayList<Object> res = new ArrayList<Object>();
    String sql = null;

    StringBuffer adhocQuerysIds = new StringBuffer();
    StringBuffer associationsIds = new StringBuffer();
    StringBuffer auditableEventsIds = new StringBuffer();
    StringBuffer classificationsIds = new StringBuffer();
    StringBuffer schemesIds = new StringBuffer();
    StringBuffer classificationNodesIds = new StringBuffer();
    StringBuffer externalIdsIds = new StringBuffer();
    StringBuffer externalLinksIds = new StringBuffer();
    StringBuffer extrinsicObjectsIds = new StringBuffer();
    StringBuffer federationsIds = new StringBuffer();
    StringBuffer organizationsIds = new StringBuffer();
    StringBuffer registrysIds = new StringBuffer();
    StringBuffer packagesIds = new StringBuffer();
    StringBuffer serviceBindingsIds = new StringBuffer();
    StringBuffer servicesIds = new StringBuffer();
    StringBuffer specificationLinksIds = new StringBuffer();
    StringBuffer subscriptionsIds = new StringBuffer();
    StringBuffer usersIds = new StringBuffer();
    StringBuffer personsIds = new StringBuffer();

    Statement stmt = null;

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

        getRegistryObjectsIdsFromResultSet(rs, startIndex, maxResults, adhocQuerysIds, associationsIds,
                auditableEventsIds, classificationsIds, schemesIds, classificationNodesIds, externalIdsIds,
                externalLinksIds, extrinsicObjectsIds, federationsIds, organizationsIds, registrysIds,
                packagesIds, serviceBindingsIds, servicesIds, specificationLinksIds, subscriptionsIds, usersIds,
                personsIds);

        ResultSet leafObjectsRs = null;

        if (adhocQuerysIds.length() > 0) {
            AdhocQueryDAO ahqDAO = new AdhocQueryDAO(context);
            sql = "SELECT * FROM " + ahqDAO.getTableName() + " WHERE id IN (" + adhocQuerysIds + ")";

            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(ahqDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (associationsIds.length() > 0) {
            AssociationDAO assDAO = new AssociationDAO(context);
            sql = "SELECT * FROM " + assDAO.getTableName() + " WHERE id IN (" + associationsIds + ")";

            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(assDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (auditableEventsIds.length() > 0) {
            AuditableEventDAO aeDAO = new AuditableEventDAO(context);
            sql = "SELECT * FROM " + aeDAO.getTableName() + " WHERE id IN (" + auditableEventsIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(aeDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (classificationsIds.length() > 0) {
            ClassificationDAO classificationDAO = new ClassificationDAO(context);
            sql = "SELECT * FROM " + classificationDAO.getTableName() + " WHERE id IN (" + classificationsIds
                    + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(classificationDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (classificationNodesIds.length() > 0) {
            ClassificationNodeDAO nodeDAO = new ClassificationNodeDAO(context);
            sql = "SELECT * FROM " + nodeDAO.getTableName() + " WHERE id IN (" + classificationNodesIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(nodeDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (schemesIds.length() > 0) {
            ClassificationSchemeDAO schemeDAO = new ClassificationSchemeDAO(context);
            sql = "SELECT * FROM " + schemeDAO.getTableName() + " WHERE id IN (" + schemesIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(schemeDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (externalIdsIds.length() > 0) {
            ExternalIdentifierDAO externalIdDAO = new ExternalIdentifierDAO(context);
            sql = "SELECT * FROM " + externalIdDAO.getTableName() + " WHERE id IN (" + externalIdsIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(externalIdDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (externalLinksIds.length() > 0) {
            ExternalLinkDAO externalLinkDAO = new ExternalLinkDAO(context);
            sql = "SELECT * FROM " + externalLinkDAO.getTableName() + " WHERE id IN (" + externalLinksIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(externalLinkDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (extrinsicObjectsIds.length() > 0) {
            ExtrinsicObjectDAO extrinsicObjectDAO = new ExtrinsicObjectDAO(context);
            sql = "SELECT * FROM " + extrinsicObjectDAO.getTableName() + " WHERE id IN (" + extrinsicObjectsIds
                    + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(extrinsicObjectDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (federationsIds.length() > 0) {
            FederationDAO fedDAO = new FederationDAO(context);
            sql = "SELECT * FROM " + fedDAO.getTableName() + " WHERE id IN (" + federationsIds + ")";

            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(fedDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (organizationsIds.length() > 0) {
            OrganizationDAO organizationDAO = new OrganizationDAO(context);
            sql = "SELECT * FROM " + organizationDAO.getTableName() + " WHERE id IN (" + organizationsIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(organizationDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (personsIds.length() > 0) {
            PersonDAO personDAO = new PersonDAO(context);
            sql = "SELECT * FROM " + personDAO.getTableName() + " WHERE id IN (" + personsIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(personDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (registrysIds.length() > 0) {
            RegistryDAO regDAO = new RegistryDAO(context);
            sql = "SELECT * FROM " + regDAO.getTableName() + " WHERE id IN (" + registrysIds + ")";

            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(regDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (packagesIds.length() > 0) {
            RegistryPackageDAO pkgDAO = new RegistryPackageDAO(context);
            sql = "SELECT * FROM " + pkgDAO.getTableName() + " WHERE id IN (" + packagesIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(pkgDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (serviceBindingsIds.length() > 0) {
            ServiceBindingDAO serviceBindingDAO = new ServiceBindingDAO(context);
            sql = "SELECT * FROM " + serviceBindingDAO.getTableName() + " WHERE id IN (" + serviceBindingsIds
                    + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(serviceBindingDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (servicesIds.length() > 0) {
            ServiceDAO serviceDAO = new ServiceDAO(context);
            sql = "SELECT * FROM " + serviceDAO.getTableName() + " WHERE id IN (" + servicesIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(serviceDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (specificationLinksIds.length() > 0) {
            SpecificationLinkDAO specLinkDAO = new SpecificationLinkDAO(context);
            sql = "SELECT * FROM " + specLinkDAO.getTableName() + " WHERE id IN (" + specificationLinksIds
                    + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(specLinkDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (subscriptionsIds.length() > 0) {
            SubscriptionDAO subDAO = new SubscriptionDAO(context);
            sql = "SELECT * FROM " + subDAO.getTableName() + " WHERE id IN (" + subscriptionsIds + ")";

            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(subDAO.getObjects(leafObjectsRs, 0, -1));
        }

        if (usersIds.length() > 0) {
            UserDAO userDAO = new UserDAO(context);
            sql = "SELECT * FROM " + userDAO.getTableName() + " WHERE id IN (" + usersIds + ")";
            leafObjectsRs = stmt.executeQuery(sql);
            res.addAll(userDAO.getObjects(leafObjectsRs, 0, -1));
        }

    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }

    return res;
}

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

/**
 * Get a HashMap with registry object id as key and owner id as value
 */// w  w w .j a v  a2s .c  o  m
public HashMap<String, String> getOwnersMap(List<String> ids) throws RegistryException {
    Statement stmt = null;
    List<?> resultSets = null;
    HashMap<String, String> ownersMap = new HashMap<String, String>();

    final String prefixPred = "SELECT ao.id, ae.user_, max(concat(ae.timeStamp_, ae.eventType)) FROM AuditableEvent ae, AffectedObject ao WHERE ao.eventId = ae.id";
    final String suffixPred = " AND (ae.eventType = '" + BindingUtility.CANONICAL_EVENT_TYPE_ID_Created
            + "' OR ae.eventType = '" + BindingUtility.CANONICAL_EVENT_TYPE_ID_Versioned
            + "' OR ae.eventType = '" + BindingUtility.CANONICAL_EVENT_TYPE_ID_Deleted + "' OR ae.eventType = '"
            + BindingUtility.CANONICAL_EVENT_TYPE_ID_Relocated + "') GROUP BY ao.id, ae.user_";

    if (ids.size() == 0) {
        return ownersMap;
    }

    try {

        if (ids.size() == 1) {
            // Optmization for 1 term case
            stmt = context.getConnection().createStatement();
            StringBuffer query = new StringBuffer(prefixPred);
            query.append(" AND ao.id = '").append(ids.get(0)).append("'");
            query.append(suffixPred);

            ResultSet rs = stmt.executeQuery(query.toString());

            // contains one line for each id and user with latest event
            while (rs.next()) {

                if (!rs.getString(3).endsWith(BindingUtility.CANONICAL_EVENT_TYPE_ID_Deleted))
                    ownersMap.put(rs.getString(1), rs.getString(2));
            }

            // while (rs.next()) {
            // ownersMap.put(rs.getString(1), rs.getString(2));
            // }
        } else {
            // This will handle unlimited terms using buffered Selects
            StringBuffer query = new StringBuffer(prefixPred);
            query.append(" AND ao.id IN ( $InClauseTerms ) ");
            query.append(suffixPred);

            resultSets = executeBufferedSelectWithINClause(query.toString(), ids, inClauseTermLimit);

            Iterator<?> resultsSetsIter = resultSets.iterator();

            while (resultsSetsIter.hasNext()) {
                ResultSet rs = (ResultSet) resultsSetsIter.next();

                // contains one line for each id and user with latest event
                while (rs.next()) {

                    if (!rs.getString(3).endsWith(BindingUtility.CANONICAL_EVENT_TYPE_ID_Deleted))
                        ownersMap.put(rs.getString(1), rs.getString(2));
                }

                // while (rs.next()) {
                // ownersMap.put(rs.getString(1), rs.getString(2));
                // }
            }
        }

        return ownersMap;
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException"), e);
        throw new RegistryException(e);
    } finally {
        if (stmt != null) {
            closeStatement(stmt);
        }

        if (resultSets != null) {
            Iterator<?> resultsSetsIter = resultSets.iterator();
            while (resultsSetsIter.hasNext()) {
                try {
                    ResultSet rs = (ResultSet) resultsSetsIter.next();
                    Statement stmt2 = rs.getStatement();
                    closeStatement(stmt2);
                } catch (SQLException e) {
                    log.error(e, e);
                }
            }
        }
    }
}

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

/**
 * Update the status of specified objects (homogenous collection) to the
 * specified status.// w  ww  .j av a 2 s  . co  m
 * 
 * @param statusUnchanged
 *            if an id in registryObjectIds is in this ArrayList, no
 *            AuditableEvent generated for that RegistryObject
 */
public void updateStatus(RegistryObjectType ro, String status) throws RegistryException {
    Statement stmt = null;

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

        String str = "UPDATE " + getTableName() + " SET status = '" + status + "' WHERE id = '" + ro.getId()
                + "'";

        log.trace("stmt = " + str);
        stmt.execute(str);
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }
}