⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectiontest.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// 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.other;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.ozoneDB.ExternalDatabase;import org.ozoneDB.OzoneInterface;import org.ozoneDB.xml.core.XMLCollection;import org.ozoneDB.xml.core.XMLCollectionImpl;import org.xmldb.api.base.Collection;import org.xmldb.api.base.Database;/** * This tests the Connection and root collection creation, * retrieval and deleting. * @author Per Nyfelt and SMB */public class ConnectionTest extends TestCase {    ExternalDatabase db = null;    Database xmlDB = null;    String databaseClass = "org.ozoneDB.xml.cli.DatabaseImpl";    String dbURI = "ozonedb:remote://localhost:3333";    String collectionName="per";    // url schema:    // xmldb:ozonexml:<database>?<rootcoll>    //    // <database> can either be a directory in the local filesystem or a remote    // ip address (host:port)    // <rootcoll> specifies the name of the root collection to load    // Example:    //Collection rootCol = xmlDB.getCollection( "xmldb:ozonexml:/home/lars/xmltest?root" );    String collectionURI = "xmldb:ozonexml://localhost:3333?" + collectionName;    /**     * @param name the name given to the test     */    public ConnectionTest(String name) {        super(name);    }    public static Test suite() {        return new TestSuite(ConnectionTest.class);    }    /*    public void testStub() {        try {        } catch (Exception e) {            fail( e.getUserName( ) );        }    }    */    /**     * Test the whole cycle of create, get and delete a collection     */    public void testCycle() {        try {            create();            get();            delete();        } catch (Exception e) {            fail( e.getMessage( ) );        }    }    private void connect() throws Exception {        if (db == null || !db.isOpen()) {                // load a database instance                xmlDB = (Database)Class.forName(databaseClass).newInstance();                db = ExternalDatabase.openDatabase(dbURI);                db.reloadClasses();        }    }    private void create() throws Exception {        connect();        assertNotNull(db);        // create a new Collection        XMLCollection root = (XMLCollection)db.createObject( XMLCollectionImpl.class.getName(), OzoneInterface.Public, collectionName);        root.setName(collectionName);        db.close();        assertTrue(!db.isOpen());    }    private void delete() throws Exception{        connect();        assertNotNull(db);        db.deleteObject(db.objectForName(collectionName));        db.close();        assertTrue(!db.isOpen());    }    private void get() throws Exception {        connect();        assertNotNull(db);        Collection rootCol = xmlDB.getCollection(collectionURI);        // check the name of the collection        assertTrue(rootCol instanceof org.ozoneDB.xml.cli.CollectionImpl);        assertEquals(collectionName, rootCol.getName());    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -