<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oracle Berkeley DB 中国研发团队的博客 &#187; Berkeley DB XML</title>
	<atom:link href="http://www.bdbchina.com/category/berkeley-db-xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bdbchina.com</link>
	<description>Oracle Berkeley DB 中国研发团队的博客</description>
	<lastBuildDate>Thu, 15 Dec 2011 10:35:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>bdb开通新浪微博</title>
		<link>http://www.bdbchina.com/2011/05/bdb%e5%bc%80%e9%80%9a%e6%96%b0%e6%b5%aa%e5%be%ae%e5%8d%9a/</link>
		<comments>http://www.bdbchina.com/2011/05/bdb%e5%bc%80%e9%80%9a%e6%96%b0%e6%b5%aa%e5%be%ae%e5%8d%9a/#comments</comments>
		<pubDate>Mon, 30 May 2011 10:41:58 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[生活圆桌]]></category>
		<category><![CDATA[bdb]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=1537</guid>
		<description><![CDATA[各位BDB中文博客的粉丝们，为了更好的和大家交互并分享BDB的消息，我们刚刚开通的新浪微博。微博地址为：
http://www.weibo.com/bdbchina
欢迎各位朋友添加关注并和我们分享信息。感谢大家的一直以来的支持。
备注： 由于工作比较忙（很少看博客评论），我们推荐大家使用新浪微博和我们互动，从而可以得到更及时、有效的反馈。
Oracle Berkeley DB 中国开发团队
]]></description>
			<content:encoded><![CDATA[<p>各位BDB中文博客的粉丝们，为了更好的和大家交互并分享BDB的消息，我们刚刚开通的新浪微博。微博地址为：<a title="http://weibo.com/bdbchina" href="http://www.weibo.com/bdbchina" target="_blank"></a></p>
<p><a title="http://weibo.com/bdbchina" href="http://www.weibo.com/bdbchina" target="_blank">http://www.weibo.com/bdbchina</a></p>
<p>欢迎各位朋友添加关注并和我们分享信息。感谢大家的一直以来的支持。</p>
<p><em><strong>备注： 由于工作比较忙（很少看博客评论），我们推荐大家使用新浪微博和我们互动，从而可以</strong></em><em><strong>得到</strong></em><em><strong>更及时、有效的反馈。</strong></em></p>
<p>Oracle Berkeley DB 中国开发团队</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2011/05/bdb%e5%bc%80%e9%80%9a%e6%96%b0%e6%b5%aa%e5%be%ae%e5%8d%9a/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Oracle Berkeley DB as a NoSQL Data Store</title>
		<link>http://www.bdbchina.com/2011/02/using-oracle-berkeley-db-as-a-nosql-data-store/</link>
		<comments>http://www.bdbchina.com/2011/02/using-oracle-berkeley-db-as-a-nosql-data-store/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 03:37:59 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[nosql]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=1527</guid>
		<description><![CDATA[

Using Oracle Berkeley DB as a NoSQL Data Store
By Shashank Tiwari
Learn why and how Oracle Berkeley DB can bring NoSQL benefits to your app.
Published February 2011
“NoSQL” is the new popular buzzword among developers, architects and even technology managers. However, despite the term&#8217;s newfound popularity, surprisingly there is no universally agreed-upon definition for it.
Generally, any database [...]]]></description>
			<content:encoded><![CDATA[<div>
<div>
<h2>Using Oracle Berkeley DB as a NoSQL Data Store</h2>
<p><em>By Shashank Tiwari</em></p>
<p><strong>Learn why and how Oracle Berkeley DB can bring NoSQL benefits to your app.</strong></p>
<p>Published February 2011</p>
<p>“NoSQL” is the new popular buzzword among developers, architects and even technology managers. However, despite the term&#8217;s newfound popularity, surprisingly there is no universally agreed-upon definition for it.</p>
<p>Generally, any database that isn’t RDBMS, upholds schema-less structures, is generally relaxed on ACID transactions, and promises high availability and support for large data sets in horizontally scaled environments is popularly categorized as a “NoSQL data store”. Given that these common features often seem in direct contrast to those of a good old RDBMS, some people propose <em>non-relational</em>, perhaps shortened as NonRel, as a more appropriate term than NoSQL.</p>
<p>Regardless, while the definitional conflict continues, many have begun to realize the benefits of NoSQL data stores by including them in their application stack. The rest are keeping a close watch and evaluating if NoSQL is right for them.</p>
<p><span id="more-1527"></span></p>
<p>The growth of NoSQL as a category has also led to the emergence of a number of new data stores. Some of these new NoSQL products are good at persisting JSON-like documents, some are sorted ordered column-family stores, and others persist distributed key-value pairs. While newer products are exciting and offer many nice features, a few existing ones rise up to deliver the new promise as well.</p>
<p>One such data store is <a href="http://www.oracle.com/technetwork/database/berkeleydb/overview/index.html">Oracle Berkeley DB</a>. In this article I will illustrate and explain why and how Berkeley DB can be included in the stack as a NoSQL solution. The article focuses exclusively on Berkeley DB’s NoSQL-centric features and thus does not exhaustively cover all of Berkeley DB’s capabilities and idiosyncrasies.</p>
<h3>Berkeley DB Essentials</h3>
<p>Fundamentally a key-value store, Berkeley DB comes in three distinct flavors:</p>
<ul>
<li>Berkeley DB – key-value store programmed in C. (Berkeley DB official documentation uses the term <em>key-data</em> in place of key-value.) This is the &#8220;classic&#8221; flavor.</li>
<li>Berkeley DB Java Edition (JE) – key-value store re-written in Java. Can easily be incorporated into a Java stack.</li>
<li>Berkeley DB XML – Written in C++, this version wraps the key-value store to behave as an indexed and optimized XML storage system.</li>
</ul>
<p>(Note: Although this article does not expressly cover Berkeley DB JE or Berkeley DB XML, it does include examples that use the Java API and the Java-based persistence frameworks to illustrate the capabilities of Berkeley DB.)</p>
<p>Simple as it may be at its core, Berkeley DB can be configured to provide concurrent non-blocking access or support transactions, scaled out as a highly available cluster of master-slave replicas, or in a number of other ways.</p>
<p>Berkeley DB is a pure storage engine that makes no assumptions about an implied schema or structure to the key-value pairs. Therefore, Berkeley DB easily allows for higher level API, query, and modeling abstractions on top of the underlying key-value store. This facilitates fast and efficient storage of application specific data, without the overhead of translating it into an abstracted data format. The flexibility offered by this simple, yet elegant design, makes it possible to store both structured and semi-structured data in Berkeley DB.</p>
<p>Berkeley DB can run as an in-memory store to hold small amounts of data or it can be configured as a large data store, with a fast in-memory cache. Multiple databases can be set up in a single physical install with the help of a higher-level abstraction, called <em>environment</em>. One environment can have multiple databases. You need to open an environment and then a database to write data to it or read data from it. It’s advised that you close a database and the environment when you have completed your interactions to optimally use resources.</p>
<p>Each item in a database is a key-value pair. The key is typically unique but you could have duplicates. A Value is accessed using a key. A retrieved value can be updated and saved back to the database. Multiple values are accessed and iterated over using a cursor. Cursors allow you to loop through the collection of values and manipulate them one at a time. Transactions and concurrent access are additionally supported.</p>
<p>The key of a key-value pair almost always serves as the primary key, which is indexed. Other properties within the value could serve as secondary indexes. Secondary indexes are maintained separately in a secondary database. The main database, which has the key-value pairs, is therefore also sometimes referred to as the primary database.</p>
<p>Berkeley DB runs as an in-process data store, so you statically or dynamically link to it when accessing it using the C, C++, C#, Java or scripting language APIs from a corresponding program.</p>
<p>With that whirlwind introduction, the following section describes Berkeley DB in the context of its NoSQL-centric features.</p>
<h3>Fluid Schema</h3>
<p>The first benefit of a NoSQL store is its relaxed attitude toward well-defined database schemas. Let us see how Berkeley DB fares on this feature.</p>
<p>To appreciate Berkeley DB’s capabilities, I suggest you take it for a spin. Therefore, it is recommended that you download and install both Berkeley DB and Berkeley DB JE on your machine so you can try some examples yourself and follow along with the rest of the illustrations in this article. Download links and installation instructions are available online <a href="http://www.oracle.com/technetwork/database/berkeleydb/downloads/index.html">here</a>. (I compiled Berkeley DB with &#8211;enable-java, &#8211;enable-sql, and &#8211;prefix=/usr/local for this article.) The fundamental concepts that relate to storage, access mechanisms and the API don’t vary much between Berkeley DB and Berkeley DB JE so most things I cover next apply equally well to both.</p>
<p>Berkeley DB itself imposes little restrictions on the data items beyond it being a collection of key-value pairs. This allows applications to flexibly use Berkeley DB to manage data in a variety of formats, including SQL, XML and Java objects. You can access data in Berkeley DB via the base API, the SQL API, the Java Collections API, and the Java Direct Persistence Layer (DPL). It allows a few different storage configurations: B-Tree, Hash, Queue, and Recno. (The Berkeley DB documentation refers to the different storage mechanisms as “access methods”. Hash, Queue, and Recno access methods are available only in Berkeley DB and not in Berkeley DB JE or Berkeley DB XML.)</p>
<p>Depending on your specific use case, you could choose an access mechanism and a storage configuration. This choice of a particular access method and a storage configuration can affect schema. To understand the impact of the choices, you need to first understand what they are. I cover the access methods and storage configurations next.</p>
<h4>Using the Base API</h4>
<p>The Base API is a low-level API that allows you to store, retrieve and update data, the key-value pairs. This API is similar across different language bindings. Therefore the Base API for C, C++ and Java are quite the same. DPL and the Java Collections API, on the other hand, are only offered as an abstraction in the Java API.</p>
<p>The Base API puts, gets and deletes key-value pairs. Both the key and the value are an array of bytes. All key and data values get serialized to byte arrays before they are stored. One could use Java’s built-in serializer or Berkeley DB’s BIND API to serialize various data types to byte arrays. Java’s built-in serializer is typically a slow performer so one must go in favor of the BIND API. (The jvm-serializers project benchmarks various alternative serializers and is a good reference point to <a href="https://github.com/eishay/jvm-serializers/wiki/">analyze relative performance</a> among different serialization mechanisms in the JVM.) The BIND API avoids redundantly storing the class information with every serialized class and instead puts that information in a separate database. Potentially, you could makes things faster by writing your own <a href="http://download.oracle.com/docs/cd/E17076_02/html/gsg/JAVA/bindAPI.html#customTuple.">custom tuple binding</a> to improve the BIND API performance.</p>
<p>As an elementary example, you can have a data value defined as follows:</p>
<pre>import java.io.Serializable;
public class DataValue implements Serializable {
    private long prop1;
    private double prop2;

    DataValue() {
      prop1 = 0;
      prop2 = 0.0;
    }

    public void setProp1(long data) {
      prop1 = data;
    }

    public long getProp1() {
      return prop1;
    }

    public void setProp2(double data) {
      prop2 = data;
    }

    public double getProp2() {
      return prop2;
    }
}</pre>
<p>Now, you can store this data value using two databases, one to store the value with a key and another to store the class information.</p>
<p>The data is stored using four distinct steps:</p>
<ol>
<li>First a second database, apart from the one to store key-value pairs, is configured to store class data as follows:
<pre>Database aClassDB = new Database("classDB", null, aDbConfig);</pre>
</li>
<li>Then a class catalog is instantiated as follows:
<pre>StoredClassCatalog storedClassCatalog = new StoredClassCatalog(aClassDb);</pre>
</li>
<li>A serial entry binding is established like so:
<pre>EntryBinding binding = new SerialBinding(storedClassCatalog, DataValue.class);</pre>
</li>
<li>Finally, a DataValue instance like so:
<pre>DataValue val = new DataValue();
val.setProp1(123456789L);
val.setProp2(1234.56789);</pre>
<p>is mapped to a Berkeley DB DatabaseEntry, which serves as a wrapper for both the key and value, using the binding you just created as follows:</p>
<pre>DatabaseEntry deKey = new DatabaseEntry(aKey.getBytes("UTF-8"));
DatabaseEntry deVal = new DatabaseEntry();
binding.objectToEntry(val, deVal);</pre>
</li>
</ol>
<p>Now you are ready to put the key-value pair in Berkeley DB.</p>
<p>The base API supports a few variants of the put and get methods, to allow or dis-allow duplicates and overwrites. (The intent of neither this example nor the article is to teach you the detailed syntax or semantics of using the base API so I will not get into further details; see the doc <a href="http://www.oracle.com/technetwork/database/berkeleydb/documentation/index.html">here</a>.) An important takeaway is that the base API allows for low-level manipulation and custom serialization around storing, retrieving and deleting key-value pairs.</p>
<p>If you prefer to interact with Berkeley DB with a higher level API, then you should use DPL.</p>
<h4>Using DPL</h4>
<p>Direct Persistence Layer (DPL) provides familiar Java persistence framework semantics for manipulating objects. You can treat Berkeley DB as an entity store where objects are persisted, retrieved to be updated and deleted. DPL uses annotations to mark a class as an @Entity. Associated classes, which get stored with an Entity, are annotated as @Persistent. Specific properties or variables can be annotated as @PrimaryKey and @SecondaryKey. A simple Entity could be as follows:</p>
<pre>@Entity
public class AnEntity {

    @PrimaryKey
    private int myPrimaryKey;

    @SecondaryKey(relate=ONE_TO_ONE)
    private String mySecondaryKey;
    ...
}</pre>
<p>DPL imposes the class definition as a well-defined schema. From the base API we know that such a conformance to schema is not a requirement for Berkeley DB. For some use cases, however, formal entity definitions are helpful and provide a structured approach to data modeling.</p>
<h4>Storage Configuration</h4>
<p>As mentioned previously, key-value pairs can be stored in four different types of data structures: B-Tree, Hash, Queue and Recno. Let’s see how they stack up.</p>
<ul>
<li><strong>B-Tree. </strong>A B-tree needs little introduction but if you do need to review its definition then read the Wikipedia page on B-Tree, available online at <a href="http://en.wikipedia.org/wiki/B-tree">http://en.wikipedia.org/wiki/B-tree</a>. It’s a balanced tree data structure that keeps its elements sorted and allows for fast sequential access, insertions and deletions. Key and values can be arbitrary data types. In Berkeley DB the B-tree access method allows duplicates. This is a good choice if you need complex data types as keys. It’s also a great choice if data access patterns lead to access of contiguous or neighboring records. B-Tree keeps a substantial amount of metadata to perform efficiently. Most Berkeley DB applications use the B-Tree storage configuration.</li>
<li><strong>Hash. </strong>Like the B-Tree a hash also allows complex types to be keys. Hashes have a more linear structure as compared to a B-Tree. Berkeley DB hash structures allow duplicates.While both a B-Tree and a hash support complex keys, a hash database usually outperforms a B-Tree when the data set far exceeds the amount of available memory. That is because a B-Tree keeps more metadata than a hash and a larger data set implies that the B-Tree metadata may not fit in the in-memory cache. In such an extreme situation the B-Tree metadata as well as the actual data record itself will often have to be fetched from files, which can cause multiple I/Os per operation. The hash access method is designed to minimize the I/Os required to access the data record and therefore in these extreme cases, may perform better than a B-Tree.</li>
<li><strong>Queue. </strong>A queue is a set of sequentially stores fixed length records. Keys are restricted to logical record numbers, which are integer types. Records are appended sequentially allowing for extremely fast writes. If you are impressed by Apache Cassandra’s fast writes by appending to logs then give Berkeley DB with queue access method a try and you wouldn’t be disappointed. Methods also allow reading and updating effectively from the head of the queue. A queue has additional support for row-level locking. This allows effective transactional integrity even in cases of concurrent processing.</li>
<li><strong>Recno. </strong>Recno is similar to a queue but allows variable length records. And like a queue, recno keys are restricted to integers.</li>
</ul>
<p>The different configurations allow you to store arbitrary types of data in a collection. Similar to NoSQL, there is no fixed schema, other than those imposed by your model. In the extreme situation, you are welcome to store disparate value types for two keys in a collection. Value types can be complex classes, which for the sake of argument could represent a JSON document, a complex data structure or a structured data set. The only restriction really is that the value should be serializable to a byte array. A single key or a single value can be as large as 4GB.</p>
<p>The possibility of secondary indexes allows filtering on the basis of value properties. The primary database does not store data in a tabular format and so non-existing properties are not stored for sparse data sets. A secondary index skips all key-value pairs that lack the property on which the index is created. In general the storage is compact and efficient.</p>
<h3>Support for Transactions</h3>
<p>Berkeley DB is a very flexible database that can turn many features on and off. Berkeley DB can run without transaction support or it could be compiled to support ACID transactional integrity. Perhaps, the malleable nature of Berkeley DB makes it a very appropriate data store for many situations. Transactional integrity is the least supported feature in a quintessential NoSQL data store. Berkeley DB, in highly available systems, that don’t expect ACID transactional compliance can turn transactions off and work like a typical NoSQL product. However, in others it could be flexible and support transactional integrity.</p>
<p>While I don’t intend to cover details on transactions, it’s worth noting that like traditional RDBMS systems, Berkeley DB enabled with transactions allows definition of transactional boundaries. Once committed, data is persisted to disk. To enhance performance, one can use non-durable commits, where writes are committed to in-memory log files and later synched with the underlying file systems. Isolation levels and locking mechanisms are also supported.</p>
<p>Before a database is closed a sync operation assures that persistent file copies have up-to-date in-memory information in the system. The combination of this sync operation and Berkeley DB&#8217;s transactional recovery subsystem (assuming that you have enabled transactions) ensure that the database is always returned to a consistent transactional state, even in the event of application or system failure.</p>
<h3>Large Data Sets</h3>
<p>Theoretically Berkeley DB has an upper bound of 256TB but in real life it’s usually bound by the size of the machine it runs on. At the time of this writing, Berkeley DB does not demonstrate support for extremely large files that span multiple machines with the help of distributed file systems. (Files larger than the size of a single node can be managed with the help of distributed file systems like the Hadoop Distributed File System, or HDFS.) Berkeley DB works better on local file systems than it does on network file systems. More accurately, Berkeley DB relies on the POSIX compliant attributes of a file system. For example, when Berkeley DB calls fsync() and the file system returns, Berkeley DB assumes that the data has been written to persistent media. For performance reasons, distributed file systems typically do not guarantee that a write has been completed all the way to the persistent media.</p>
<p>The maximum B-Tree depth supported is 255. Lengths of the key and value records are typically bound by the available memory.</p>
<h3>Horizontal Scale-out</h3>
<p>Berkeley DB replication follows a master-slave pattern. In such a pattern there is one master and multiple slaves or replicas. However, the selection of a master is not static and it’s recommended that the selection is not manual. All participants in a replication cluster go through an election process to choose the master. The one with the most up-to-date log records is the winner. If there is a tie, then priorities are used to select the master. The election process is based on an industry standard <a href="http://en.wikipedia.org/wiki/Paxos_algorithm">Paxos-compliant algorithm</a>.</p>
<p>Replication has numerous benefits including the following:</p>
<ul>
<li>Improves read performance – The availability of multiple replicated nodes to read data from improves the read performance drastically.</li>
<li>Improves reliability – The presence of replicated instances provides better failover options in times of node failure and data corruption.</li>
<li>Improves durability – You can relax durability guarantees on the master to avoid excessive write to disk operations, which typically involves expensive I/O. In a clustered environment the durability is enhanced by the fact that the write has been committed to multiple nodes, even if it’s not written to disk.</li>
<li>Improves availability – The presence of multiple nodes, along with asynchronous write to disk, makes it possible for replicas to keep serving operations even when the master is under heavy load.</li>
</ul>
<h3>Summary</h3>
<p>Berkeley DB undoubtedly qualifies as a robust and scalable NoSQL key-value store; the use of Berkeley DB as the underlying storage for Amazon’s <a href="http://www.allthingsdistributed.com/2007/10/amazons_dynamo.html">Dynamo</a>, <a href="http://project-voldemort.com/">Project Voldemort</a>, <a href="http://memcachedb.org/">MemcacheDB</a>, and <a href="http://www.geniedb.com/">GenieDB</a> is further evidence supporting this claim. There has been a little bit of FUD around Berkeley DB performance, especially in the wake of couple of comparative benchmarks published online:</p>
<ul>
<li><a href="http://www.dmo.ca/blog/benchmarking-hash-databases-on-large-data/">http://www.dmo.ca/blog/benchmarking-hash-databases-on-large-data/</a></li>
<li><a href="http://stackoverflow.com/questions/601348/berkeleydb-vs-tokyo-cabinet">http://stackoverflow.com/questions/601348/berkeleydb-vs-tokyo-cabinet</a></li>
</ul>
<p>However, there are many live systems that prove Berkeley DB’s strengths. Many of these systems, through careful tuning and application coding improvements, have achieved excellent scalability, throughput, and reliability results. Following the lead of those systems, Berkeley DB can certainly be used as a scalable NoSQL solution.</p>
<hr /><strong>Shashank Tiwari </strong>is Founder &amp; CEO of <a href="http://www.treasuryofideas.com/">Treasury of Ideas</a>, a technology driven innovation and value optimization company. As an experienced software developer and architect, he is adept in a multitude of technologies. He is an internationally recognized speaker, author and mentor. As an expert group member on a number of JCP (Java Community Process) specifications he has been actively participating in shaping the future of Java. He is also an common voice in the NoSQL and Cloud Computing space and a recognized expert in the RIA community.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2011/02/using-oracle-berkeley-db-as-a-nosql-data-store/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Oracle Berkeley DB 产品家族介绍</title>
		<link>http://www.bdbchina.com/2010/09/oracle-berkeley-db-%e4%ba%a7%e5%93%81%e5%ae%b6%e6%97%8f%e4%bb%8b%e7%bb%8d/</link>
		<comments>http://www.bdbchina.com/2010/09/oracle-berkeley-db-%e4%ba%a7%e5%93%81%e5%ae%b6%e6%97%8f%e4%bb%8b%e7%bb%8d/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 05:45:49 +0000</pubDate>
		<dc:creator>haomianwang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Haomian Wang]]></category>
		<category><![CDATA[JE]]></category>
		<category><![CDATA[Mobile Sync Server]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=1336</guid>
		<description><![CDATA[Oracle Berkeley DB最先由加州大学伯克利分校为了移除受到AT&#38;T限制的dbm代码，而从BSD 4.3到4.4时所改写的。经过将近二十年的衍化，目前Oracle Berkeley DB家族已经发展到包含4个独立产品线 &#8211; Berkeley DB、Berkeley DB Java 版、Berkeley DB XML和Mobile Server，被应用到行行业业，在全球有超过2亿的部署。
本文将分别介绍Oracle Berkeley DB四大产品线的特点以及应用，希望能对中国市场的新老用户有所启发和帮助。

1. Oracle Berkeley DB数据库产品系列
（图一）
Oracle Berkeley DB 产品家族目前有三大数据库产品，分别是：Berkeley DB，Berkeley DB XML 和 Berkeley DB Java Edition。它们的关系和系统架构可以参照图一。下面我将分别进行介绍。
1.1 Berkeley DB
Berkeley DB 也称 Core（下文都以此简称），是Berkeley DB家族第一个发布的产品。Core的核心代码全部由C语言写成，同时提供其他多种语言的应用程序接口（包括 C++, C#,  Java, Perl, Python, PHP, Tcl, Ruby等等）。Core有以下一些特点（请大家注意，下面列举的大部分特点其实是Berkeley DB家族所有产品的共同特点）：

基于Key/Value的存储：对于Core以及Berkeley DB其他产品来说，用户可以任意定义所存储数据的键（key）以及对应的值（value），这样的数据存储方式具有很好的灵活性和多样性。也是由于这个特点，Berkeley DB产品家族被业界归为非关系型（non-relational）数据库。
嵌入式数据管理：这里的嵌入式跟大家平时提到的嵌入式有点不一样。这里的嵌入式的意思是指，Core是作为库（library）的形式直接嵌入到用户的应用程序当中，和用户程序运行到同一地址空间，用户选择适当的API进行编程调用。这样“嵌入式”的最大好处就是不需要人为进行管理（即不需要专门的DBA），并可以大大提高程序开发的周期，和降低程序后期的维护成本。
体积(footprint)小：由于Core是直接嵌入应用程序当中，所以产品的体积必须越小越好。目前，Core的体积只有1M左右，这意味着，即使对于移动设备（如手机）来说，Core也可以十分轻松嵌入到你的程序中。
几乎具备数据库的所有功能和特性：对于这么小体积的数据库，你也许会问，Core会不会丧失很多数据库的特性呢。恰恰相反，在保持小体积的优势下，Berkeley DB几乎具备数据库的所有特性，包括：ACID，事务性（transaction），错误恢复（failure recover），高并发性（high concurrency）等等。
高可用性（high availability，简称HA)：高可用性一方面可以提高数据读取性能，另一方面是具备自动错误恢复（automatic failover）功能，使数据存储更加安全可靠。
高性能：Core拥有极高的数据存取性能，并且用户可以根据机器的配置进行调优。具体性能测试可以参考文档  Oracle [...]]]></description>
			<content:encoded><![CDATA[<p>Oracle Berkeley DB最先由加州大学伯克利分校为了移除受到AT&amp;T限制的dbm代码，而从BSD 4.3到4.4时所改写的。经过将近二十年的衍化，目前Oracle Berkeley DB家族已经发展到包含4个独立产品线 &#8211; Berkeley DB、Berkeley DB Java 版、Berkeley DB XML和Mobile Server，被应用到行行业业，在全球有超过2亿的部署。</p>
<p>本文将分别介绍Oracle Berkeley DB四大产品线的特点以及应用，希望能对中国市场的新老用户有所启发和帮助。</p>
<p><span id="more-1336"></span></p>
<h1>1. Oracle Berkeley DB数据库产品系列</h1>
<p style="text-align: center;"><a href="http://www.bdbchina.com/wp-content/uploads/2010/09/bdb11gr21.png"><img class="aligncenter size-full wp-image-1416" style="margin-top: 10px; margin-bottom: 10px;" title="bdb11gr2" src="http://www.bdbchina.com/wp-content/uploads/2010/09/bdb11gr21.png" alt="" width="595" height="304" /></a>（图一）</p>
<p>Oracle Berkeley DB 产品家族目前有三大数据库产品，分别是：Berkeley DB，Berkeley DB XML 和 Berkeley DB Java Edition。它们的关系和系统架构可以参照<strong>图一</strong>。下面我将分别进行介绍。</p>
<h2><strong>1.1 Berkeley DB</strong></h2>
<p>Berkeley DB 也称 Core（下文都以此简称），是Berkeley DB家族第一个发布的产品。Core的核心代码全部由C语言写成，同时提供其他多种语言的应用程序接口（包括 C++, C#,  Java, Perl, Python, PHP, Tcl, Ruby等等）。Core有以下一些特点（请大家注意，下面列举的大部分特点其实是Berkeley DB家族所有产品的共同特点）：</p>
<ul>
<li><strong>基于Key/Value的存储</strong>：对于Core以及Berkeley DB其他产品来说，用户可以任意定义所存储数据的键（key）以及对应的值（value），这样的数据存储方式具有很好的灵活性和多样性。也是由于这个特点，Berkeley DB产品家族被业界归为非关系型（non-relational）数据库。</li>
<li><strong>嵌入式数据管理：</strong>这里的嵌入式跟大家平时提到的嵌入式有点不一样。这里的嵌入式的意思是指，Core是作为库（library）的形式直接嵌入到用户的应用程序当中，和用户程序运行到同一地址空间，用户选择适当的API进行编程调用。这样“嵌入式”的最大好处就是不需要人为进行管理（即不需要专门的DBA），并可以大大提高程序开发的周期，和降低程序后期的维护成本。</li>
<li><strong>体积(footprint)小：</strong>由于Core是直接嵌入应用程序当中，所以产品的体积必须越小越好。目前，Core的体积只有1M左右，这意味着，即使对于移动设备（如手机）来说，Core也可以十分轻松嵌入到你的程序中。</li>
<li><strong>几乎具备数据库的所有功能和特性：</strong>对于这么小体积的数据库，你也许会问，Core会不会丧失很多数据库的特性呢。恰恰相反，在保持小体积的优势下，Berkeley DB几乎具备数据库的所有特性，包括：ACID，事务性（transaction），错误恢复（failure recover），高并发性（high concurrency）等等。</li>
<li><strong>高可用性（high availability，简称HA)：</strong>高可用性一方面可以提高数据读取性能，另一方面是具备自动错误恢复（automatic failover）功能，使数据存储更加安全可靠。</li>
<li><strong>高性能：</strong>Core拥有极高的数据存取性能，并且用户可以根据机器的配置进行调优。具体性能测试可以参考文档 <a href="http://www.oracle.com/technology/products/berkeley-db/pdf/berkeley-db-perf.pdf" target="_blank"> Oracle Berkeley DB:Performance Metrics and Benchmarks</a>。</li>
</ul>
<p>尤其需要指出的是：最新版本的Oracle Berkeley DB（11gR2）的一个引人瞩目的特性就是我们引入了对SQL 92标准的支持（见图一红色圆圈部分）。Oracle Berkeley DB SQL接口完全兼容SQLite原有的编程接口， 从而以往运行在SQLite上的程序和应用都可以无缝的、方便的迁移到Oracle Berkeley DB这个更加强大的存储引擎。并且，Oracle Berkeley DB和SQLite还将进行长期的官方层面的合作，保证了Oracle Berkeley DB的SQL接口和SQLite保持一致，免除了用户的后顾之忧。此外，Berkeley DB SQL接口完美支持很多第三方的SQLite工具，如JDBC，ODBC，FireFox 3及其SQLite Manager 插件等。更多有关DBSQL的技术细节，可以参考本站另外一篇博客《<a href="http://www.bdbchina.com/2010/03/oracle-berkeley-db-%e6%94%af%e6%8c%81sql%e5%95%a6%ef%bc%81/" target="_blank">Oracle Berkeley DB 支持SQL啦</a>》。</p>
<p>也许有人会问：何时该选用BDB的Key/Value的选项，何时该选用BDB的SQL接口呢？</p>
<ul>
<li>简单的来理解，BDB的Key/Value的选项是一个本地持久化的“HashTable”，可以存取任何数据类型（声音、视频、图像、Java对象等），通过简单的put/get/delete接口来操作。简单的数据访问方式、不需要太多复杂的统计和分析计算的场合都可以使用。比如，微博客的底层数据管理；如果再和hadoop集成后，还可以做一些复杂的分析功能。</li>
</ul>
<ul>
<li>当使用场合需要轻量级的数据库、有SQL支持、要求高性能和高并发；或者需要和企业端的Oracle 数据库（如Oracle 11g）进行双向的数据同步时，建议可选用Oracle Berkeley DB的SQL接口。举例来说，手持设备/平台上（如Android，Windows Mobile、iPhone等）。</li>
</ul>
<p>更多关于Core的信息，可以参考下面相关链接：</p>
<ul>
<li><a href="http://www.oracle.com/technology/software/products/berkeley-db/index.html" target="_blank">Core下载</a></li>
<li><a href="http://www.oracle.com/technology/documentation/berkeley-db/db/index.html" target="_blank">Core相关文档</a></li>
<li><a href="http://www.oracle.com/technology/products/berkeley-db/faq/db_faq.html" target="_blank">Core FAQ</a> （可以在此找到常见问题答案）</li>
<li><a href="http://forums.oracle.com/forums/forum.jspa?forumID=271" target="_blank">Core官方论坛</a> （在此论坛提出技术问题，会得到Berkeley DB组资深工程师的回答，当然，提问必须是英文。）</li>
<li><a href="http://forums.oracle.com/forums/forum.jspa?forumID=272" target="_blank">Core HA官方论坛</a></li>
</ul>
<h2><strong>1.2 Berkeley DB XML</strong></h2>
<p>Berkeley DB XML是基于Core数据存取之上，专门用于存取XML文档的数据库（如图一所示），简而言之，Berkeley DB XML以Core作为存储引擎，在此基础上建立对XML文档进行管理、索引和查询优化模块，并提供相应的XML 标准的API。因为Berkeley DB XML建立在Core之上，所以除了具备Core的大部分特点之外，还有以下针对XML文档的一些特点：</p>
<ul>
<li><strong>支持XQuery 1.0 and XPath 2.0。</strong></li>
<li><strong>十分灵活的索引功能：</strong>Berkeley DB XML支持节点（node），element（元素），attribute（属性）和元数据（meta-data）索引。这样灵活的索引可以极大提高查找性能，特别是针对存取较大的XML文件。</li>
<li><strong>支持对XML文档的修改</strong></li>
</ul>
<p>更多关于Berkeley DB XML的信息，可以参考下面相关链接：</p>
<ul>
<li><a href="http://www.oracle.com/technology/software/products/berkeley-db/index.html" target="_blank">Berkeley DB XML下载</a></li>
<li><a href="http://www.oracle.com/technology/documentation/berkeley-db/xml/index.html" target="_blank">Berkeley DB XML相关文档</a></li>
<li><a href="http://www.oracle.com/technetwork/database/berkeleydb/xml-faq-088319.html" target="_blank">Berkeley DB XML FAQ</a></li>
<li><a href="http://forums.oracle.com/forums/forum.jspa?forumID=274" target="_blank">Berkeley DB XML官方论坛</a></li>
</ul>
<h2><strong>1.3 Berkeley DB Java Edition</strong></h2>
<p>Berkeley DB Java Edition（以下简称JE）是Berkeley DB产品家族另外一个独立的产品，也就是说，它并不像BDB XML一样基于BDB Core。JE 除了具备上述 Core 的特点（K/V存储、体积小、性能高以及高可用性（HA）等等）之外，还有以下特色：</p>
<ul>
<li><strong>纯java，简单易用：</strong>JE 是纯java语言编写的，意味着JE可以无缝运行于任何java环境。用户只需要在应用程序中包含JE的jar文件，便可调用JE的API进行编程，无需任何额外配置工作。</li>
<li><strong>更高的并发性，更高的性能：</strong>相对于Core，由于JE提供基于“记录”级别（record level，一条记录由Key和Value组成）的锁，所以JE拥有更高的并发性以及更高的读写性能。关于JE的性能测试，可以参考文档：
<ul>
<li><a href="http://www.oracle.com/technetwork/database/berkeleydb/je-derby-performance-130289.pdf" target="_blank">Oracle Berkeley DB Java Edition vs. Apache Derby: A Performance Comparison</a></li>
<li><a href="http://www.oracle.com/technetwork/database/berkeleydb/bdb-je-highavailability-whitepaper--129298.pdf" target="_blank">Oracle Berkeley DB Java Edition High Availability -Large Configuration and Scalability Testing</a></li>
</ul>
</li>
<li><strong>Java对象存储：</strong>JE 利用直接持久层（Direct Persistence Layer，DPL) 可以十分方便、灵活、快速存取用户定义的任意java对象。可参考文档<a href="http://www.oracle.com/technetwork/cn/database/berkeley-db/bdb-je-persistence-api-basics-133242-zhs.pdf?ssSourceSiteId=otnen" target="_blank">Direct Persistence Layer for Berkeley DB Java Edition</a>。</li>
<li><strong>适用于J2EE：</strong>JE 提供对Java Transaction API (JTA), J2EE Connector Architecture (JCA) 和 Java Management Extensions (JMX)的支持。</li>
</ul>
<p>更多关于JE的信息，可以参考下面相关链接：</p>
<ul>
<li><a href="http://www.oracle.com/technology/software/products/berkeley-db/index.html" target="_blank">JE下载</a></li>
<li><a href="http://www.oracle.com/technology/documentation/berkeley-db/je/index.html" target="_blank">JE相关文档</a></li>
<li><a href="http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html" target="_blank">JE FAQ</a></li>
<li><a href="http://forums.oracle.com/forums/forum.jspa?forumID=273" target="_blank">JE官方论坛</a></li>
</ul>
<h2><strong>1.4 应用举例</strong></h2>
<p>概括而言，你需要一个数据存取的产品，并要满足：</p>
<ul>
<li>性能要求高，相应时间短、占用资源少的场合</li>
<li>方便管理，不需要DBA</li>
<li>数据访问方式是简单的，任何类型的数据</li>
<li>运行于普通硬件平台，随着业务增长可以水平扩展</li>
<li>高可用集群和容错备份</li>
</ul>
<p>可能的应用场景包括：</p>
<ul>
<li>搜索及内容管理</li>
<li>缓存及日志模块</li>
<li>SOA及Web Service的相关模块</li>
<li>资源、系统或者仪器管理</li>
<li>存储设备</li>
<li>网关、网络设备、网络计费系统等</li>
<li>消息队列、工作流等系统</li>
<li>授权及身份管理</li>
<li>仪器、终端和手持设备</li>
</ul>
<p>举例而言：</p>
<ol>
<li>某全球知名电子商务公司，选择Core作为中间层的静态数据缓存。当用户浏览产品页面的时候，所有的产品信息、价格、用户评价等等数据都是先从Core进行读取。这样可以大大提高页面的显示时间，从而增进用户购物体验。同时还利用Core来管理购物车和交易结算等。</li>
<li>某全球著名互联网公司，利用Core HA存取数亿用户的账户信息。Core HA的高性能、高并发性和高可用性满足了此互联网公司对用户登录功能的苛刻要求，包括极短的登录请求响应时间，24×7的无间断服务，高达十亿级别的扩展性，以及极高的可靠性。</li>
<li>比如某知名手机公司推出的智能手机选择Berkeley DB SQL作为其底层数据库。某知名POS机厂商也选择 Berkeley DB SQL接口作为新推出的某款POS机的存储引擎。</li>
<li>某全球连锁酒店选择Berkeley DB XML来实现在线预定和销售系统。</li>
<li>某大型跨国企业选择Berkeley DB XML里进行资产和仪器管理。</li>
<li>很多全球型的金融公司的交易系统和底层基础架构的数据存取模块中选择Berkeley DB及Berkeley DB JE。</li>
<li>军方的战场实施动态监控系统选择Berkeley DB JE。</li>
<li>若干全球知名的社交网站中选择Berkeley DB JE构建上千个节点的云计算方案。</li>
<li>某全球知名的网络服务商的视频点播、短信/邮件、视频电话等系统中。</li>
</ol>
<h1>2. Oracle Berkeley DB 11gR2 + Mobile Server</h1>
<p style="text-align: center;"><a href="http://www.bdbchina.com/wp-content/uploads/2010/07/BDB_MobileServer.png"><img class="aligncenter size-full wp-image-1340" style="margin-top: 10px; margin-bottom: 10px;" title="BDB_MobileServer" src="http://www.bdbchina.com/wp-content/uploads/2010/07/BDB_MobileServer.png" alt="" width="561" height="331" /></a>（图二）</p>
<p style="text-align: left;">Oracle Berkeley DB 11gR2 + Mobile Server 可以提供移动数据同步解决方案。Oracle Mobile Sync Server（以下简称为Mobile Server）是一个提供企业级移动解决方案的中间层（middle-tier infrastructure）。它的一端连接的是客户端数据库，另外一端连接的是Oracle数据库。Mobile Server主要提供以下功能：</p>
<ol>
<li>应用程序统一部署和配置。比如，应用Mobile Server方案的移动设备都可以自动实现软件的安装、更新和打补丁等等配置，这一过程不需要用户的过多参与。</li>
<li>移动设备统一管理。管理员可以远程收集众多移动设备的信息，同时也可以进行统一的操作与部署。比如，管理员可以远程向丢失的移动设备进行额外加密或者销毁设备中的数据。</li>
<li>移动设备与Oracle数据库的数据双向同步。与Oracle数据库的同步功能可以保持移动设备的完整性和及时性，并且不要求移动设备时刻与Oracle数据库保持连接。</li>
</ol>
<p>在Oracle Berkeley DB 11gR2之前，Mobile Server支持的客户端数据库是Oracle Database Lite Client。往后Oracle Berkeley DB 11gR2 会是Mobile Server客户端数据库的推荐选择，而原来的Oracle Database Lite Client将停止新功能开发。因为Berkeley DB 11gR2安装更加简单，性能更加优越，并且体积更小。Berkeley DB 11gR2 + Mobile Server的总体架构图如<strong>图二</strong>所示。</p>
<p>Oracle Mobile Server 的应用举例：</p>
<ol>
<li>某国的海岸卫队的舰船上的数据同步和设备管理。</li>
<li>某大型的博彩机构的手机订单系统。</li>
<li>某国海关的缉私等设备上。</li>
<li>某大型快速消费品公司的自动售货机上。</li>
</ol>
<p>更多关于Oracle Mobile Sync Server的信息，可以参考下面相关链接：</p>
<ul>
<li><a href="http://www.oracle.com/technetwork/database/database-lite/overview/index.html" target="_blank">Oracle Database Lite 10g</a></li>
<li><a href="http://www.oracle.com/technetwork/database/database-lite/lite-mobile-server-083863.html" target="_blank">Oracle Database Lite Mobile Server 10g</a></li>
</ul>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1562px; width: 1px; height: 1px; overflow: hidden;">- 性能要求高，资源少的场合 （如任务密集型的应用，像工作流、规则引擎、队<br />
列、SOA事件管理和监控、网站缓存等）<br />
- 方便管理，不需要dba （如仪器、设备，像手机，汽车、医疗设备等）<br />
- 数据管理/访问方式是简单的，面向对象的 （如Twitter， facebook等，只需要<br />
简单、高效的插入和删除操作；不需要很多复杂的分析和统计功能）<br />
- 运行于普通硬件平台，随着业务增长可以水平扩展的 (如云计算、金融系统等）</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2010/09/oracle-berkeley-db-%e4%ba%a7%e5%93%81%e5%ae%b6%e6%97%8f%e4%bb%8b%e7%bb%8d/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Berkeley DB XML 多线程添加文档例子</title>
		<link>http://www.bdbchina.com/2010/03/berkeley-db-xml-%e5%a4%9a%e7%ba%bf%e7%a8%8b%e6%b7%bb%e5%8a%a0%e6%96%87%e6%a1%a3%e4%be%8b%e5%ad%90/</link>
		<comments>http://www.bdbchina.com/2010/03/berkeley-db-xml-%e5%a4%9a%e7%ba%bf%e7%a8%8b%e6%b7%bb%e5%8a%a0%e6%96%87%e6%a1%a3%e4%be%8b%e5%ad%90/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 06:56:02 +0000</pubDate>
		<dc:creator>蔡瀛</dc:creator>
				<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Ying Cai]]></category>
		<category><![CDATA[蔡瀛]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=809</guid>
		<description><![CDATA[
import java.io.File;
import java.util.concurrent.CountDownLatch;

import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.db.LockDetectMode;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlContainerConfig;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlDocumentConfig;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlManagerConfig;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlTransaction;
import com.sleepycat.dbxml.XmlUpdateContext;

public class DbxmlThreads extends Thread {

        public static XmlManager mgr = null;
        public static String containerName = "test.dbxml";
        [...]]]></description>
			<content:encoded><![CDATA[<pre name="code" class="java:nogutter">
import java.io.File;
import java.util.concurrent.CountDownLatch;

import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.db.LockDetectMode;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlContainerConfig;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlDocumentConfig;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlManagerConfig;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlTransaction;
import com.sleepycat.dbxml.XmlUpdateContext;

public class DbxmlThreads extends Thread {

        public static XmlManager mgr = null;
        public static String containerName = "test.dbxml";
        public static Environment dbEnv = null;
        private static XmlContainer cont = null;

        static {
                EnvironmentConfig envConf = new EnvironmentConfig();
                envConf.setThreaded(true);
                envConf.setAllowCreate(true);
                envConf.setTransactional(true);
                envConf.setInitializeCache(true);
                envConf.setInitializeLocking(true);
                envConf.setInitializeLogging(true);
                envConf.setCacheSize(64 * 1024 * 1024);
                envConf.setLockDetectMode(LockDetectMode.DEFAULT);

                XmlManagerConfig xmlMgrConfig = new XmlManagerConfig();
                xmlMgrConfig.setAdoptEnvironment(true);

                File dbHome = new File(".");

                try {
                        dbEnv = new Environment(dbHome, envConf);
                        mgr = new XmlManager(dbEnv, xmlMgrConfig);

                        // 创建XmlContainer
                        if(mgr.existsContainer(containerName)!=0)
                                mgr.removeContainer(containerName);

                        XmlContainerConfig containerConf = new XmlContainerConfig();
                        containerConf.setTransactional(true);
                        containerConf.setAllowCreate(true);
                        containerConf.setContainerType(XmlContainer.NodeContainer);
                        cont = mgr.openContainer(containerName, containerConf);
                        cont.setAutoIndexing(false);
                } catch (Exception e) {
                        e.printStackTrace();
                }

        }

        private String name;
        private CountDownLatch doneSignal;

        DbxmlThreads(String name, CountDownLatch doneSignal) {
                this.name = name;
                this.doneSignal = doneSignal;
        }

        public void run() {
                XmlTransaction txn = null;
                try {
                        String content = "<"+name+">I am "+name+"</"+name+">";
                        for (int i = 0; i < 100; i++) {
                                XmlDocumentConfig dc = new XmlDocumentConfig();
                                dc.setGenerateName(true);
                                System.out.println(name+" insert "+i);
                                txn = mgr.createTransaction();

                                XmlDocument doc = mgr.createDocument();
                                doc.setContent(content);
                                cont.putDocument(txn, doc, dc);

                                txn.commit();
                        }
                } catch (XmlException e) {
                        System.out.println("insert error:" + e.getMessage());
                } finally {
                        doneSignal.countDown();
                }
        }

        public static void main(String[] args) throws Exception {

                CountDownLatch doneSignal = new CountDownLatch(5);
                DbxmlThreads threadA = new DbxmlThreads("A", doneSignal);
                DbxmlThreads threadB = new DbxmlThreads("B", doneSignal);
                DbxmlThreads threadC = new DbxmlThreads("C", doneSignal);
                DbxmlThreads threadD = new DbxmlThreads("D", doneSignal);
                DbxmlThreads threadE = new DbxmlThreads("E", doneSignal);

                threadA.start();
                threadB.start();
                threadC.start();
                threadD.start();
                threadE.start();

                doneSignal.await();

                XmlQueryContext qc = mgr.createQueryContext();
                String query = "collection('"+containerName+"')/A";
                XmlResults res = mgr.query(query, qc);
                System.out.println("The results size is: "+res.size());
                res.delete();
                cont.close();
                mgr.close();
        }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2010/03/berkeley-db-xml-%e5%a4%9a%e7%ba%bf%e7%a8%8b%e6%b7%bb%e5%8a%a0%e6%96%87%e6%a1%a3%e4%be%8b%e5%ad%90/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>欢迎加入Berkeley DB群@LinkedIn</title>
		<link>http://www.bdbchina.com/2010/02/%e6%ac%a2%e8%bf%8e%e5%8a%a0%e5%85%a5berkeley-db%e7%be%a4linkedin/</link>
		<comments>http://www.bdbchina.com/2010/02/%e6%ac%a2%e8%bf%8e%e5%8a%a0%e5%85%a5berkeley-db%e7%be%a4linkedin/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 13:19:01 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[bdb]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=791</guid>
		<description><![CDATA[首先祝各位访客新年快乐，虎年富贵吉祥！
Oracle Berkeley DB在LinkedIn.com上的新建了一个群，供全球的相关人士（包括工程师、产品经理、客户等）共同讨论Berkeley DB的话题和业界动态。群地址：http://www.linkedin.com/groups?gid=2131985. 欢迎加入！
Oracle Berkeley DB 中国研发团队
]]></description>
			<content:encoded><![CDATA[<p>首先祝各位访客新年快乐，虎年富贵吉祥！</p>
<p>Oracle Berkeley DB在LinkedIn.com上的新建了一个群，供全球的相关人士（包括工程师、产品经理、客户等）共同讨论Berkeley DB的话题和业界动态。群地址：<a href="http://www.linkedin.com/groups?gid=2131985">http://www.linkedin.com/groups?gid=2131985</a>. 欢迎加入！</p>
<p>Oracle Berkeley DB 中国研发团队</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2010/02/%e6%ac%a2%e8%bf%8e%e5%8a%a0%e5%85%a5berkeley-db%e7%be%a4linkedin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Berkeley DB三大产品收费模式</title>
		<link>http://www.bdbchina.com/2009/11/berkeley-db%e4%b8%89%e5%a4%a7%e4%ba%a7%e5%93%81%e6%94%b6%e8%b4%b9%e6%a8%a1%e5%bc%8f/</link>
		<comments>http://www.bdbchina.com/2009/11/berkeley-db%e4%b8%89%e5%a4%a7%e4%ba%a7%e5%93%81%e6%94%b6%e8%b4%b9%e6%a8%a1%e5%bc%8f/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 08:21:58 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[bdb]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=711</guid>
		<description><![CDATA[众所周知，Berkeley DB是开源的，个人用户可以下载做学习、试用。但实际上，Berkeley DB是Oracle的一个产品，也是要收费的。
英文好的同学，可以读一下我们的授权申明：http://www.oracle.com/technology/software/products/berkeley-db/htdocs/licensing.html。
英文不好的同学，我在此可以稍作解释（强调：我的观点仅作参考，Oracle公司拥有最终解释权）：
1.  Berkeley DB产品家族三大产品（BDB，BDB-JE和BDB-XML）都是采取双license的授权模式，即开源（免费使用）和商用（付费使用）两种模式。
2. 衡量两种授权模式的一个主要区别是 &#8211; “redistribute”，意即你是否将自己的应用程序（在你的应用中使用了BDB）发布给第三方，如客户，机构，附属机构，母公司，合作者，中间商，第三方的非营利组织等。
3. 举例子来说：

如果是个人用户做学习研究之用，可以选择开源授权，免费；


如果是个人用户在BDB上做一些应用，如果你的应用是开源发布的，可以选择开源授权（但要符合BSD、GPL等开源条款）；如果是闭源，需要选择商业授权；


如果是在公司的商用项目使用，需要选择商业授权，即付费；

如果大家再有问题，或者不确定，欢迎留言。版权保护，也是保护到每个IT从业人员。
&#8212;
附件： Oracle官方网站给出TimesTen和Berkeley DB 产品家族在美国市场参考价格（见下图）。
关于Oracle产品的价格清单，请浏览官方网址: http://www.oracle.com/corporate/pricing/pricelists.html. 
注意： 价格仅作参考，Oracle公司拥有最终解释权。
]]></description>
			<content:encoded><![CDATA[<p>众所周知，Berkeley DB是开源的，个人用户可以下载做学习、试用。但实际上，Berkeley DB是Oracle的一个产品，也是要收费的。</p>
<p>英文好的同学，可以读一下我们的授权申明：http://www.oracle.com/technology/software/products/berkeley-db/htdocs/licensing.html。</p>
<p>英文不好的同学，我在此可以稍作解释（<strong>强调：我的观点仅作参考，Oracle公司拥有最终解释权</strong>）：</p>
<p>1.  Berkeley DB产品家族三大产品（BDB，BDB-JE和BDB-XML）都是采取双license的授权模式，即开源（免费使用）和商用（付费使用）两种模式。</p>
<p>2. 衡量两种授权模式的一个主要区别是 &#8211; “<strong>redistribute</strong>”，意即你是否将自己的应用程序（在你的应用中使用了BDB）发布给第三方，如客户，机构，附属机构，母公司，合作者，中间商，第三方的非营利组织等。<span id="more-711"></span></p>
<p>3. 举例子来说：</p>
<ul>
<li>如果是个人用户做学习研究之用，可以选择开源授权，免费；</li>
</ul>
<ul>
<li>如果是个人用户在BDB上做一些应用，如果你的应用是开源发布的，可以选择开源授权（但要符合BSD、GPL等开源条款）；如果是闭源，需要选择商业授权；</li>
</ul>
<ul>
<li>如果是在公司的商用项目使用，需要选择商业授权，即付费；</li>
</ul>
<p>如果大家再有问题，或者不确定，欢迎留言。版权保护，也是保护到每个IT从业人员。</p>
<p>&#8212;</p>
<p><strong><em>附件： Oracle官方网站给出TimesTen和Berkeley DB 产品家族在美国市场参考价格（见下图）。</em></strong></p>
<div id="attachment_779" class="wp-caption aligncenter" style="width: 612px"><a href="http://www.bdbchina.com/wp-content/uploads/2009/11/BDB_price.png"><img class="size-full wp-image-779 " title="BDB Price" src="http://www.bdbchina.com/wp-content/uploads/2009/11/BDB_price.png" alt="Berkeley DB 价格清单" width="602" height="231" /></a><p class="wp-caption-text">Berkeley DB 价格清单</p></div>
<p><em>关于Oracle产品的价格清单，请浏览官方网址: http://www.oracle.com/corporate/pricing/pricelists.html. </em></p>
<p><em>注意： 价格仅作参考，Oracle公司拥有最终解释权。</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2009/11/berkeley-db%e4%b8%89%e5%a4%a7%e4%ba%a7%e5%93%81%e6%94%b6%e8%b4%b9%e6%a8%a1%e5%bc%8f/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>甲骨文中国(包括Berkeley DB)2010校招日程</title>
		<link>http://www.bdbchina.com/2009/10/%e7%94%b2%e9%aa%a8%e6%96%87%e4%b8%ad%e5%9b%bd%e5%8c%85%e6%8b%acberkeley-dbfy2010%e6%a0%a1%e6%8b%9b%e6%97%a5%e7%a8%8b/</link>
		<comments>http://www.bdbchina.com/2009/10/%e7%94%b2%e9%aa%a8%e6%96%87%e4%b8%ad%e5%9b%bd%e5%8c%85%e6%8b%acberkeley-dbfy2010%e6%a0%a1%e6%8b%9b%e6%97%a5%e7%a8%8b/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 06:37:50 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[Haomian Wang]]></category>
		<category><![CDATA[Linchun Sun]]></category>
		<category><![CDATA[campus]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=692</guid>
		<description><![CDATA[2010财年甲骨文(中国)校园招聘大致流程：
校园宣讲 -&#62; 在线申请 -&#62; 在线测试（涵盖：技术、性格、英文等）-&#62; 初步筛选 -&#62; 邀请合格同学on-site 笔试和面试 -&#62; 进一步筛选 -&#62; 发offer
校园宣讲会初步日程（注意：日期及时间请以51job和校园广告为准）：

Oct. 19th Shanghai Tongji Univ. (19:00-21:00)
Oct. 20th Shenzhen HIT Graduate School (19:00-21:00)
Oct. 21th Guangzhou Southern China Univ. of Tech. (15:00-17:00)
Oct. 26th Beijing Tsinghua Univ. (19:00-21:00)
Oct. 27th Wuhan Huazhong Univ. of Science and Tech. (19:00-21:00)
Oct. 30th Hangzhou Zhejing Univ. (19:00-21:00)
Nov. 2nd Suzhou Suzhou Univ. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>2010财年甲骨文(中国)校园招聘大致流程：</strong><br />
校园宣讲 -&gt; 在线申请 -&gt; 在线测试（涵盖：技术、性格、英文等）-&gt; 初步筛选 -&gt; 邀请合格同学on-site 笔试和面试 -&gt; 进一步筛选 -&gt; 发offer</p>
<p><strong>校园宣讲会初步日程（注意：日期及时间请以51job和校园广告为准）：</strong></p>
<ul>
<li>Oct. 19th Shanghai Tongji Univ. (19:00-21:00)</li>
<li>Oct. 20th Shenzhen HIT Graduate School (19:00-21:00)</li>
<li>Oct. 21th Guangzhou Southern China Univ. of Tech. (15:00-17:00)</li>
<li>Oct. 26th Beijing Tsinghua Univ. (19:00-21:00)</li>
<li>Oct. 27th Wuhan Huazhong Univ. of Science and Tech. (19:00-21:00)</li>
<li>Oct. 30th Hangzhou Zhejing Univ. (19:00-21:00)</li>
<li>Nov. 2nd Suzhou Suzhou Univ. (14:00-16:00)</li>
<li>Nov. 4th Nanjing Southest Univ.(19:00-21:00)</li>
<li>Nov. 5th Dalian Dalian Univ. of Tech. (19:00-21:00)</li>
</ul>
<p><strong><span style="color: red">更新！！原计划于Nov.  6th的在线测试，因后台录入部分同学的纸质简历而推迟。新的时间安排：HR给的反馈是定在本周（Nov. 9th这周末或者周末以前），请大家留意Email通知并谅解。</span></strong></p>
<p><strong><span style="color: red">注: BDB的招聘行程（此项会持续更新，期待届时与你见面交流）</span></strong>：</p>
<ul>
<li>Chao Huang &#8211; 校园宣讲，Oct. 19th Shanghai Tongji Univ. (19:00-21:00)</li>
<li>Eric Wang &#8211; 校园宣讲，Oct. 20th Shenzhen HIT Graduate School (19:00-21:00)</li>
</ul>
<p>今年Oracle会组织在多个城市进行面试，BDB初步决定参加下面4个。各位面试同学的时间地点请以电话通知为准。</p>
<ul>
<li>Eric Wang &#8211; 面试官，Nov. 17-18，深圳</li>
<li>Linchun Sun &#8211; 面试官，Nov. 19-20，广州</li>
<li>Chao Huang &#8211; 面试官，Nov. 25-27，北京</li>
<li>Chao Huang &#8211; 面试官，Nov. 24-25，上海</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2009/10/%e7%94%b2%e9%aa%a8%e6%96%87%e4%b8%ad%e5%9b%bd%e5%8c%85%e6%8b%acberkeley-dbfy2010%e6%a0%a1%e6%8b%9b%e6%97%a5%e7%a8%8b/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>采用Berkeley DB XML PHP建立原生XML Web服务器</title>
		<link>http://www.bdbchina.com/2009/10/%e9%87%87%e7%94%a8berkeley-db-xml-php%e5%bb%ba%e7%ab%8b%e5%8e%9f%e7%94%9fxml-web%e6%9c%8d%e5%8a%a1%e5%99%a8/</link>
		<comments>http://www.bdbchina.com/2009/10/%e9%87%87%e7%94%a8berkeley-db-xml-php%e5%bb%ba%e7%ab%8b%e5%8e%9f%e7%94%9fxml-web%e6%9c%8d%e5%8a%a1%e5%99%a8/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 05:58:39 +0000</pubDate>
		<dc:creator>赵汝聪</dc:creator>
				<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[赵汝聪]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=618</guid>
		<description><![CDATA[近十年来，XML应用越发广泛，政府也推出了《基于XML的电子公文格式规范》等标准。那么，在需要XML数据库引擎的情况下，采用原生XML数据库Berkeley DB XML(以下简称BDB XML)取代MySQL(或其它传统DB)做后台数据库是一个更好的选择。
BDB XML是Oracle推出的一款开源原生XML数据库。与传统数据库相比，原生XML数据库的优势有：
1. 可以直接操作XML文件，XML数据无损&#8211;在某些场合，无损的数据源意味着法律效力。
2. 原生检索方式，支持XQuery和XPath，符合XML习惯。
3. 性能优化：原生XML数据库会针对XML特点进行各种优化，如插入文档索引、建立节点ID等。
4. 支持相同数据的不同视图。
和其它原生XML数据库相比，BDB XML优势有：
1. 完整的ACID 事务处理、自动恢复、热备份、用于分布式事务的HA支持。
2. 支持XQuery(含XQuery Update)和XPATH。
3. 可以利用其特有的二进制元数据存取大容量二进制对象(非XML数据)。
4. 支持全Unicode字符集，中文存储、查询都不成问题。
5. 提供一套容器和迭代器接口访问和操作查询结果。
6. 提供交互式命令行工具。

以上第三点是一个非常实用的特性，某种程度上它补足了XML应用的”最后一公里“：比方说，你正在为教育部门开发一个考生管理数据库，需要将考生的资料存成XML文档，那么存取照片(二进制数据)就相当麻烦。一般来讲传统的选择有两种：一是转换为Base64Binary格式嵌入到XML文档中，这意味着存取两端都需要转换大量图片数据，效率就很低下;二是为每个照片生成一个引用再另存它处，只在XML文档中保留一个引用，这种方法不但复杂，而且把数据从文档中分割了出来，损失了ACID特性，管理不便。而使用BDB XML就可以将照片数据直接以二进制元数据的形式嵌入到XML文档中，存取都非常方便，还可以基于数据库实现图像/视频检索。
下面，介绍一下BDB XML PHP的安装过程：
安装Apache+PHP环境
好吧，这是一个烂大街的话题，网上一抓一大把。下面以Debian 5.0和apache2为例：
用aptitude安装以下软件包：

apache2
libapache2-mod-php5
php5
php5-dev
php5-cgi
安装完毕。启动Apache服务器：
sudo /etc/init.d/apache2 start
测试一下是否安装成功，首先找到http的根目录(本机环境是/var/www)，在该目录下生成php测试文件test.php(内容如下)：
&#60;?phpinfo();?&#62;
用浏览器打开网页服务器的test.php，如果安装成功，会打开php信息页。
安装BDB XML PHP
移步http://www.oracle.com/technology/software/products/berkeley-db/xml/index.html下载源码包dbxml-2.5.13.tar.gz，并放置在$HOME目录下。下面以Linux上的安装为例：

cd $HOME
tar zxf dbxml-2.5.13.tar.gz
cd dbxml-2.5.13
./buildall
cd db-4.8.24/php_db4
phpize
./configure --with-db4=$PWD/../../install
make
sudo make install
cd ../../dbxml/src/php/
phpize
./configure --with-dbxml=$PWD/../../../install
make
sudo make install

接下来编辑/etc/php5/apache2/php.ini和/etc/php5/cgi/php.ini文件(可能路径略有不同)，把以下两行加到Dynamic Extensions段：
extension=db4.so
extension=dbxml.so
大功告成，为保安全，最好重启一下Apache服务器。到此BDB XML PHP全部安装成功。在实际应用中，需要特别注意帐户和权限问题：要保证Apache的运行帐户对容器(Container)文件及其所在目录有读写权限。
范例
从开心网的群共享页面http://www.kaixin001.com/group/file.php?gid=627784&#038;fid=450163&#038;start=0下载附件xmlData.tar.gz，解压后，将xmlData目录下的所有文件拷贝到http根目录下，然后执行：
./gen_cont.sh $HOME/dbxml-2.5.13/install/bin/dbxml
脚本即会生成一个容器：simple.dbxml。该容器内包含三百多个xml文档，形如：
&#60;?xml version="1.0"?&#62;
&#60;产品&#62;
    &#60;种类&#62;fruits&#60;/种类&#62;
    &#60;商品&#62;Avocado&#60;/商品&#62;
    &#60;存货&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<p>近十年来，XML应用越发广泛，政府也推出了《基于XML的电子公文格式规范》等标准。那么，在需要XML数据库引擎的情况下，采用原生XML数据库Berkeley DB XML(以下简称BDB XML)取代MySQL(或其它传统DB)做后台数据库是一个更好的选择。</p>
<p>BDB XML是Oracle推出的一款开源原生XML数据库。与传统数据库相比，原生XML数据库的优势有：<br />
1. 可以直接操作XML文件，XML数据无损&#8211;在某些场合，无损的数据源意味着法律效力。<br />
2. 原生检索方式，支持XQuery和XPath，符合XML习惯。<br />
3. 性能优化：原生XML数据库会针对XML特点进行各种优化，如插入文档索引、建立节点ID等。<br />
4. 支持相同数据的不同视图。</p>
<p>和其它原生XML数据库相比，BDB XML优势有：<br />
1. 完整的ACID 事务处理、自动恢复、热备份、用于分布式事务的HA支持。<br />
2. 支持XQuery(含XQuery Update)和XPATH。<br />
3. 可以利用其特有的二进制元数据存取大容量二进制对象(非XML数据)。<br />
4. 支持全Unicode字符集，中文存储、查询都不成问题。<br />
5. 提供一套容器和迭代器接口访问和操作查询结果。<br />
6. 提供交互式命令行工具。<br />
<span id="more-618"></span><br />
以上第三点是一个非常实用的特性，某种程度上它补足了XML应用的”最后一公里“：比方说，你正在为教育部门开发一个考生管理数据库，需要将考生的资料存成XML文档，那么存取照片(二进制数据)就相当麻烦。一般来讲传统的选择有两种：一是转换为Base64Binary格式嵌入到XML文档中，这意味着存取两端都需要转换大量图片数据，效率就很低下;二是为每个照片生成一个引用再另存它处，只在XML文档中保留一个引用，这种方法不但复杂，而且把数据从文档中分割了出来，损失了ACID特性，管理不便。而使用BDB XML就可以将照片数据直接以二进制元数据的形式嵌入到XML文档中，存取都非常方便，还可以基于数据库实现图像/视频检索。</p>
<p>下面，介绍一下BDB XML PHP的安装过程：</p>
<h2>安装Apache+PHP环境</h2>
<p>好吧，这是一个烂大街的话题，网上一抓一大把。下面以Debian 5.0和apache2为例：<br />
用aptitude安装以下软件包：</p>
<pre>
apache2
libapache2-mod-php5
php5
php5-dev
php5-cgi</pre>
<p>安装完毕。启动Apache服务器：</p>
<pre>sudo /etc/init.d/apache2 start</pre>
<p>测试一下是否安装成功，首先找到http的根目录(本机环境是/var/www)，在该目录下生成php测试文件test.php(内容如下)：</p>
<blockquote><p>&lt;?phpinfo();?&gt;</p></blockquote>
<p>用浏览器打开网页服务器的test.php，如果安装成功，会打开php信息页。</p>
<h2>安装BDB XML PHP</h2>
<p>移步http://www.oracle.com/technology/software/products/berkeley-db/xml/index.html下载源码包dbxml-2.5.13.tar.gz，并放置在$HOME目录下。下面以Linux上的安装为例：</p>
<pre>
cd $HOME
tar zxf dbxml-2.5.13.tar.gz
cd dbxml-2.5.13
./buildall
cd db-4.8.24/php_db4
phpize
./configure --with-db4=$PWD/../../install
make
sudo make install
cd ../../dbxml/src/php/
phpize
./configure --with-dbxml=$PWD/../../../install
make
sudo make install
</pre>
<p>接下来编辑/etc/php5/apache2/php.ini和/etc/php5/cgi/php.ini文件(可能路径略有不同)，把以下两行加到Dynamic Extensions段：</p>
<pre>extension=db4.so
extension=dbxml.so</pre>
<p>大功告成，为保安全，最好重启一下Apache服务器。到此BDB XML PHP全部安装成功。在实际应用中，需要特别注意帐户和权限问题：<span style="color: #ff0000;"><strong>要保证Apache的运行帐户对容器(Container)文件及其所在目录有读写权限。</strong></span></p>
<h2>范例</h2>
<p>从开心网的群共享页面http://www.kaixin001.com/group/file.php?gid=627784&#038;fid=450163&#038;start=0下载附件xmlData.tar.gz，解压后，将xmlData目录下的所有文件拷贝到http根目录下，然后执行：</p>
<pre>./gen_cont.sh $HOME/dbxml-2.5.13/install/bin/dbxml</pre>
<p>脚本即会生成一个容器：simple.dbxml。该容器内包含三百多个xml文档，形如：</p>
<pre>&lt;?xml version="1.0"?&gt;
&lt;产品&gt;
    &lt;种类&gt;fruits&lt;/种类&gt;
    &lt;商品&gt;Avocado&lt;/商品&gt;
    &lt;存货&gt;
        &lt;库存量单位&gt;AvocfruijfHs18&lt;/库存量单位&gt;
        &lt;价格&gt;0.24&lt;/价格&gt;
        &lt;存货&gt;393&lt;/存货&gt;
    &lt;/存货&gt;
    &lt;厂家&gt;Simply Fresh&lt;/厂家&gt;
&lt;/产品&gt;</pre>
<p>使用浏览器访问服务器上的simple.php页面，即可看到转换后输出的数据表。simple.php的内容如下：</p>
<pre>&lt;html&gt;
&lt;body&gt;
&lt;?
$contName = 'simple.dbxml'; // Container名字

// 创建Manager和Context
$mgr = new XmlManager();
$qc = $mgr-&gt;createQueryContext(); // Query Context
$qc-&gt;setDefaultCollection($contName); // 设置默认Container

// 打开Container
$cont = $mgr-&gt;openContainer($contName);

// 创建XQuery查询表达式，将数据提取出来并转换为html表格
$query = 'for $产品 in collection()/产品';
$query .= ' return &lt;tr&gt;';
$query .= '&lt;td&gt;{$产品/种类/string()}&lt;/td&gt;';
$query .= '&lt;td&gt;{$产品/商品/string()}&lt;/td&gt;';
$query .= '&lt;td&gt;{$产品/存货/价格/string()}&lt;/td&gt;';
$query .= '&lt;td&gt;{$产品/存货/存货/string()}&lt;/td&gt;';
$query .= '&lt;td&gt;{$产品/厂家/string()}&lt;/td&gt;';
$query .= '&lt;/tr&gt;';

// 输出表格头
?&gt;&lt;table width='100%' border='frame'&gt;
&lt;tr&gt;&lt;td&gt;种类&lt;/td&gt;&lt;td&gt;商品&lt;/td&gt;&lt;td&gt;价格&lt;/td&gt;&lt;td&gt;存货&lt;/td&gt;&lt;td&gt;厂家&lt;/td&gt;&lt;/tr&gt;&lt;?

// 查询并遍历结果，输出到表格
$results = $mgr-&gt;query($query, $qc);
while ($results-&gt;hasNext())
echo $results-&gt;next()-&gt;asString();

// 输出表格尾
?&gt;&lt;/table&gt;&lt;?
?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>可见，只需30余行的代码就能完成xml数据库到网页表格的转换。例图：<br />
<img src="http://www.bdbchina.com/wp-content/uploads/2009/10/bdb_xml_php_web.png" alt="bdb_xml_php_web" title="bdb_xml_php_web" width="500" height="500" class="alignnone size-full wp-image-641" /></p>
<h2>总结</h2>
<p>至此，我们已经介绍了BDB XML PHP的安装和使用。至于更多BDB XML功能，如二进制元数据、环境、事务、排序、索引等，请关注后续文章。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2009/10/%e9%87%87%e7%94%a8berkeley-db-xml-php%e5%bb%ba%e7%ab%8b%e5%8e%9f%e7%94%9fxml-web%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Berkeley DB (中国)2010校园招聘</title>
		<link>http://www.bdbchina.com/2009/09/berkeley-db-%e4%b8%ad%e5%9b%bd%e6%a0%a1%e5%9b%ad%e6%8b%9b%e8%81%98/</link>
		<comments>http://www.bdbchina.com/2009/09/berkeley-db-%e4%b8%ad%e5%9b%bd%e6%a0%a1%e5%9b%ad%e6%8b%9b%e8%81%98/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 06:45:55 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[bdb]]></category>
		<category><![CDATA[campus]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=594</guid>
		<description><![CDATA[重要：关于招聘的最新信息，请看：Oracle 2010 校招日程

各位2010届的毕业生同学，你们好！
你喜欢编程，擅长算法吗？你有志于开发数据库内核吗？欢迎你申请加入Berkeley DB全球研发团队。
关于我们及职位要求（见下图）：

Berkeley DB的全球客户（部分）：
重要! 如何申请：
我们将和Oracle其他部门一起，以校园招聘形式来进行。请大家届时留意本博客和Oracle的校园宣传广告、BBS等，然后登录Oracle的在线系统进行申请(网址：http://campus.oracle.cn)。申请时，请选择&#8221;Software Developer&#8221;, 并在系统注明你申请的是Oracle Berkeley DB（也作DB）开发工程师。
今年我们组的招聘名额是4个，地点在深圳。校园宣讲初步定于2009/10月。
]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: red">重要：关于招聘的最新信息，请看</span></strong>：<a title="Oracle 2010校招日程" href="http://www.bdbchina.com/2009/10/%e7%94%b2%e9%aa%a8%e6%96%87%e4%b8%ad%e5%9b%bd%e5%8c%85%e6%8b%acberkeley-dbfy2010%e6%a0%a1%e6%8b%9b%e6%97%a5%e7%a8%8b/" target="_blank">Oracle 2010 校招日程<br />
</a></p>
<p><strong>各位2010届的毕业生同学，你们好！</strong></p>
<p>你喜欢编程，擅长算法吗？你有志于开发数据库内核吗？欢迎你申请加入Berkeley DB全球研发团队。</p>
<p><strong>关于我们及职位要求（见下图）：</strong></p>
<div id="attachment_601" class="wp-caption aligncenter" style="width: 650px"><img class="size-full wp-image-601" title="职位要求" src="http://www.bdbchina.com/wp-content/uploads/2009/09/p1-small.png" alt="职位要求" width="640" height="476" /><p class="wp-caption-text">职位要求</p></div>
<p><span id="more-594"></span></p>
<p><strong>Berkeley DB的全球客户（部分）：</strong></p>
<div id="attachment_602" class="wp-caption aligncenter" style="width: 650px"><img class="size-full wp-image-602" title="商业客户" src="http://www.bdbchina.com/wp-content/uploads/2009/09/p2-small.png" alt="商业客户" width="640" height="484" /><p class="wp-caption-text">商业客户</p></div>
<div id="attachment_603" class="wp-caption aligncenter" style="width: 650px"><img class="size-full wp-image-603" title="开源应用" src="http://www.bdbchina.com/wp-content/uploads/2009/09/p3-small.png" alt="开源应用" width="640" height="480" /><p class="wp-caption-text">开源应用</p></div>
<p><strong>重要! 如何申请：</strong></p>
<p>我们将和Oracle其他部门一起，以校园招聘形式来进行。请大家届时留意本博客和Oracle的校园宣传广告、BBS等，然后登录Oracle的在线系统进行申请(网址：<strong>http://campus.oracle.cn</strong>)。申请时，<strong>请选择&#8221;Software Developer&#8221;</strong>, 并<strong>在系统注明</strong>你申请的是Oracle Berkeley DB（也作DB）开发工程师。</p>
<p>今年我们组的招聘名额是4个，地点在深圳。校园宣讲初步定于2009/10月。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2009/09/berkeley-db-%e4%b8%ad%e5%9b%bd%e6%a0%a1%e5%9b%ad%e6%8b%9b%e8%81%98/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>小奖品</title>
		<link>http://www.bdbchina.com/2009/09/%e5%b0%8f%e5%a5%96%e5%93%81/</link>
		<comments>http://www.bdbchina.com/2009/09/%e5%b0%8f%e5%a5%96%e5%93%81/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 03:11:56 +0000</pubDate>
		<dc:creator>chaohuang</dc:creator>
				<category><![CDATA[Berkeley DB]]></category>
		<category><![CDATA[Berkeley DB JE]]></category>
		<category><![CDATA[Berkeley DB XML]]></category>
		<category><![CDATA[Chao Huang]]></category>
		<category><![CDATA[bdb]]></category>

		<guid isPermaLink="false">http://www.bdbchina.com/?p=588</guid>
		<description><![CDATA[大家好！
BDB小礼物 &#8211; 若干2GB U盘（带Oracle Logo）
最近留意到我们BDB中国社区算是小有人气了，我们开发人员也十分开心。在此也感谢大家的支持。
我很努力争取到了一些U盘，用来奖励有兴趣为BDB做点事情的朋友。礼物虽不贵重，但希望大家理解，实是我们的一片心意。由于数量有限，先到先得吧。
重在人人参与
BDB的3个产品都是开源的，大家可以下载并研究源代码。有心的开发者，也可以把你自己写的示例程序、文章、使用心得、创意等发给我（chao.huang at oracle dot com）。每个入围的朋友都可以收到我们寄出的小奖品，并且获奖者会在bdbchina blog上公布。
我们鼓励每个人的参与，和大家分享你的才智，共同进步。同时，也期待能出现眼前一亮的创意(idea)，实现自己的事业成功。比如，由于BDB的非关系型数据库的特性，它很适合于用作基因测序等方面数据（基因节点，序列图等）的管理、在医疗监控仪器（大型仪器，小型的传感器等）等应用，等等。
]]></description>
			<content:encoded><![CDATA[<p>大家好！</p>
<p><strong>BDB小礼物 &#8211; 若干2GB U盘</strong>（带Oracle Logo）</p>
<p>最近留意到我们BDB中国社区算是小有人气了，我们开发人员也十分开心。在此也感谢大家的支持。</p>
<p>我很努力争取到了一些U盘，用来奖励有兴趣为BDB做点事情的朋友。礼物虽不贵重，但希望大家理解，实是我们的一片心意。由于数量有限，先到先得吧。</p>
<p><strong>重在人人参与</strong></p>
<p>BDB的3个产品都是开源的，大家可以下载并研究源代码。有心的开发者，也可以把你自己写的示例程序、文章、使用心得、创意等发给我（chao.huang at oracle dot com）。每个入围的朋友都可以收到我们寄出的小奖品，并且获奖者会在bdbchina blog上公布。</p>
<p>我们鼓励每个人的参与，和大家分享你的才智，共同进步。同时，也期待能出现眼前一亮的创意(idea)，实现自己的事业成功。比如，由于BDB的非关系型数据库的特性，它很适合于用作基因测序等方面数据（基因节点，序列图等）的管理、在医疗监控仪器（大型仪器，小型的传感器等）等应用，等等。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bdbchina.com/2009/09/%e5%b0%8f%e5%a5%96%e5%93%81/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
Դ
