KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > xmldb > levelzero > TransactionalDOMTest


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
package test.xmldb.levelzero;
8
9 import org.w3c.dom.Document JavaDoc;
10 import org.xmldb.api.modules.TransactionService;
11 import org.xmldb.api.modules.XMLResource;
12 import test.xmldb.XMLDBTestCase;
13
14 /**
15  * @author Per Nyfelt
16  */

17 public class TransactionalDOMTest extends XMLDBTestCase implements LevelZeroTestConstants {
18
19     /** Creates new TransactionalDOMTest */
20     public TransactionalDOMTest(String JavaDoc name) {
21         super(name);
22     }
23
24     /**
25      * test the transaction capabilities, this is optional for Core Level 1
26      */

27     public void testTransaction() {
28         try {
29             Document JavaDoc document1 = null;
30             Document JavaDoc document2 = null;
31
32             String JavaDoc id1 = "LevelZeroTest";
33             String JavaDoc id2 = "LevelZeroTest2";
34             transactionalInsertDOMDocument(id1, document1, id2, document2);
35
36         } catch (Exception JavaDoc e) {
37             fail( e.getMessage( ) );
38         }
39     }
40
41    // Transaction support is optional for level 0 compliance
42
private void transactionalInsertDOMDocument(String JavaDoc id1, Document JavaDoc document1,
43                     String JavaDoc id2, Document JavaDoc document2) throws Exception JavaDoc {
44
45         TransactionService transaction =
46            (TransactionService) col.getService("TransactionService", "1.0");
47
48         transaction.begin();
49
50         XMLResource resource1 =
51            (XMLResource) col.createResource(id1, XMLResource.RESOURCE_TYPE);
52
53         resource1.setContentAsDOM(document1);
54         col.storeResource(resource1);
55
56         XMLResource resource2 =
57            (XMLResource) col.createResource(id2, XMLResource.RESOURCE_TYPE);
58
59         resource2.setContentAsDOM(document2);
60         col.storeResource(resource2);
61
62         transaction.commit();
63
64    }
65 }
66
Popular Tags