Source Code Cross Referenced for GenericDB2WorkflowLifecycleBean.java in  » Workflow-Engines » JFolder » org » jfolder » workflow » lifecycle » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » JFolder » org.jfolder.workflow.lifecycle 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


        /*
         * JFolder, Copyright 2001-2006 Gary Steinmetz
         *
         * Distributable under LGPL license.
         * See terms of license at gnu.org.
         */

        package org.jfolder.workflow.lifecycle;

        //base classes
        import java.io.ByteArrayInputStream;
        import java.io.ByteArrayOutputStream;
        import java.io.File;
        import java.io.FileInputStream;
        import java.io.FileNotFoundException;
        import java.io.FileOutputStream;
        import java.io.IOException;
        import java.io.InputStream;
        import java.io.ObjectInputStream;
        import java.io.ObjectOutputStream;
        import java.io.PrintWriter;
        import java.io.Reader;
        import java.io.StringReader;
        import java.io.StringWriter;
        import java.math.BigDecimal;
        import java.sql.CallableStatement;
        import java.sql.Connection;
        import java.sql.DriverManager;
        import java.sql.PreparedStatement;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.sql.Timestamp;
        import java.sql.Types;
        import java.util.ArrayList;
        import java.util.Collection;
        import java.util.Date;
        import java.util.Enumeration;
        import java.util.HashMap;
        import java.util.Iterator;
        import java.util.Properties;
        import java.util.StringTokenizer;
        import javax.naming.Context;
        import javax.naming.InitialContext;
        import javax.naming.NamingException;
        import javax.rmi.PortableRemoteObject;
        import javax.sql.DataSource;
        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.ParserConfigurationException;
        import org.w3c.dom.Document;
        import org.w3c.dom.Element;
        import org.w3c.dom.NodeList;
        import org.xml.sax.InputSource;
        import org.xml.sax.SAXException;

        //project specific classes
        import org.jfolder.common.UnexpectedSystemException;
        import org.jfolder.common.tagging.ValueAndClassForConceptTag;
        import org.jfolder.common.utils.misc.MiscHelper;
        import org.jfolder.common.utils.xml.XMLHelper;
        import org.jfolder.workflow.model.attributes.AttributeSet;
        import org.jfolder.workflow.model.attributes.WaitHelper;
        import org.jfolder.workflow.model.trigger.WorkflowTrigger;
        import org.jfolder.workflow.query.BaseDBQueryVendor;
        import org.jfolder.workflow.query.ColumnContainer;
        import org.jfolder.workflow.query.QueryContainer;
        import org.jfolder.workflow.query.ResultSetContainer;
        import org.jfolder.workflow.query.StatementContainer;
        import org.jfolder.workflow.query.SysDecIsGreaterThanOrEqualQC;

        //other classes

        /*
         //TO DO: make calls transactional where appropriate
         public class GenericDB2WorkflowLifecycleBean
         implements WorkflowLifecycle, SessionBean {
        
         private SessionContext sessionContext = null;
        
         public GenericDB2WorkflowLifecycleBean() {
         }
        
         public void close() {
         //not implemented, included in WorkflowLifecycle, not used
         }
        
         //TO DO: determine good function name and return type
         //TO DO: is there a regular expressions library
         //TO DO: determine if returning list of string ID's is okay
         //TO DO: determine what should be returned in a query
         //TO DO: determine what return will work with messaging and database
        
         //TO DO: determine good function name and return type
         //TO DO: determine if returning list of string ID's is okay
         //TO DO: determine what should be returned in a query
         //TO DO: determine what return will work with messaging and database
         public ResultSetContainer queryWorkflows(StatementContainer inStatement) {
        
         try {
         ResultSetContainer outValue = null;
        
         Connection con = getDatabaseConnection();
        
         DB2QueryVendorProprietarySyntax oqvps =
         new DB2QueryVendorProprietarySyntax();
         BaseDBQueryVendor bdbqv = BaseDBQueryVendor.newBaseDBQueryVendor(
         oqvps, true);
        
         outValue = bdbqv.executeStatement(con, inStatement);
        
         con.close();
         return outValue;
        
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         }
        
         public void startWorkflow(WorkflowPrecursor inWp) {
        
         try {
        
         Connection con = getDatabaseConnection();
        
         AttributeSet as = inWp.getAttributeSet();
         Trigger t = inWp.getTrigger();
         RootScriptTagHolder rth = inWp.getRootScriptTagHolder();
         History h = inWp.getHistory();
        
         BigDecimal pfId = getNextIndex(con);
        
         //this is the only attribute added in this function
         as.addPublicSysAttr(AttributeSet.ID,
         ValueAndClassFactory.newValueAndClass(pfId, BigDecimal.class));
        
        
         insertWorkflowInstance(con, pfId,
         WorkflowFactory.newWorkflow(inWp));
         storeWorkflowAttributes(con, pfId, as, true);
        
         con.close();
        
         //send message to queue
         QueueConnectionFactory queueFactory =
         getWorkflowQueueConnectionFactory();
         QueueConnection queueConnection =
         queueFactory.createQueueConnection();
         Queue queue = getWorkflowQueue();
         QueueSession queueSession =
         queueConnection.createQueueSession(false,
         Session.AUTO_ACKNOWLEDGE);
         QueueSender sender = queueSession.createSender(queue);
         queueConnection.start();
         ObjectMessage message = queueSession.createObjectMessage();
         message.setObject(pfId);
         sender.send(message);
         queueConnection.close();
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         catch (JMSException jmse) {
         throw new UnexpectedSystemException(jmse);
         }
        
         }
        
         public void updateWorkflow(Workflow inWorkflow) {
        
         try {
         AttributeSet as = inWorkflow.getAttributeSet();
         ValueAndClass idVac = as.getPublicSysAttr(AttributeSet.ID);
         ValueAndClass statusVac = as.getPublicSysAttr(AttributeSet.STATUS);
        
         BigDecimal id = (BigDecimal)idVac.getValue();
         String status = (String)statusVac.getValue();
        
         String workflowText =
         VersionHelper.createXMLRepresentationOfWorkflow(inWorkflow);
        
         Connection con = getDatabaseConnection();
        
         PreparedStatement ps = con.prepareStatement(
         "update pf_workflows set wf_instance = ? where id = ?");
        
         ps.setCharacterStream(1, new StringReader(workflowText),
         workflowText.length());
         ps.setBigDecimal(2, id);
        
         ps.execute();
         ps.close();
        
         storeWorkflowAttributes(con, id, as, false);
        
         //con.commit();//TO DO: remove this
         con.close();
        
         if (status.equals(Trace.STATUS_ACTIVE)) {
         QueueConnectionFactory queueFactory =
         getWorkflowQueueConnectionFactory();
         QueueConnection queueConnection =
         queueFactory.createQueueConnection();
         Queue queue = getWorkflowQueue();
         QueueSession queueSession =
         queueConnection.createQueueSession(false,
         Session.AUTO_ACKNOWLEDGE);
         QueueSender sender = queueSession.createSender(queue);
         queueConnection.start();
         ObjectMessage message = queueSession.createObjectMessage();
         message.setObject(id);
         sender.send(message);
         queueConnection.close();
         }
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         catch (JMSException jmse) {
         throw new UnexpectedSystemException(jmse);
         }
        
        
         ////TO DO: should this function return anything?
         ////TO DO: in the end, is this necessary? consider SYS_STATUS
         //Iterator attributeNames = as.getPublicAttrNames();
         //
         //HashMap properties = new HashMap();
         //while (attributeNames.hasNext()) {
         //    String aName = (String)attributeNames.next();
         //    properties.put(aName, as.getPublicAttr(aName).getValue());
         //}
         //
         ////Workflow workflow = WorkflowFactory.newWorkflow(h, inRth, as, t);
         //ServerFunctions sf =
         //    ServerFunctionsFactory.createNewServerFunctionsInstance();
         //
         //String wString =
         //    VersionHelper.createXMLRepresentationOfWorkflow(inWorkflow);
         //sf.sendTextMessageToQueue("queue/WorkflowMDB", wString, properties);
        
         }
        
         public WorkflowScript[] getDeployedScripts() {
        
         Connection con = null;
         PreparedStatement ps = null;
         ResultSet rs = null;
        
         try {
         WorkflowScript outValue[] = null;
        
         ConfigManager cm = ConfigManagerFactory.getConfigManager();
        
         File pfDir =
         GenericFileWorkflowApplicationSet.getJFolderDirectory(cm);
         File scriptsDir = new File(pfDir, "scripts");
        
         con = getDatabaseConnection();
        
         ps = con.prepareStatement(
         "select script_name from pf_deployed_scripts order by id");
         rs = ps.executeQuery();
         ArrayList scriptList = new ArrayList();
         while (rs.next()) {
         String nextScript = rs.getString(1);
         File nextScriptFile = new File(scriptsDir, nextScript + ".xml");
         if (nextScriptFile.exists()) {
         scriptList.add(nextScriptFile);
         }
         }
        
         outValue = new WorkflowScript[scriptList.size()];
         for (int i = 0; i < scriptList.size(); i++) {
         File nextFile = (File)scriptList.get(i);
         String nextName =
         MiscHelper.removeFileExtension(nextFile.getName());
         outValue[i] = new GenericFileWorkflowScript(nextFile, nextName);
         }
        
         cm.close();
        
         return outValue;
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         finally {
         try {
         if (rs != null) {
         rs.close();
         }
         if (ps != null) {
         ps.close();
         }
         if (con != null) {
         con.close();
         }
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         }
        
         }
        
         public void setDeployedScripts(WorkflowScript inWs[]) {
        
         Connection con = null;
         PreparedStatement ps = null;
        
         try {
         ConfigManager cm = ConfigManagerFactory.getConfigManager();
        
         //delete existing deployed files
         File pfDir =
         GenericFileWorkflowApplicationSet.getJFolderDirectory(cm);
         File scriptsDir = new File(pfDir, "scripts");
         if (!scriptsDir.exists()) {
         scriptsDir.mkdirs();
         }
         File deployedScripts[] = scriptsDir.listFiles();
         for (int i = 0; i < deployedScripts.length; i++) {
         if (deployedScripts[i].isFile()
         && deployedScripts[i].getName().endsWith(".xml")) {
         deployedScripts[i].delete();
         }
         }
         con = getDatabaseConnection();
         ps = con.prepareStatement("delete from pf_deployed_scripts");
         ps.execute();
         ps.close();
        
         //create new deployed files
         for (int i = 0; i < inWs.length; i++) {
        
         WorkflowScript nextScript = inWs[i];
        
         File nextScriptFile = new File(scriptsDir,
         nextScript.getName() + ".xml");
        
         MiscHelper.writeTextFile(nextScriptFile,
         nextScript.getContent());
        
         BigDecimal id = getNextIndex(con);
        
         ps = con.prepareStatement(
         "insert into pf_deployed_scripts "
         + "(id, script_name)  values (?,?)");
         ps.setBigDecimal(1, id);
         ps.setString(2, nextScript.getName());
         ps.execute();
         }
        
         cm.close();
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         finally {
         try {
         if (ps != null) {
         ps.close();
         }
         if (con != null) {
         con.close();
         }
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         }
         }
        
         public WorkflowApplicationSet getWorkflowApplicationSet(UserHolder inUh) {
        
         GenericFileWorkflowApplicationSet outValue =
         new GenericFileWorkflowApplicationSet(
         getApplicationsDirectory(inUh));
        
         //MiscHelper.println(
         //    "getWorkflowApplicationSet::getApplicationsDirectory(inUh) = "
         //    + getApplicationsDirectory(inUh).getAbsolutePath());
        
         File appList[] = getApplicationsDirectory(inUh).listFiles();
         for (int i = 0; i < appList.length; i++) {
         if (appList[i].isDirectory()) {
         GenericFileWorkflowApplication nextWa =
         new GenericFileWorkflowApplication(appList[i]);
         outValue.registerApplication(nextWa);
         }
         }
        
         outValue.load();
        
         return outValue;
         }
        
         public void setWorkflowApplicationSet(WorkflowApplicationSet inWas,
         UserHolder inUh) {
        
         //reset deployed applications
         File appList[] = getApplicationsDirectory(inUh).listFiles();
         for (int i = 0; i < appList.length; i++) {
         MiscHelper.deleteFileOrDirectory(appList[i]);
         }
        
         ((GenericFileWorkflowApplicationSet)inWas).store();
         }
        
         protected final static File getApplicationsDirectory(UserHolder inUh) {
        
         File outValue = null;
        
         ConfigManager cm = ConfigManagerFactory.getConfigManager();
        
         File pfDir =
         GenericFileWorkflowApplicationSet.getJFolderDirectory(cm);
         File usersDir = new File(pfDir, "users");
         if (!usersDir.exists()) {
         usersDir.mkdirs();
         }
        
         int id = getFileIdOfUser(inUh);
         File userDir = new File(usersDir, id + "");
         if (!userDir.exists()) {
         userDir.mkdirs();
         }
        
         outValue = new File(userDir, "applications");
         if (!outValue.exists()) {
         outValue.mkdirs();
         }
        
         cm.close();
        
         return outValue;
         }
        
         private final static int getFileIdOfUser(UserHolder inUh) {
        
         Connection con = null;
         PreparedStatement ps = null;
         ResultSet rs = null;
         PreparedStatement ps2 = null;
         //ResultSet rs2 = null;
         //PreparedStatement ps3 = null;
         //ResultSet rs3 = null;
        
         try {
         int outValue = 0;
        
         String name = inUh.getName();
         String securityClass = inUh.getSecurityClass();
        
         //check if id is already present
         con = getDatabaseConnection();
         ps = con.prepareStatement(
         "select id from pf_users "
         + "where user_name = ? and security_class = ?");
         ps.setString(1, name);
         ps.setString(2, securityClass);
         rs = ps.executeQuery();
        
         //get id
         if (rs.next()) {
         outValue = rs.getInt(1);
         }
         else {
         //insert user into
         outValue = getNextIndex(con).intValue();
         ps2 = con.prepareStatement("insert into pf_users "
         + "(id, user_name, security_class) values (?,?,?)");
         ps2.setInt(1, outValue);
         ps2.setString(2, name);
         ps2.setString(3, securityClass);
         ps2.execute();
        
         //get user id
         //ps3 = con.prepareStatement("CALL IDENTITY()");
         //rs3 = ps3.executeQuery();
         //rs3 = ps2.executeQuery("CALL IDENTITY()");
         //while (rs3.next()) {
         //    outValue = rs3.getInt(1);
         //}
         }
        
         return outValue;
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         finally {
         try {
         if (rs != null) {
         rs.close();
         }
         if (ps != null) {
         ps.close();
         }
         //if (rs2 != null) {
         //    rs.close();
         //}
         if (ps2 != null) {
         ps.close();
         }
         //if (rs3 != null) {
         //    rs.close();
         //}
         //if (ps3 != null) {
         //    ps.close();
         //}
         if (con != null) {
         con.close();
         }
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         }
         }
        
         public Workflow retrieveWorkflow(Serializable inHandle) {
        
         try {
         Workflow outValue = null;
        
         //MiscHelper.println("HANDLE = " + inHandle);
         //MiscHelper.println("handle(type) = "
         //    + inHandle.getClass().getName());
        
         BigDecimal id = null;
         if (inHandle instanceof BigDecimal) {
         id = (BigDecimal)inHandle;
         }
         else {
         throw new UnexpectedSystemException(
         "Handle is not a BigDecimal");
         }
        
         Connection con = getDatabaseConnection();
        
         PreparedStatement ps = con.prepareStatement(
         "select wf_instance from pf_workflows where id = ?");
         ps.setBigDecimal(1, id);
         ps.execute();
        
         ResultSet rs = ps.getResultSet();
         if (rs.next()) {
         Reader r = rs.getCharacterStream(1);
         StringBuffer sb = new StringBuffer();
         int nextChar = -1;
         while ((nextChar = r.read()) != -1) {
         sb.append(((char)nextChar));
         }
         outValue = VersionHelper.createWorkflowFromXMLRepresentation(
         sb.toString());
         }
         else {
         throw new UnexpectedSystemException(
         "No workflow-instance found with id '" + id + "'");
         }
        
         rs.close();
         ps.close();
         con.close();
        
         return outValue;
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         catch (IOException ioe) {
         throw new UnexpectedSystemException(ioe);
         }
         }
        
         //private helper methods
         private final static Connection getDatabaseConnection() {
         try {
         Connection outValue = null;
        
         Context context = new InitialContext();
         Object dsObject = context.lookup(
         "java:comp/env/jdbc/WorkflowLifecycle/DBStore");
         DataSource ds = (DataSource)PortableRemoteObject.narrow(
         dsObject, DataSource.class);
        
         ////TO DO: move to connection pool
         //Class.forName("oracle.jdbc.driver.OracleDriver");
         //outValue = DriverManager.getConnection(
         //    "jdbc:oracle:oci:powerfolder/powerfolder@");
        
         outValue = ds.getConnection();
        
         return outValue;
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         catch (NamingException ne) {
         throw new UnexpectedSystemException(ne);
         }
         //catch (ClassNotFoundException cnfe) {
         //    throw new UnexpectedSystemException(cnfe);
         //}
         }
        
         //private helper methods
         private final static QueueConnectionFactory
         getWorkflowQueueConnectionFactory() {
         try {
         QueueConnectionFactory outValue = null;
        
         Context context = new InitialContext();
         Object object = context.lookup(
         "java:comp/env/jms/powerfolder/QueueConnectionFactory");
         outValue = (QueueConnectionFactory)PortableRemoteObject.narrow(
         object, QueueConnectionFactory.class);
        
         return outValue;
         }
         catch (NamingException ne) {
         throw new UnexpectedSystemException(ne);
         }
         }
        
         //private helper methods
         private final static Queue getWorkflowQueue() {
         try {
         Queue outValue = null;
        
         Context context = new InitialContext();
         Object object = context.lookup(
         "java:comp/env/jms/powerfolder/WorkflowQueue");
         outValue = (Queue)PortableRemoteObject.narrow(
         object, Queue.class);
        
         return outValue;
         }
         catch (NamingException ne) {
         throw new UnexpectedSystemException(ne);
         }
         }
        
         //private helper methods
         private final static Queue getTriggerQueue() {
         try {
         Queue outValue = null;
        
         Context context = new InitialContext();
         Object object = context.lookup(
         "java:comp/env/jms/powerfolder/TriggerQueue");
         outValue = (Queue)PortableRemoteObject.narrow(
         object, Queue.class);
        
         return outValue;
         }
         catch (NamingException ne) {
         throw new UnexpectedSystemException(ne);
         }
         }
        
         private final static BigDecimal getNextIndex(Connection inCon) {
         try {
         BigDecimal outValue = null;
        
         //CallableStatement cs =
         //  inCon.prepareCall("{? = call get_next_index}");
         //cs.registerOutParameter(1, Types.NUMERIC);
         //cs.executeUpdate();
         //outValue = cs.getBigDecimal(1);
         PreparedStatement cs = inCon.prepareStatement(
         "SELECT NEXTVAL FOR pf_sequence FROM sysibm.sysdummy1");
         ResultSet rs = cs.executeQuery();
         while (rs.next()) {
         outValue = rs.getBigDecimal(1);
         }
         rs.close();
         cs.close();
        
         return outValue;
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         }
        
         private final static void insertWorkflowInstance(Connection inCon,
         BigDecimal inPfId, Workflow inWorkflow) {
        
         try {
         //TO DO: update query variables
        
         Document workflowDocument = XMLHelper.loadDocument(
         VersionHelper.createXMLRepresentationOfWorkflow(inWorkflow));
         StringWriter sw = new StringWriter();
        
         XMLHelper.writeDocument(workflowDocument, sw);
        
         String workflowXml = sw.toString();
        
         StringReader sr = new StringReader(workflowXml);
        
         PreparedStatement ps = inCon.prepareStatement(
         "insert into pf_workflows (id, wf_instance) values (?,?)");
        
         //MiscHelper.println("workflowXml.len() = " + workflowXml.length());
         ps.setBigDecimal(1, inPfId);
         ps.setCharacterStream(2, sr, workflowXml.length());
         ps.execute();
         ps.close();
        
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         catch (ParserConfigurationException pce) {
         throw new UnexpectedSystemException(pce);
         }
         catch (SAXException saxe) {
         throw new UnexpectedSystemException(saxe);
         }
         catch (IOException ioe) {
         throw new UnexpectedSystemException(ioe);
         }
         }
        
         private final static void storeWorkflowAttributes(Connection inCon,
         BigDecimal inPfId, AttributeSet inAs, boolean inIsInsert) {
        
         try {
        
         Iterator iter = null;
        
         //public system attributes
         iter = inAs.getPublicSysAttrNames();
         while (iter.hasNext()) {
         String attrName = (String)iter.next();
         ValueAndClass vac = inAs.getPublicSysAttr(attrName);
         int pubAttr = BaseDBQueryVendor.PUBLIC;
         int sysAttr = BaseDBQueryVendor.SYSTEM;
         if (inIsInsert) {
         insertWorkflowAttribute(inCon, inPfId, attrName, vac,
         pubAttr, sysAttr);
         }
         else {
         updateWorkflowAttribute(inCon, inPfId, attrName, vac,
         sysAttr);
         }
         }
        
         //private system attributes
         iter = inAs.getPrivateSysAttrNames();
         while (iter.hasNext()) {
         String attrName = (String)iter.next();
         ValueAndClass vac = inAs.getPrivateSysAttr(attrName);
         int pubAttr = BaseDBQueryVendor.PRIVATE;
         int sysAttr = BaseDBQueryVendor.SYSTEM;
         if (inIsInsert) {
         insertWorkflowAttribute(inCon, inPfId, attrName, vac,
         pubAttr, sysAttr);
         }
         else {
         updateWorkflowAttribute(inCon, inPfId, attrName, vac,
         sysAttr);
         }
         }
        
         //public application attributes
         iter = inAs.getPublicAppAttrNames();
         while (iter.hasNext()) {
         String attrName = (String)iter.next();
         ValueAndClass vac = inAs.getPublicAppAttr(attrName);
         int pubAttr = BaseDBQueryVendor.PUBLIC;
         int sysAttr = BaseDBQueryVendor.APPLICATION;
         if (inIsInsert) {
         insertWorkflowAttribute(inCon, inPfId, attrName, vac,
         pubAttr, sysAttr);
         }
         else {
         updateWorkflowAttribute(inCon, inPfId, attrName, vac,
         sysAttr);
         }
         }
        
         //private application attributes
         iter = inAs.getPrivateAppAttrNames();
         while (iter.hasNext()) {
         String attrName = (String)iter.next();
         ValueAndClass vac = inAs.getPrivateAppAttr(attrName);
         int pubAttr = BaseDBQueryVendor.PRIVATE;
         int sysAttr = BaseDBQueryVendor.APPLICATION;
         if (inIsInsert) {
         insertWorkflowAttribute(inCon, inPfId, attrName, vac,
         pubAttr, sysAttr);
         }
         else {
         updateWorkflowAttribute(inCon, inPfId, attrName, vac,
         sysAttr);
         }
         }
        
         }
         catch (SQLException sqle) {
         throw new UnexpectedSystemException(sqle);
         }
         }
        
         private static void insertWorkflowAttribute(Connection inCon,
         BigDecimal inPfId, String inAttrName, ValueAndClass inVac,
         int inPubAttr, int inSysAttr) throws SQLException {
        
         //TO DO: check for attribute type, view, set flag for class type
        
         final String INSERT_QUERY =
         "insert into pf_attributes ("
         + QueryConstructor.ID + ", "
         + QueryConstructor.PF_ID + ", "
         + QueryConstructor.ATTR_NAME + ", "
         + QueryConstructor.DECIMAL_VALUE + ", "
         + QueryConstructor.BOOLEAN_VALUE + ", "
         + QueryConstructor.STRING_VALUE + ", "
         + QueryConstructor.LONG_STRING_VALUE + ", "
         + BaseDBQueryVendor.ATTR_TYPE + ", "
         + BaseDBQueryVendor.ATTR_ACCESS + ", "
         + BaseDBQueryVendor.ATTR_CLASS
         + ") values (NEXTVAL FOR pf_sequence,?,?,?,?,?,?,?,?,?)";
        
         Object value = inVac.getValue();
         Class valueClass = inVac.getValueClass();
        
         PreparedStatement ps = null;
         ps = inCon.prepareStatement(INSERT_QUERY);
        
         ps.setBigDecimal(1, inPfId);
         ps.setString(2, inAttrName.toUpperCase());
         ps.setInt(7, inSysAttr);
         ps.setInt(8, inPubAttr);
        
         if (MiscHelper.isClassNumber(valueClass)) {
         //set class
         ps.setInt(9, BaseDBQueryVendor.DECIMAL);
        
         //TO DO: check for null
         if (value != null) {
         ps.setBigDecimal(3,
         MiscHelper.convertNumberToBigDecimal(value));
         }
         else {
         ps.setNull(3, Types.NUMERIC);
         }
         ps.setNull(4, Types.NUMERIC);
         ps.setNull(5, Types.VARCHAR);
         ps.setNull(6, Types.CLOB);
         }
         else if (value.getClass().getName().equals(Boolean.class.getName())) {
         //set class
         ps.setInt(9, BaseDBQueryVendor.BOOLEAN);
        
         //TO DO: check for null
         Boolean bValue = (Boolean)value;
        
         ps.setNull(3, Types.NUMERIC);
         if (bValue == null) {
         ps.setNull(4, Types.NUMERIC);
         }
         else if (bValue.booleanValue()) {
         ps.setInt(4, 1);
         }
         else {
         ps.setInt(4, 0);
         }
         ps.setNull(5, Types.VARCHAR);
         ps.setNull(6, Types.CLOB);
        
         }
         else {
         //set class
         ps.setInt(9, BaseDBQueryVendor.STRING);
        
         //TO DO: check for null
         String sValue = null;
         if (value != null) {
         sValue = value.toString();
         }
        
         ps.setNull(3, Types.NUMERIC);
         ps.setNull(4, Types.NUMERIC);
        
         if (sValue == null) {
         ps.setNull(5, Types.VARCHAR);
         ps.setNull(6, Types.CLOB);
         }
         else if (sValue.length() <= 250) {
         ps.setString(5, sValue);
         ps.setNull(6, Types.CLOB);
         }
         else {
         ps.setNull(5, Types.VARCHAR);
         ps.setCharacterStream(6, new StringReader(sValue),
         sValue.length());
         }
         }
        
         ps.execute();
         ps.close();
         }
        
         private static void updateWorkflowAttribute(Connection inCon,
         BigDecimal inPfId, String inAttrName, ValueAndClass inVac,
         int inSysAttr) throws SQLException {
        
         //TO DO: check for attribute type, view, set flag for class type
        
         final String UPDATE_BOOLEAN =
         "update pf_attributes set "
         + QueryConstructor.BOOLEAN_VALUE
         + " = ? where "
         + QueryConstructor.PF_ID
         + " = ? and "
         + QueryConstructor.ATTR_NAME
         + " = ? and "
         + BaseDBQueryVendor.ATTR_TYPE
         + " = ?";
        
         final String UPDATE_DECIMAL =
         "update pf_attributes set "
         + QueryConstructor.DECIMAL_VALUE
         + " = ? where "
         + QueryConstructor.PF_ID
         + " = ? and "
         + QueryConstructor.ATTR_NAME
         + " = ? and "
         + BaseDBQueryVendor.ATTR_TYPE
         + " = ?";
        
         final String UPDATE_STRING =
         "update pf_attributes set "
         + QueryConstructor.STRING_VALUE
         + " = ?, "
         + QueryConstructor.LONG_STRING_VALUE
         + " = ? where "
         + QueryConstructor.PF_ID
         + " = ? and "
         + QueryConstructor.ATTR_NAME
         + " = ? and "
         + BaseDBQueryVendor.ATTR_TYPE
         + " = ?";
        
         Object value = inVac.getValue();
         Class valueClass = inVac.getValueClass();
        
         PreparedStatement ps = null;
        
         if (MiscHelper.isClassNumber(valueClass)) {
        
         ps = inCon.prepareStatement(UPDATE_DECIMAL);
        
         if (value != null) {
         ps.setBigDecimal(1,
         MiscHelper.convertNumberToBigDecimal(value));
         }
         else {
         ps.setNull(1, Types.NUMERIC);
         }
         ps.setBigDecimal(2, inPfId);
         ps.setString(3, inAttrName);
         ps.setInt(4, inSysAttr);
         }
         else if (value.getClass().getName().equals(Boolean.class.getName())) {
        
         ps = inCon.prepareStatement(UPDATE_BOOLEAN);
        
         Boolean bValue = (Boolean)value;
        
         if (bValue == null) {
         ps.setNull(1, Types.NUMERIC);
         }
         else if (bValue.booleanValue()) {
         ps.setInt(1, 1);
         }
         else {
         ps.setInt(1, 0);
         }
         ps.setBigDecimal(2, inPfId);
         ps.setString(3, inAttrName);
         ps.setInt(4, inSysAttr);
         }
         else {
        
         ps = inCon.prepareStatement(UPDATE_STRING);
        
         String sValue = null;
         if (value != null) {
         sValue = value.toString();
         }
        
         if (sValue == null) {
         ps.setNull(1, Types.VARCHAR);
         ps.setNull(2, Types.CLOB);
         }
         else if (sValue.length() <= 250) {
         ps.setString(1, sValue);
         ps.setNull(2, Types.CLOB);
         }
         else {
         ps.setNull(1, Types.VARCHAR);
         ps.setCharacterStream(2, new StringReader(sValue),
         sValue.length());
         }
         ps.setBigDecimal(3, inPfId);
         ps.setString(4, inAttrName);
         ps.setInt(5, inSysAttr);
         }
        
         ps.execute();
         ps.close();
         }
        
         public void fireTrigger(String inTrigger) {
         try {
         QueueConnectionFactory queueFactory =
         getWorkflowQueueConnectionFactory();
         QueueConnection queueConnection =
         queueFactory.createQueueConnection();
         Queue queue = getTriggerQueue();
         QueueSession queueSession =
         queueConnection.createQueueSession(false,
         Session.AUTO_ACKNOWLEDGE);
         QueueSender sender = queueSession.createSender(queue);
         queueConnection.start();
         TextMessage message = queueSession.createTextMessage();
         message.setText(inTrigger);
         sender.send(message);
         queueConnection.close();
         }
         catch (JMSException jmse) {
         throw new UnexpectedSystemException(jmse);
         }
         }
        
         //lifecycle methods
         public void setSessionContext(SessionContext sc) {
         this.sessionContext = sc;
         }
        
         public void ejbActivate() {
         }
        
         public void ejbPassivate() {
         }
        
         public void ejbCreate() {
         }
        
         public void ejbRemove() {
         }
        
         }*/
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.