ラベル Berkeley DB XML の投稿を表示しています。 すべての投稿を表示
ラベル Berkeley DB XML の投稿を表示しています。 すべての投稿を表示

2009年5月16日土曜日

Java で Berkely DB XML を操作する 第1回

Java で Berkely DB XML を扱う環境が整ったので、チュートリアル「Getting Started with Berkeley DB XML for Java(日本語訳)」を基にJavaで作ってみる。

  1. プロジェクトの作成
    dbxml_gettingstart」という名前でJavaのプロジェクトを新規作成する。
  2. ライブラリの追加
    以下のJar ファイルを追加する。
    • /opt/oracle/dbxml-2.4.16/lib/dbxml.jar
    • /opt/oracle/dbxml-2.4.16/lib/db.jar
  3. DBD XML の例外処理のソースを記述する。
    /*
    * File Name :Chapter2_1.java
    * Created on :2009/05/15, 22:13:25

    * Copyright(c) Exacteye.com All Rights Reserved.
    */

    package dbxml.chapter2;

    import com.sleepycat.dbxml.XmlContainer;
    import com.sleepycat.dbxml.XmlException;
    import com.sleepycat.dbxml.XmlManager;

    /**
    DBXML 例外の処理
    * @author obiwan
    */
    public class Chapter2_1 {

    public static void main(String[] args) throws Throwable{
    XmlContainer myConatiner = null;
    XmlManager myManager = null;
    String theContainer = "container.dbxml";

    // XmlConatiner と XmlManager のオープン
    try {
    myManager = new XmlManager();
    myConatiner = myManager.openContainer(theContainer);
    } catch (XmlException ex) {
    // ここで例外処理を実装する。
    ex.printStackTrace();
    }
    }
    }

  4. 実行させる。ソース上にある、container.dbxml は作成していないのでエラーが出るはず。
    run:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no db_java-4.6 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1030)
    at com.sleepycat.db.internal.db_javaJNI.(db_javaJNI.java:52)
    at com.sleepycat.db.internal.DbEnv.(DbEnv.java:264)
    at com.sleepycat.dbxml.XmlManager.(XmlManager.java:78)
    at com.sleepycat.dbxml.XmlManager.(XmlManager.java:102)
    at dbxml.chapter2.Chapter2_1.main(Chapter2_1.java:27)
    Java Result: 1
    構築成功 (合計時間: 1 秒)
    java.lang.UnsatisfiedLinkError: no db_java-4.6 in java.library.path」って違うエラーが出た。検索したら、「Thread: java.lang.UnsatisfiedLinkError on Mac OS X with 2.4.16」が参考になった。
    プロジェクトのプロパティを表示させ、VMオプションに「-Djava.library.path=/opt/oracle/dbxml-2.4.16/lib」を追加した。


  5. 再度、実行。
    run:
    com.sleepycat.dbxml.XmlException: Error: container.dbxml: container file not found, or not a container, errcode = CONTAINER_NOT_FOUND
    at com.sleepycat.dbxml.dbxml_javaJNI.XmlManager_openContainer__SWIG_2(Native Method)
    at com.sleepycat.dbxml.XmlManager.openContainer(XmlManager.java:585)
    at com.sleepycat.dbxml.XmlManager.openContainer(XmlManager.java:218)
    at com.sleepycat.dbxml.XmlManager.openContainer(XmlManager.java:160)
    at dbxml.chapter2.Chapter2_1.main(Chapter2_1.java:28)
    構築成功 (合計時間: 1 秒)

    今度は想定していた、「container.dbxml」が無い例外が発生する。

2009年5月13日水曜日

ubuntu 9.04 に Berkeley DB XML をインストールする

Berkeley DB XML は組み込み型のXMLデータベースです。XQuery で検索が出きるとのことなので使ってみる。今日の目標はインストールまで。

ドキュメント関係はここからダウンロードする。日本語のドキュメント無いかな?
あった。Berkeley DB XML関係 に日本語訳があった。

インストール
ダウンロードサイトから最新版をダウンロードする。ダウンロードしたファイルは dbxml-2.4.16.tar.gz

$ tar zxvf dbxml-2.4.16.tar.gz
$ cd dbxml-2.4.16/
$ ./buildall.sh
Start DB build: 2009年 5月 13日 水曜日 22:37:56 JST
Configuring Berkeley DB
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking if building in the top-level or dist directories... no
checking if --disable-cryptography option specified... no
checking if --disable-hash option specified... no
checking if --disable-mutexsupport option specified... no
checking if --disable-queue option specified... no
checking if --disable-replication option specified... no
checking if --disable-statistics option specified... no
checking if --disable-verify option specified... no
checking if --enable-compat185 option specified... no
checking if --enable-cxx option specified... yes
checking if --enable-debug option specified... no
checking if --enable-debug_rop option specified... no
checking if --enable-debug_wop option specified... no
checking if --enable-diagnostic option specified... no
checking if --enable-dump185 option specified... no
checking if --enable-java option specified... no
checking if --enable-mingw option specified... no
checking if --enable-fine_grained_lock_manager option specified... no
checking if --enable-o_direct option specified... no
checking if --enable-posixmutexes option specified... no
checking if --enable-pthread_api option specified... no
checking if --enable-rpc option specified... no
checking if --enable-smallbuild option specified... no
checking if --enable-tcl option specified... no
checking if --enable-test option specified... no
checking if --enable-uimutexes option specified... no
checking if --enable-umrw option specified... no
checking if --with-mutex=MUTEX option specified... no
checking if --with-tcl=DIR option specified... no
checking if --with-uniquename=NAME option specified... no
checking for chmod... chmod
checking for cp... cp
checking for ln... ln
checking for mkdir... mkdir
checking for rm... rm
checking for sh... /bin/sh
checking for a BSD-compatible install... /usr/bin/install -c
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking how to run the C++ preprocessor... /lib/cpp
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.


GNU C++のコンパイラと g++ が無いと怒られる。
$ sudo apt-get install gcc g++


インストール先を /opt/oracle/dbxml-2.4.16 にして、Javaを使用可能にし、インストールを実行する。
$ sudo ./buildall.sh --prefix=/opt/oracle/dbxml-2.4.16 --enable-java --enable-debug


インストールが無事済んだようなので、コマンドラインのdbxmlを使えるようにする。
$ vi ~/.bashrc

以下のPATHを追加し、保存。
DBXML_HOME=/opt/oracle/dbxml-2.4.16
LD_LIBRARY_PATH=$DBXML_HOME/lib
LD_RUN_PATH=$DBXML_HOME/lib
PATH="$PATH":$DBXML_HOME/bin

設定を有効にする。
$ source ~/.bashrc

DBXMLコマンドを実行してみる。
$ dbxml
dbxml>

を!動いた。
では、「qune: Berkeley DB XML で NXD みたいなことをしてみる」に掲載されていたサンプルを実行してみる。
dbxml> createContainer sample.xmldb
Creating node storage container

dbxml> addDocument doc1 '<?xml version="1.0"?><foo>bar</foo>'
Document added, name = doc1

dbxml> getMetaData doc1
Metadata for document: doc1
http://www.sleepycat.com/2002/dbxml:name

dbxml> addDocument doc2 '<?xml version="1.0"?><foo>Hello,World!</foo>'
Document added, name = doc2

dbxml> query 'collection("sample.xmldb")/foo'
2 objects returned for eager expression 'collection("sample.xmldb")/foo'

dbxml> print
<foo>bar</foo>
<foo>Hello,World!</foo>

今日はここまでかな〜。