Package test.xmldb.levelzero

Source Code of test.xmldb.levelzero.TransactionalDOMTest

// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
package test.xmldb.levelzero;

import test.xmldb.*;
import junit.framework.*;

import org.xmldb.api.modules.TransactionService;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

import org.xmldb.api.modules.XMLResource;

/**
* @author  Per Nyfelt
*/
public class TransactionalDOMTest extends XMLDBTestCase implements LevelZeroTestConstants {

    /** Creates new TransactionalDOMTest */
    public TransactionalDOMTest(String name) {
        super(name);
    }

    /**
     * test the transaction capabilities, this is optional for Core Level 1
     */
    public void testTransaction() {
        try {
            Document document1 = null;
            Document document2 = null;

            String id1 = "LevelZeroTest";
            String id2 = "LevelZeroTest2";
            transactionalInsertDOMDocument(id1, document1, id2, document2);

        } catch (Exception e) {
            fail( e.getMessage( ) );
        }
    }

   // Transaction support is optional for level 0 compliance
   private void transactionalInsertDOMDocument(String id1, Document document1,
                    String id2, Document document2) throws Exception {

        TransactionService transaction =
           (TransactionService) col.getService("TransactionService", "1.0");

        transaction.begin();

        XMLResource resource1 =
           (XMLResource) col.createResource(id1, XMLResource.RESOURCE_TYPE);

        resource1.setContentAsDOM(document1);
        col.storeResource(resource1);

        XMLResource resource2 =
           (XMLResource) col.createResource(id2, XMLResource.RESOURCE_TYPE);

        resource2.setContentAsDOM(document2);
        col.storeResource(resource2);

        transaction.commit();

   }
}
TOP

Related Classes of test.xmldb.levelzero.TransactionalDOMTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.