//* IBM Business Process Choreographer Java API Bean - Sample Application * //* * //* "This sample program is provided AS IS and may be used, executed, copied * //* and modified without royalty payment by customer * //* (a) for its own instruction and study, * //* (b) in order to develop applications designed to run with an * //* IBM WebSphere product, either for customer's own internal use or for * //* redistribution by customer, as part of such an application, in * //* customer's own products." * //* * //* Product 5655-FLW, * //* (C) COPYRIGHT International Business Machines Corp., 2006, 2009 * //* All Rights Reserved * Licensed Materials - Property of IBM * //* * //***************************************************************************** //* * //* DISCLAIMER * //* * //* This material contains programming source code for your consideration. * //* These examples have not been thoroughly tested under all conditions. * //* IBM, therefore, cannot guarantee or imply reliability, serviceability, * //* or function of these programs. * //* ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY * //* WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT * //* NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS * //* FOR A PARTICULAR PURPOSE. * //* * //***************************************************************************** /* * This samples shows how to handle stored queries. * - It creates a stored query, i.e. it stores a query, which consists * of a selectClause, whereClaus, and orderClause and a threshold, * in the database. The query is identified by its name. * - It retrieve the stored query * - It executes the stored query * - It deletes the stored query. * To create and delete a stored query you have to be the system administrator * */ import com.ibm.bpe.api.*; public class HandleStoredQueries { public static void main(String[] args) { try { // initialize context and access the remote interface for the // BusinessFlowManager bean BusinessFlowManager bfm = ApiHelper.initializeBFM(); // you can retrieve the stored queries calling getStoredQueryNames() String[] storedQueryNames = bfm.getStoredQueryNames(); if( storedQueryNames.length > 0 ) { System.out.println(" > Available stored queries: "); for( int i = 0; i < storedQueryNames.length; i++ ) { System.out.println(" > " + storedQueryNames[i]); } } String storedQueryName = "Ready/running processes"; String processTemplateName = "OrderApprovalProcess"; // in case there is already a stored query with name 'Ready/running processes' // delete it to avoid duplicate names bfm.deleteStoredQuery( storedQueryName ); // set the parameters that define a new stored query String selectClause = "DISTINCT PROCESS_INSTANCE.PIID, PROCESS_INSTANCE.NAME, PROCESS_INSTANCE.STATE, PROCESS_TEMPLATE.NAME "; String whereClause = "PROCESS_INSTANCE.STATE IN ( PROCESS_INSTANCE.STATE.STATE_READY, PROCESS_INSTANCE.STATE.STATE_RUNNING ) AND " + "PROCESS_TEMPLATE.NAME = '" + processTemplateName + "'"; String orderClause = "PROCESS_INSTANCE.NAME"; Integer threshold = new Integer(10); // Store the query in the database bfm.createStoredQuery( storedQueryName, selectClause, whereClause, orderClause, threshold, null); System.out.println( "\n > storedQuery: '" + storedQueryName + "' stored in DB "); // retrieve the definition of the stored query from the database StoredQueryData query = bfm.getStoredQuery( storedQueryName ); MyTrace.trace(query,"StoredQuery '" + storedQueryName + "' retrieved from DB"); // execute the stored query Integer skipTuples = new Integer(0); QueryResultSet result = bfm.query( storedQueryName , skipTuples , (java.util.List)null ); System.out.println( "\n > query(), result size: " + result.size()); if (result != null && result.size() > 0 && result.first()) { do { MyTrace.trace( (PIID)result.getOID(1), "process instance retrieved", bfm ); } while (result.next()); } // retrieve the next 10 tuples that qualify skipTuples = new Integer(10); result = bfm.query( storedQueryName, skipTuples , (java.util.List)null ); if (result != null && result.size() > 0 && result.first()) { do { System.out.println( result.getOID(1) + ", " + result.getString(2) + ", " + result.getString(3) + ", " + result.getInteger(4)); } while (result.next()); } // delete the stored query from the database bfm.deleteStoredQuery( storedQueryName ); System.out.println("\n > successfully processed.\n" ); System.exit(0); } catch ( com.ibm.bpe.api.ProcessException xcpt) { System.out.println(" " + xcpt.getMessage()); } catch (java.lang.Exception xcpt ) { System.out.println( xcpt ); } catch (Throwable xcpt ) { System.out.println( xcpt ); } finally { System.exit(0); } } }