Source Code Cross Referenced for StoreDocument.java in  » Database-DBMS » Ozone-1.1 » test » xmldb » other » 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 » Database DBMS » Ozone 1.1 » test.xmldb.other 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006:        //
007:        package test.xmldb.other;
008:
009:        import java.io.BufferedReader;
010:        import java.io.FileReader;
011:        import java.io.StringWriter;
012:        import java.util.Iterator;
013:
014:        import org.ozoneDB.ExternalDatabase;
015:        import org.ozoneDB.OzoneInterface;
016:        import org.ozoneDB.OzoneProxy;
017:        import org.ozoneDB.xml.core.XMLCollectionImpl;
018:        import org.ozoneDB.xml.core.XMLCollection;
019:        import org.xmldb.api.modules.XMLResource;
020:
021:        import org.xmldb.api.base.Collection;
022:        import org.xmldb.api.base.Database;
023:        import org.xmldb.api.DatabaseManager;
024:
025:        import org.xml.sax.InputSource;
026:        import org.apache.xerces.parsers.DOMParser;
027:        import org.w3c.dom.Document;
028:        import org.apache.xml.serialize.OutputFormat;
029:        import org.apache.xml.serialize.XMLSerializer;
030:
031:        import org.ozoneDB.xml.util.*;
032:        import org.ozoneDB.ExternalTransaction;
033:        import org.xml.sax.helpers.*;
034:        import org.apache.xerces.parsers.DOMParser;
035:        import org.w3c.dom.Node;
036:        import org.w3c.dom.Document;
037:
038:        import test.xmldb.*;
039:
040:        /**
041:         * @author  Per Nyfelt
042:         */
043:        public class StoreDocument implements  Constants {
044:
045:            ExternalDatabase db = null;
046:
047:            /** Creates new StoreDocument */
048:            public StoreDocument() {
049:                try {
050:                    createCollection();
051:                    Class c = Class.forName(driver);
052:
053:                    //Database database = (Database) c.newInstance();      
054:                    System.out.println("collectionURI is " + collectionURI);
055:                    Collection col = DatabaseManager
056:                            .getCollection(collectionURI);
057:                    //Collection col = database.getCollection(collectionURI);
058:                    Document doc = parseDocument();
059:                    XMLResource resource = (XMLResource) col
060:                            .getResource(resourceName);
061:                    if (resource == null) {
062:                        OzoneProxy o = db.objectForName(resourceName);
063:                        if (o != null) {
064:                            System.out
065:                                    .println("Object found as db oject, deleting it..");
066:                            db.deleteObject(o);
067:                        }
068:                        System.out
069:                                .println("resource is null, create the resource with name "
070:                                        + resourceName);
071:                        resource = (XMLResource) col.createResource(
072:                                resourceName, XMLResource.RESOURCE_TYPE);
073:                    } else {
074:                        System.out.println("deleting resource" + resourceName);
075:                        col.removeResource(resource);
076:                        resource = (XMLResource) col.createResource(
077:                                resourceName, XMLResource.RESOURCE_TYPE);
078:                    }
079:                    System.out.println("Created resource " + resourceName
080:                            + " with id " + resource.getId());
081:                    // double check to see if it actually works
082:                    resource = (XMLResource) col.getResource(resourceName);
083:                    System.out.println("Resource found with name "
084:                            + resource.getId());
085:                    resource.setContentAsDOM(doc);
086:                    System.out.println("Updated content: "
087:                            + resource.getContent());
088:                    col.storeResource(resource);
089:                    //System.out.println("Stored the following Document:\n" + toString(doc));
090:                    System.out.println("Stored the following Document:\n"
091:                            + doc.getDocumentElement().getTagName());
092:                    col.close();
093:                    db.close();
094:                } catch (Exception e) {
095:                    System.out.println(e.getMessage());
096:                    e.printStackTrace();
097:                }
098:            }
099:
100:            private void createCollection() throws Exception {
101:                try {
102:                    connect();
103:                    // check if there is an object there already in that case delete it
104:                    // we assume we are cleaning up after an usuccessful testrun
105:                    XMLCollection test = (XMLCollection) db
106:                            .objectForName(collectionName);
107:                    if (test != null) {
108:                        deleteCollection();
109:                        connect();
110:                    }
111:                    // create a new Collection
112:                    org.ozoneDB.xml.cli.CollectionFactory.create(db,
113:                            collectionName);
114:                } catch (Exception e) {
115:                    e.printStackTrace();
116:                    throw e;
117:                }
118:            }
119:
120:            private void connect() throws Exception {
121:                if (db == null || !db.isOpen()) {
122:                    db = ExternalDatabase.openDatabase(dbURI);
123:                    System.out.println("StoreDocument.connect() - connected");
124:                    db.reloadClasses();
125:                }
126:            }
127:
128:            public void deleteCollection() {
129:                try {
130:                    connect();
131:                    XMLCollection collection = (XMLCollection) db
132:                            .objectForName(collectionName);
133:                    Iterator it = collection.getResources().iterator();
134:                    while (it.hasNext()) {
135:                        XMLContainer.forName(db, (String) it.next()).delete();
136:                    }
137:                    db.deleteObject(collection);
138:                    System.out
139:                            .println("StoreDocument.deleteCollection() - deleted "
140:                                    + collectionName);
141:                    db.close();
142:                } catch (Exception e) {
143:                    e.printStackTrace();
144:                }
145:            }
146:
147:            Document parseDocument() throws Exception {
148:                BufferedReader in = new BufferedReader(new FileReader(fileName));
149:                InputSource source = new InputSource(in);
150:                DOMParser parser = new DOMParser();
151:                parser.parse(source);
152:                return parser.getDocument();
153:            }
154:
155:            private XMLSerializer getSerializer() throws Exception {
156:                StringWriter writer = new StringWriter();
157:                XMLSerializer serializer = new XMLSerializer(writer,
158:                        new OutputFormat("xml", "UTF-8", true));
159:                return serializer;
160:            }
161:
162:            protected static void domStore(String id, Node doc)
163:                    throws Exception {
164:                String dbURI = "ozonedb:remote://localhost:3333";
165:                ExternalDatabase db = ExternalDatabase.openDatabase(dbURI);
166:                XMLContainer container = XMLContainer.forName(db, id);
167:                if (container == null) {
168:                    container = XMLContainer.newContainer(db, id);
169:                }
170:
171:                ExternalTransaction tx = db.newTransaction();
172:                try {
173:                    long start = System.currentTimeMillis();
174:
175:                    tx.begin();
176:                    start = System.currentTimeMillis();
177:                    container.storeDOM(null, doc);
178:                    System.out.println("DOM store: store time: "
179:                            + (System.currentTimeMillis() - start) + " ms");
180:
181:                    start = System.currentTimeMillis();
182:                    tx.commit();
183:                    System.out.println("DOM store: commit time: "
184:                            + (System.currentTimeMillis() - start) + " ms");
185:                } catch (Exception e) {
186:                    tx.rollback();
187:                    throw e;
188:                }
189:            }
190:
191:            public static void main(String args[]) {
192:                new StoreDocument();
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.