了解JackRabbit和Java Content Repository API Part 1

来源:百度文库 编辑:神马文学网 时间:2024/04/28 21:16:30
http://www.artima.com/lejava/articles/contentrepository1.html
在Thomas名作《乌托邦》(Ultopia)中,作者描述了一个非常理想的世界,如果作者有幸生在今日,恐怕他的文章要增加一个章节:JCR了!JSR-170号称他们能够极大简化Java数据管理,并号称在五到十年的时间里,我们将基于仓库(Repository,注意不是数据仓库)进行编码而不是基于数据库。
 
 
商业的仓库产品同样在传统的数据库基础上实现的,也有基于文件系统的。所以,仓库通常是作为RDBMS和需要访问持久化数据的应用程序之间的一个连接。一个Repository通常包含一下几个组成部分:
 
1,  repository engine :用来管理仓库内容或者仓库对象。
 
2,  repository information model : 描述仓库的内容。
 
3,  repository API :允许应用称呼和repository engine交互并且提供查询或者修改repository information model的功能。
 
4,  可选,仓库会包含对于持久化的接口。
 
结构图如下:

 
这些功能比起传统的数据库(RDBMS)有什么优势呢?repository engine 提供了六个特性:
 
1.      Object management:Managing repository objects means storing a repository object‘s state.That state comprises the object‘s property and attribute values.Repositories typically allow applications to manage objects via therepository API.
 
2.      Dynamic extensibility:Each repository object has a type. The repository information model isa collection of the possible object types in the repository as well asof the objects that implement those types. The repository engine allowsadding new types and extending existing types. In contrast torelational databases, a repository information model, including typeinformation, is often implemented not as metadata, but as a collectionof first-class repository objects. As a result, a repository often hasno metadata in the sense of relational database metadata. This isroughly analogous to how objects run in a Java virtual machine, forinstance: Type information is represented by first-class objects of thetype Class, and the JVM associates non-Class objects with Class objects that define the object‘s type.
 
3.      Relationship management:While relational databases define entity relations between databaseobjects, they do so at the level of the database schema (metadata), notin terms of actual database objects. By contrast, repositories allowobject relationships to be specified in terms of first-class objectsrepresenting those relationships. For instance, two Page objects might be related via a Link object, denoting that one page links to another. Because Linkis a repository object, it can be associated with a rich object type:For example, one describing a bi-directional link between the twopages. A repository engine enforces referential integrity betweenrelated objects.
 
4.      Notification:Objects both inside and outside the repository may listen to changesoccurring to repository objects. The repository engine dispatchesnotifications as such changes take place.
 
5.      Version management:Most applications today require versioned data: Given a data item, anapplication must be able to access the current as well as all pastversions of that data item. Neither relational nor object databasesprovide standard, out-of-the-box versioning, leaving versioning choresto each application accessing the data store. By contrast, keepingtrack of versions, and making those versions available to applications,is an important repository feature.
 
6.      Configuration management:Applications often need to keep track of subsets of repository objects.For instance, a single repository might contain objects belonging toseveral users or companies, or might comprise objects for severalsoftware packages. Such repository object subsets are termedconfigurations or workspaces.
 
如果你的应用程序需要上述的功能特性,那么内容仓库可能很适合你。有很多仓库产品可供选择,通常,数据库厂商会附带repository组件。IDE和软件配置工具厂商通常也提供仓库产品。版本控制工具,如CVS或者Subversion,是另外一种特殊的仓库。很多开源的和商业的内容管理系统(Content Management System CMS)也是基于仓库的。现在,Jackrabbit,就是Apache的一个开源内容仓库。
 
 
在JCR API出现之前,各个内容仓库提供商提供它们自己的访问协议和API。JCR定义了厂商无关的独立Java API。允诺提供更简单的操作方式,甚至比JDBC访问RDBMS还要方便。
 
JCR information model
JCR定义了一个非常简单的数据模式层次,包含workspaces,没个workspace包含多个Items,Items是Node 或者Property。Node可以有子Node。Property是一个name-value对。一个workspace包含一个根节点。