Java 何时使用 JCR(内容存储库)而不是其他选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3908584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 06:42:04  来源:igfitidea点击:

When to use JCR (content repository) over other options?

javadatabasecontent-managementjcr

提问by Ither

I'm trying to evaluate content repositories (JSR283) like Hymanrabbitand ModeShapebut I must confess that I don't understand what problem resolves in first place and even if it is a good choice for the project. Which cases do you think is the best solution to apply? Is not the same thing as relational databases, except for the size? Why? Extra points for pointing real world examples.

我正在尝试评估像HymanrabbitModeShape这样的内容存储库(JSR283),但我必须承认,我不明白首先解决了什么问题,即使它是项目的一个不错的选择。您认为哪些案例是最适合应用的解决方案?和关系型数据库不一样,只是大小不一样?为什么?指向真实世界示例的额外积分。

Thanks in advance.

提前致谢。

采纳答案by Randall Hauch

JCR repositories are different than RDBMSes, because a JCR repository:

JCR 存储库与 RDBMS 不同,因为 JCR 存储库:

  • is hierarchical, allowing your to organize your content in a structure that closely matches your needs and where related information is often stored close together and thus easily navigated
  • is flexible, allowing the content to adapt and evolve, using a node type system that can be completely "schemaless" to full-on restrictive (e.g., like a relational database)
  • uses a standard Java API (e.g., javax.jcr)
  • abstracts where the information is really stored: many JCR implementations can store content in a variety of relational databases and other stores, some can expose non-JCR stores through the JCR API, and some can federate multiple stores into a single, virtual repository.
  • supports queries and full-text search out of the box
  • supports events, locking, versioning, and other features
  • 是分层的,允许您以与您的需求紧密匹配的结构组织您的内容,并且相关信息通常紧密存储在一起,因此易于导航
  • 是灵活的,允许内容适应和发展,使用可以完全“无模式”到完全限制的节点类型系统(例如,像关系数据库)
  • 使用标准的 Java API(例如,javax.jcr)
  • 抽象信息真正存储的位置:许多 JCR 实现可以将内容存储在各种关系数据库和其他存储中,有些可以通过 JCR API 公开非 JCR 存储,有些可以将多个存储联合到单个虚拟存储库中。
  • 支持开箱即用的查询和全文搜索
  • 支持事件、锁定、版本控制和其他功能

You certainly can build all or some of these features in your own application, but that likely gets further away from what your main purpose of your app.

您当然可以在自己的应用程序中构建所有或部分这些功能,但这可能与您的应用程序的主要目的相去甚远。

What kind of applications can benefit from these features? Content management systems have used repositories for a long time, and JCR (and Hymanrabbit) really grew out of the need for a common, standard API to access different content repositories (see JSR-170and JSR-283).

什么样的应用程序可以从这些功能中受益?内容管理系统已经使用存储库很长时间了,JCR(和 Hymanrabbit)的真正发展源于对访问不同内容存储库的通用标准 API 的需求(参见JSR-170JSR-283)。

Another example are document management systems, which manage electronic files (that are often images of paper documents) and provide search and query. DMSes have used repositories for some time.

另一个例子是文件管理系统,它管理电子文件(通常是纸质文件的图像)并提供搜索和查询。DMS 使用存储库已有一段时间了。

Artifact management systems can use repositories to manage digital artifacts (often files) along with additional information (metadata). JCR works great here, because you can store the metadata in the same location as the files: those that understand these extra properties can see them, those that don't care don't have to see them. I know Artifactoryis a Maven repository implementation that uses JCR. There are also repositories for managing web service artifacts, data service artifacts, and test artifacts.

工件管理系统可以使用存储库来管理数字工件(通常是文件)以及附加信息(元数据)。JCR 在这里工作得很好,因为您可以将元数据存储在与文件相同的位置:了解这些额外属性的人可以看到它们,不关心的人不必看到它们。我知道Artifactory是一个使用 JCR 的 Maven 存储库实现。还有用于管理 Web 服务工件、数据服务工件和测试工件的存储库。

But JCR repositories are not for managing files. JCR uses a simple notion of a hierarchy of nodes, where the nodes can contain named properties (with one or multiple values) and children. The properties and child node that are allowed are dictated entirely by node types, which can be changed and mixed in as needed on a node-by-node basis. JCR predefines some built-in node types that are commonly needed, like those used to represent files and folders in the repository. You can reuse these built-in types, extend them, or write your own. Many people advocate using mixins almost as facets or aspects, so that if a node needs to take on a facet you can simply add a mixin to the node.

但是 JCR 存储库不用于管理文件。JCR 使用节点层次结构的简单概念,其中节点可以包含命名属性(具有一个或多个值)和子项。允许的属性和子节点完全由节点类型决定,可以根据需要逐个节点地更改和混合。JCR 预定义了一些通常需要的内置节点类型,例如用于表示存储库中的文件和文件夹的节点类型。您可以重用这些内置类型、扩展它们或编写自己的类型。许多人提倡使用 mixin 几乎作为 facet 或 aspect,因此如果节点需要采用 facet,您可以简单地向节点添加 mixin。

JCR was designed to easily support importing XML content into the repository, where each element is mapped to a node and each attribute is mapped to an attribute. And lots of stuff is represented using XML (or YAML or JSON), and all of this can easily be represented and stored in a JCR repository. As an example, consider a JCR repository that stores configuration information (that might normally be stored in multiple XML files). JCR can version that information, allow access to it from multiple processes, enable querying and search, and notify the application(s) when content changes.

JCR 旨在轻松支持将 XML 内容导入存储库,其中每个元素映射到一个节点,每个属性映射到一个属性。很多东西都使用 XML(或 YAML 或 JSON)表示,所有这些都可以轻松表示并存储在 JCR 存储库中。例如,考虑一个存储配置信息(通常可能存储在多个 XML 文件中)的 JCR 存储库。JCR 可以对该信息进行版本控制,允许从多个进程访问它,启用查询和搜索,并在内容更改时通知应用程序。

There are several good overviews of JCR with more detail and examples. A few of these are:

有几个很好的 JCR 概述,其中包含更多详细信息和示例。其中一些是: