在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 the
repository API.
2.Dynamic extensibility:
Each repository object has a type. The repository information model is
a collection of the possible object types in the repository as well as
of the objects that implement those types. The repository engine allows
adding new types and extending existing types. In contrast to
relational databases, a repository information model, including type
information, is often implemented not as metadata, but as a collection
of first-class repository objects. As a result, a repository often has
no metadata in the sense of relational database metadata. This is
roughly analogous to how objects run in a Java virtual machine, for
instance: Type information is represented by first-class objects of the
typeClass, and the JVM associates non-Classobjects withClassobjects that define the object‘s type.
3.Relationship management:
While relational databases define entity relations between database
objects, they do so at the level of the database schema (metadata), not
in terms of actual database objects. By contrast, repositories allow
object relationships to be specified in terms of first-class objects
representing those relationships. For instance, twoPageobjects might be related via aLinkobject, denoting that one page links to another. BecauseLinkis a repository object, it can be associated with a rich object type:
For example, one describing a bi-directional link between the two
pages. A repository engine enforces referential integrity between
related objects.
4.Notification:
Objects both inside and outside the repository may listen to changes
occurring to repository objects. The repository engine dispatches
notifications as such changes take place.
5.Version management:
Most applications today require versioned data: Given a data item, an
application must be able to access the current as well as all past
versions of that data item. Neither relational nor object databases
provide standard, out-of-the-box versioning, leaving versioning chores
to each application accessing the data store. By contrast, keeping
track 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 to
several users or companies, or might comprise objects for several
software packages. Such repository object subsets are termed
configurations 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包含一个根节点。