Search in sources :

Example 1 with ManagementException

use of org.apache.ode.bpel.pmapi.ManagementException in project carbon-business-process by wso2.

the class Utils method getInstanceCountForProcess.

/**
 * Return the instances in the given processes list
 *
 * @param processesInPackage
 * @return Instance count
 * @throws ManagementException
 */
public static long getInstanceCountForProcess(List<QName> processesInPackage) throws ManagementException {
    if (processesInPackage != null) {
        String filter = null;
        for (QName q : processesInPackage) {
            if (filter == null) {
                filter = "pid=" + q.toString();
            } else {
                filter += "|" + q.toString();
            }
        }
        try {
            final InstanceFilter instanceFilter = new InstanceFilter(filter);
            long count = (long) dbexec(new BpelDatabase.Callable<Object>() {

                public Object run(BpelDAOConnection conn) {
                    return conn.instanceCount(instanceFilter);
                }
            });
            return count;
        } catch (Exception e) {
            String errMsg = "Exception during instance count for deletion. Filter: " + filter;
            throw new ManagementException(errMsg, e);
        }
    } else {
        return 0;
    }
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) QName(javax.xml.namespace.QName) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with ManagementException

use of org.apache.ode.bpel.pmapi.ManagementException in project carbon-business-process by wso2.

the class Utils method dbexec.

/**
 * Execute a database transaction, unwrapping nested
 * {@link org.apache.ode.bpel.pmapi.ManagementException}s.
 *
 * @param callable action to run
 * @return object of type T
 * @throws org.apache.ode.bpel.pmapi.ManagementException if exception occurred during transaction
 */
private static <T> T dbexec(BpelDatabase.Callable<T> callable) throws ManagementException {
    try {
        BPELServerImpl bpelServer = (BPELServerImpl) BPELServiceComponent.getBPELServer();
        BpelDatabase bpelDb = bpelServer.getODEBPELServer().getBpelDb();
        return bpelDb.exec(callable);
    } catch (ManagementException me) {
        // Passthrough.
        throw me;
    } catch (Exception ex) {
        log.error("Exception during database operation", ex);
        throw new ManagementException("Exception during database operation", ex);
    }
}
Also used : ManagementException(org.apache.ode.bpel.pmapi.ManagementException) BPELServerImpl(org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with ManagementException

use of org.apache.ode.bpel.pmapi.ManagementException in project carbon-business-process by wso2.

the class Utils method delete.

public static List<Long> delete(String filter) {
    log.info("Instance filter for instance deletion:" + filter);
    final InstanceFilter instanceFilter = new InstanceFilter(filter);
    final List<Long> ret = new LinkedList<Long>();
    try {
        dbexec(new BpelDatabase.Callable<Object>() {

            public Object run(BpelDAOConnection conn) {
                Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter);
                for (ProcessInstanceDAO instance : instances) {
                    instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class), true);
                    ret.add(instance.getInstanceId());
                }
                return null;
            }
        });
    } catch (Exception e) {
        String errMsg = "Exception during instance deletion. Filter: " + filter;
        log.error(errMsg, e);
        throw new ManagementException(errMsg, e);
    }
    return ret;
}
Also used : InstanceFilter(org.apache.ode.bpel.common.InstanceFilter) BpelDatabase(org.apache.ode.bpel.engine.BpelDatabase) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) BpelDAOConnection(org.apache.ode.bpel.dao.BpelDAOConnection) LinkedList(java.util.LinkedList) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ManagementException(org.apache.ode.bpel.pmapi.ManagementException) ProcessInstanceDAO(org.apache.ode.bpel.dao.ProcessInstanceDAO) Collection(java.util.Collection)

Aggregations

IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ManagementException (org.apache.ode.bpel.pmapi.ManagementException)3 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)2 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)2 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)2 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)1 ProcessConf (org.apache.ode.bpel.iapi.ProcessConf)1 BPELServerImpl (org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl)1