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:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * Gets objects based upon parent set for this DAO
 *
 *//*from  w w  w .  j  a va 2  s .  c  o  m*/
public List getByParent() throws RegistryException {
    List objects = new ArrayList();
    PreparedStatement stmt = null;
    try {
        String sql = "SELECT * FROM " + getTableName() + " WHERE " + getParentAttribute() + " = ? ";
        stmt = context.getConnection().prepareStatement(sql);
        stmt.setString(1, getParentId());
        log.trace("SQL = " + sql); // HIEOS/BHT: (DEBUG)
        ResultSet rs = stmt.executeQuery();

        objects = getObjects(rs, 0, -1);
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (JAXRException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } finally {
        closeStatement(stmt);
    }

    return objects;
}

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * @see org.freebxml.omar.server.persistence.rdb.OMARDAO#insert(org.oasis.ebxml.registry.bindings.rim.UserType, java.sql.Connection, java.util.List, java.util.HashMap)
 *///from  w ww  .j a v a2  s.c  o m
public void insert(List objects) throws RegistryException {
    //Return immediatley if no objects to insert
    if (objects.size() == 0) {
        return;
    }

    //First process any objects that may already exists in persistence layer
    // BHT: OPTIMIZE ME!!!!!!!!!!!!!
    objects = processExistingObjects(objects);

    //Return immediately if no objects to insert
    if (objects.size() == 0) {
        return;
    }

    log.trace(ServerResourceBundle.getInstance().getString("message.InsertingRowsInTable",
            new Object[] { new Integer(objects.size()), getTableName() }));
    action = DAO_ACTION_INSERT;

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

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

            String str = getSQLStatementFragment(obj);
            log.trace("SQL = " + str);
            stmt.addBatch(str);

            // HIEOS/BHT (Added block to get rid of MySQL performance bug with DB views).
            String mirrorImageStr = this.getSQLStatementFragmentForMirrorImage(obj);
            if (mirrorImageStr != null) {
                log.trace("SQL = " + mirrorImageStr); // HIEOS/BHT (DEBUG)
                stmt.addBatch(mirrorImageStr); // Now, insert into the mirror.
            }

            prepareToInsert(obj);
        }
        long startTime = System.currentTimeMillis();
        log.trace("AbstractDAO.insert: doing executeBatch");
        int[] updateCounts = stmt.executeBatch();
        long endTime = System.currentTimeMillis();
        log.trace("AbstractDAO.insert: done executeBatch elapedTimeMillis=" + (endTime - startTime));
        iter = objects.iterator();
        while (iter.hasNext()) {
            Object obj = iter.next();
            onInsert(obj);
        }

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

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * @see org.freebxml.omar.server.persistence.rdb.OMARDAO#update(org.oasis.ebxml.registry.bindings.rim.UserType, java.sql.Connection, java.util.List, java.util.HashMap)
 *//*from  ww w.  j  a v  a2s .  c  o  m*/
public void update(List objects) throws RegistryException {

    //Return immediatley if no objects to insert
    if (objects.size() == 0) {
        return;
    }

    log.trace(ServerResourceBundle.getInstance().getString("message.UpdatingRowsInTable",
            new Object[] { new Integer(objects.size()), getTableName() }));
    action = DAO_ACTION_UPDATE;

    Statement stmt = null;

    try {
        stmt = context.getConnection().createStatement();
        Iterator iter = objects.iterator();
        while (iter.hasNext()) {
            Object obj = iter.next();

            prepareToUpdate(obj);

            String str = getSQLStatementFragment(obj);
            log.trace("SQL = " + str);
            stmt.addBatch(str);

            // HIEOS/BHT (Added block to get rid of MySQL performance bug with DB views).
            String mirrorImageStr = this.getSQLStatementFragmentForMirrorImage(obj);
            if (mirrorImageStr != null) {
                log.trace("SQL = " + mirrorImageStr); // HIEOS/BHT (DEBUG)
                stmt.addBatch(mirrorImageStr); // Now, update the mirror.
            }
        }

        int[] updateCounts = stmt.executeBatch();

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

            onUpdate(obj);
        }

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

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * Return the id for the repository item used to hold information that
 * could not fit in a db column and therefor "spilled over" into a repository item.
 * The returned id is then stored instead of the content that "spilled over" into 
 * the repository item.//from  ww  w . j a v a 2s  .  co m
 *
 * @param parentId the id of the parent object whose column data is being "spilled over"
 * @param columnInfo contains information on the table and column whose data is being spilledOver. Format SHOULD be tableName:columnName)
 *
 * @return the id of the "spill over" repository item
 */
String getSpillOverRepositoryItemId(String parentId, String columnInfo) throws RegistryException {
    String spillOverId = null;
    if ((columnInfo == null) || (columnInfo.length() == 0)) {
        throw new RegistryException(
                ServerResourceBundle.getInstance().getString("message.error.columnInfoUnspecified"));
    } else if (!columnInfo.endsWith(":")) {
        columnInfo += ":";
    }

    spillOverId = "urn:freebxml:registry:spillOverId:" + columnInfo + parentId;

    if (!org.freebxml.omar.common.Utility.getInstance().isValidRegistryId(spillOverId)) {
        throw new RegistryException(ServerResourceBundle.getInstance()
                .getString("message.error.spillOverIdTooLong", new Object[] { parentId }));
    }

    return spillOverId;
}

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * Saves content of a db column to an ExtrinsicObject / RepositoryItem pair.
 *
 * TODO: /* w  w w.jav  a2  s  . c  o m*/
 *
 * Need to enforce referencial integrity by deleting spillover EO/RI when parent is deleted.
 * This should be done as part of the fix to prevent deletions when there are existing references
 * by treating spillover objects as if they are referenced by their parent.      
 *
 * @param parentId the id of the parent object whose column data is being "spilled over"
 * @param columnInfo contains information on the table and column whose data is being spilledOver. Format SHOULD be tableName:columnName)
 * @param columnData contains the column data being "spilled over" into RepositoryItem
 *
 * @return the id of the "spill over" repository item
 */
protected String marshalToRepositoryItem(String parentId, String columnInfo, String columnData)
        throws RegistryException {

    String spillOverId = getSpillOverRepositoryItemId(parentId, columnInfo);

    try {
        ExtrinsicObject eo = bu.rimFac.createExtrinsicObject();
        eo.setId(spillOverId);
        eo.setLid(spillOverId);
        eo.setMimeType("text/plain");

        VersionInfoType versionInfo = bu.rimFac.createVersionInfoType();
        versionInfo.setVersionName("1.1");
        eo.setVersionInfo(versionInfo);
        eo.setContentVersionInfo(versionInfo);

        ExtrinsicObjectDAO extrinsicObjectDAO = new ExtrinsicObjectDAO(context);

        //Delete any previous eo and ri
        removeSpillOverRepositoryItem(parentId, columnInfo);

        RepositoryItem ri = org.freebxml.omar.common.Utility.getInstance().createRepositoryItem(spillOverId,
                columnData);

        //Insert the extrinsic objects

        //Need to place ri in RepositoryItemsMap otherwise ExtrinsicObjectDAO will not set contentVersionInfo.versionName
        context.getRepositoryItemsMap().put(spillOverId, ri);
        ArrayList extrinsicObjects = new ArrayList();
        extrinsicObjects.add(eo);
        extrinsicObjectDAO.insert(extrinsicObjects);

        //Inserting the repository item
        rm.insert(((ServerRequestContext) context), ri);

        //Remove ri from RepositoryItemsMap to otherwise it will create problems in lcm.submitObjects wrapUp
        context.getRepositoryItemsMap().remove(spillOverId);
    } catch (RegistryException e) {
        throw e;
    } catch (Exception e) {
        throw new RegistryException(e);
    }

    return spillOverId;
}

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * Remove specified spillover ExtrinsicObject and ReositoryItem.
 *//*w ww .ja v  a2 s.c o m*/
protected void removeSpillOverRepositoryItem(String parentId, String columnInfo) throws RegistryException {
    String spillOverId = getSpillOverRepositoryItemId(parentId, columnInfo);

    try {
        ExtrinsicObject eo = bu.rimFac.createExtrinsicObject();
        eo.setId(spillOverId);
        eo.setLid(spillOverId);
        eo.setMimeType("text/plain");

        VersionInfoType versionInfo = bu.rimFac.createVersionInfoType();
        versionInfo.setVersionName("1.1");
        eo.setVersionInfo(versionInfo);
        eo.setContentVersionInfo(versionInfo);

        ExtrinsicObjectDAO extrinsicObjectDAO = new ExtrinsicObjectDAO(context);

        //Delete any previous copy
        try {
            //Delete existing eo and ri
            rm.delete(spillOverId);
        } catch (ObjectNotFoundException e) {
            //Also catches RepositoryItemNotFoundException
            //Does not exist. All is well
        }

        try {
            //Delete existing eo and ri
            extrinsicObjectDAO.delete(Collections.singletonList(eo));
        } catch (ObjectNotFoundException e) {
            //Does not exist. All is well
        }
    } catch (JAXBException e) {
        throw new RegistryException(e);
    }
}

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * Unmarshalls a "spilled over" RepositoryItem into a String
 *
 * @param spillOverId the id of the ExtrinsicObject associated with the RepositoryItem 
 * used to unmarshal the "spilled over" content from.
 *//*from w  w  w  .j  a  va 2 s  .co m*/
public String unmarshallFromRepositoryItem(String spillOverId) throws RegistryException {
    String content = spillOverId;

    InputStream is = null;
    try {
        RepositoryItem ri = rm.getRepositoryItem(spillOverId);

        content = org.freebxml.omar.common.Utility.getInstance()
                .unmarshalInputStreamToString(ri.getDataHandler().getInputStream());
    } catch (IOException e) {
        throw new RegistryException(e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                log.error(e, e);
            }
        }
    }

    return content;
}

From source file:org.freebxml.omar.server.persistence.rdb.AbstractDAO.java

/**
 * Executes a Select statment that has an IN clause while
 * taking care to execute it in chunks to avoid scalability limits
 * in some databases (Oracle 10g limits terms in IN clause to 1000)
 *
 * Note: Caller is responsible for closing statement associated with each resultSet
 * in resultSets. // ww w.  ja va  2 s.c  o  m
 *
 * @param selectStmtTemplate a string representing the SELECT statment in a parameterized format consistent withebRR parameterized queries.
 * @return a List of Objects
 */
public List executeBufferedSelectWithINClause(String selectStmtTemplate, List terms, int termLimit)
        throws RegistryException {
    List resultSets = new ArrayList();

    if (terms.size() == 0) {
        return resultSets;
    }

    Iterator iter = terms.iterator();

    try {
        //We need to count the number of terms in "IN" list. 
        //We need to split the SQL Strings into chunks if there are too many terms. 
        //Reason is that some database such as Oracle, do not allow the IN list is too long
        int termCounter = 0;

        StringBuffer inTerms = new StringBuffer();
        while (iter.hasNext()) {
            String term = (String) iter.next();

            if (iter.hasNext() && (termCounter < termLimit)) {
                inTerms.append("'" + term + "',");
            } else {
                inTerms.append("'" + term + "' ");
                String sql = selectStmtTemplate.replaceAll("\\$InClauseTerms", inTerms.toString());

                Statement stmt = context.getConnection().createStatement();
                log.trace("SQL = " + sql); // HIEOS/BHT: (DEBUG)
                ResultSet rs = stmt.executeQuery(sql);
                resultSets.add(rs);

                termCounter = 0;
                inTerms = new StringBuffer();
            }

            termCounter++;
        }

    } catch (SQLException e) {
        throw new RegistryException(e);
    } finally {
        //Do not close stmt as that will close resultSet. Caller needs to do this after reading resultSets.
    }

    return resultSets;
}

From source file:org.freebxml.omar.server.persistence.rdb.AdhocQueryDAO.java

protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    try {/*from  w  ww.  ja  v  a 2 s.c  o m*/
        //TODO: Add support for filter query type later
        if (!(obj instanceof AdhocQuery)) {
            throw new RegistryException(ServerResourceBundle.getInstance().getString("message.SQLQueryExpected",
                    new Object[] { obj }));
        }

        AdhocQuery ahq = (AdhocQuery) obj;
        super.loadObject(obj, rs);

        String query = rs.getString("query");

        //Check if query is actually a ref to a query stored in a repository item 
        //If so we needs to dereference it to get actual query string
        if (query.startsWith("urn:freebxml:registry:spillOverId:")) {
            //query is actually in a repository item and this is just the id of that repository item
            //Fetch the actual query by dereferencing this id

            try {
                query = unmarshallFromRepositoryItem(query);

                //We escape single quotes in the query with another single quote when storing as VARCHAR. 
                //JDBC strips the first single quote on read from VARCHAR column
                //When reading from content of a RepositoryItem replace "''" with "'"
                query = query.replaceAll("''", "'");

            } catch (Exception e) {
                //throw new RegistryException(e);
                log.error(e, e);
            }
        }

        String queryLang = rs.getString("queryLanguage");

        QueryExpressionType queryExp = bu.rimFac.createQueryExpression();
        queryExp.setQueryLanguage(queryLang);
        queryExp.getContent().add(query);
        ahq.setQueryExpression(queryExp);
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (JAXBException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    }
}

From source file:org.freebxml.omar.server.persistence.rdb.AssociationDAO.java

protected void loadObject(Object obj, ResultSet rs) throws RegistryException {
    try {/*from  w  w  w . j a  v a  2s .c o m*/
        if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.Association)) {
            throw new RegistryException(ServerResourceBundle.getInstance()
                    .getString("message.AssociationExpected", new Object[] { obj }));
        }

        Association ass = (Association) obj;

        super.loadObject(ass, rs);

        String associationType = rs.getString("associationType");
        ass.setAssociationType(associationType);

        String sourceObjectId = rs.getString("sourceObject");

        ObjectRef so = bu.rimFac.createObjectRef();
        so.setId(sourceObjectId);
        context.getObjectRefs().add(so);
        ass.setSourceObject(sourceObjectId);

        String targetObjectId = rs.getString("targetObject");
        ObjectRef to = bu.rimFac.createObjectRef();
        to.setId(targetObjectId);
        context.getObjectRefs().add(to);
        ass.setTargetObject(targetObjectId);
    } catch (SQLException e) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e);
        throw new RegistryException(e);
    } catch (JAXBException j) {
        log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), j);
        throw new RegistryException(j);
    }
}