Source Code Cross Referenced for NXDInvSchema.java in  » Workflow-Engines » pegasus-2.1.0 » org » griphyn » vdl » dbschema » 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 » pegasus 2.1.0 » org.griphyn.vdl.dbschema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file or a portion of this file is licensed under the terms of
003:         * the Globus Toolkit Public License, found in file ../GTPL, or at
004:         * http://www.globus.org/toolkit/download/license.html. This notice must
005:         * appear in redistributions of this file, with or without modification.
006:         *
007:         * Redistributions of this Software, with or without modification, must
008:         * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009:         * some other similar material which is provided with the Software (if
010:         * any).
011:         *
012:         * Copyright 1999-2004 University of Chicago and The University of
013:         * Southern California. All rights reserved.
014:         */
015:        package org.griphyn.vdl.dbschema;
016:
017:        import java.sql.*;
018:        import java.util.List;
019:        import java.util.ArrayList;
020:        import java.util.Properties;
021:        import java.io.*;
022:        import java.lang.reflect.*;
023:        import java.net.InetAddress;
024:
025:        import org.xmldb.api.base.*;
026:        import org.xmldb.api.modules.*;
027:        import org.xmldb.api.*;
028:        import javax.xml.transform.OutputKeys;
029:        import javax.xml.parsers.DocumentBuilder;
030:        import javax.xml.parsers.DocumentBuilderFactory;
031:        import javax.xml.parsers.ParserConfigurationException;
032:
033:        import org.w3c.dom.Document;
034:        import org.w3c.dom.Element;
035:        import org.w3c.dom.DOMException;
036:        import org.xml.sax.SAXException;
037:        import org.xml.sax.SAXParseException;
038:        import org.xml.sax.InputSource;
039:
040:        import org.griphyn.vdl.util.ChimeraProperties;
041:        import org.griphyn.vdl.util.Logging;
042:        import org.griphyn.vdl.parser.*;
043:        import org.griphyn.vdl.invocation.*;
044:        import org.griphyn.common.util.Separator;
045:        import org.xml.sax.InputSource;
046:
047:        /**
048:         * This class provides basic functionalities to interact with the
049:         * backend database for invocation records, such as insertion, deletion,
050:         * and search.
051:         *
052:         * @author Jens-S. Vöckler
053:         * @author Yong Zhao
054:         * @version $Revision: 50 $
055:         */
056:        public class NXDInvSchema extends DatabaseSchema implements  PTC {
057:            private DocumentBuilderFactory m_factory;
058:
059:            private DocumentBuilder m_builder;
060:
061:            protected Collection m_db;
062:
063:            protected Collection m_ptc;
064:
065:            protected CollectionManagementService m_dbColService;
066:
067:            protected CollectionManagementService m_ptcColService;
068:
069:            protected XPathQueryService m_dbQrySvc;
070:
071:            protected XPathQueryService m_ptcQrySvc;
072:
073:            /**
074:             * Default constructor for the provenance tracking.
075:             *
076:             * @param dbDriverName is the database driver name
077:             */
078:            public NXDInvSchema(String dbDriverName)
079:                    throws ClassNotFoundException, NoSuchMethodException,
080:                    InstantiationException, IllegalAccessException,
081:                    InvocationTargetException, SQLException, IOException,
082:                    ParserConfigurationException {
083:                // load the driver from the properties
084:                super (); // call minimalistic c'tor, no driver loading!
085:                ChimeraProperties props = ChimeraProperties.instance();
086:
087:                m_dbschemaprops = props
088:                        .getDatabaseSchemaProperties(PROPERTY_PREFIX);
089:
090:                // extract those properties specific to the database driver.
091:                // use default settings.
092:                String driverPrefix = null;
093:                String driverName = props.getDatabaseDriverName(driverPrefix);
094:                Properties driverprops = props
095:                        .getDatabaseDriverProperties(driverPrefix);
096:                String url = props.getDatabaseURL(driverPrefix);
097:
098:                try {
099:                    m_factory = DocumentBuilderFactory.newInstance();
100:                    m_builder = m_factory.newDocumentBuilder();
101:
102:                    Class cl = Class.forName(driverName);
103:                    Database database = (Database) cl.newInstance();
104:                    DatabaseManager.registerDatabase(database);
105:
106:                    // get the collection
107:                    m_db = DatabaseManager.getCollection(url + "/db");
108:                    m_dbColService = (CollectionManagementService) m_db
109:                            .getService("CollectionManagementService", "1.0");
110:
111:                    m_ptc = m_db.getChildCollection("ptc");
112:
113:                    if (m_ptc == null) {
114:                        // collection does not exist, create
115:                        m_ptc = m_dbColService.createCollection("ptc");
116:                    }
117:                    m_ptc.setProperty(OutputKeys.INDENT, "no");
118:
119:                    m_ptcColService = (CollectionManagementService) m_ptc
120:                            .getService("CollectionManagementService", "1.0");
121:
122:                    m_dbQrySvc = (XPathQueryService) m_db.getService(
123:                            "XPathQueryService", "1.0");
124:
125:                    m_ptcQrySvc = (XPathQueryService) m_ptc.getService(
126:                            "XPathQueryService", "1.0");
127:
128:                    m_dbQrySvc.setProperty("indent", "no");
129:
130:                    m_ptcQrySvc.setProperty("indent", "no");
131:                } catch (XMLDBException e) {
132:                    throw new SQLException(e.getMessage());
133:                }
134:            }
135:
136:            /**
137:             * Checks the existence of an invocation record in the database.
138:             * The information is based on the (start,host,pid) tuple, although
139:             * with private networks, cases may arise that have this tuple
140:             * identical, yet are different. 
141:             *
142:             * @param start is the start time of the grid launcher
143:             * @param host is the address of the host it ran upon
144:             * @param pid is the process id of the grid launcher itself. 
145:             * @return the id of the existing record, or -1 
146:             */
147:            public long getInvocationID(java.util.Date start, InetAddress host,
148:                    int pid) throws SQLException {
149:                long result = -1;
150:                Logging.instance().log("xaction", 1,
151:                        "START select invocation id");
152:
153:                String xquery = "/invocation[@start='" + start + "']";
154:                xquery += "[@host='" + host.getHostAddress() + "']";
155:                xquery += "[@pid=" + pid + "]";
156:
157:                try {
158:                    Logging.instance().log("nxd", 2, xquery);
159:                    ResourceSet rs = m_dbQrySvc.query(xquery);
160:                    ResourceIterator i = rs.getIterator();
161:                    if (i.hasMoreResources()) {
162:                        result = 1;
163:                    } else {
164:                        result = -1;
165:                    }
166:                } catch (XMLDBException e) {
167:                    throw new SQLException(e.getMessage());
168:                }
169:
170:                Logging.instance().log("xaction", 1,
171:                        "FINAL select invocation id");
172:                return result;
173:            }
174:
175:            /**
176:             * Inserts an invocation record into the database.
177:             *
178:             * @param ivr is the invocation record to store.
179:             * @return true, if insertion was successful, false otherwise. 
180:             */
181:            public boolean saveInvocation(InvocationRecord ivr)
182:                    throws SQLException {
183:                try {
184:                    StringWriter sw = new StringWriter();
185:
186:                    ivr.toXML(sw, "", null);
187:                    // create new XMLResource; an id will be assigned to the new resource
188:                    XMLResource document = (XMLResource) m_ptc.createResource(
189:                            null, "XMLResource");
190:                    document.setContent(sw.toString());
191:                    System.out.println(sw.toString());
192:                    m_ptc.storeResource(document);
193:                    return true;
194:                } catch (Exception e) {
195:                    throw new SQLException(e.getMessage());
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.