Orientdb 简明教程
OrientDB - Basic Concepts
OrientDB 的主要功能是对多模型对象的支持,即支持文档、图、键/值和真实对象等不同的模型。它包含一个单独的 API 来支持这四个模型。
The main feature of OrientDB is to support multi-model objects, i.e. it supports different models like Document, Graph, Key/Value and Real Object. It contains a separate API to support all these four models.
Document Model
术语文档模型属于 NoSQL 数据库。这意味着数据存储在文档中,并且一组文档称为 Collection 。从技术上讲,文档表示一组键/值对,或称为字段或属性。
The terminology Document model belongs to NoSQL database. It means the data is stored in the Documents and the group of Documents are called as Collection. Technically, document means a set of key/value pairs or also referred to as fields or properties.
OrientDB 使用类、丛集和链接等概念来存储、分组和分析文档。
OrientDB uses the concepts such as classes, clusters, and link for storing, grouping, and analyzing the documents.
下表说明了关系模型、文档模型和 OrientDB 文档模型之间的比较 −
The following table illustrates the comparison between relational model, document model, and OrientDB document model −
Relational Model |
Document Model |
OrientDB Document Model |
Table |
Collection |
Class or Cluster |
Row |
Document |
Document |
Column |
Key/value pair |
Document field |
Relationship |
Not available |
Link |
Graph Model
图数据结构是一个数据模型,它可以以顶点(节点)的形式存储数据,顶点通过边(弧)相互连接。OrientDB 图数据库的构思源自属性图。顶点和边是图模型的主要组成部分。它们包含属性,这可以使它们看起来类似于文档。
A graph data structure is a data model that can store data in the form of Vertices (Nodes) interconnected by Edges (Arcs). The idea of OrientDB graph database came from property graph. The vertex and edge are the main artifacts of the Graph model. They contain the properties, which can make these appear similar to documents.
下表显示了图模型、关系数据模型和 OrientDB 图模型之间的比较。
The following table shows a comparison between graph model, relational data model, and OrientDB graph model.
Relational Model |
Graph Model |
OrientDB Graph Model |
Table |
Vertex and Edge Class |
Class that extends "V" (for Vertex) and "E" (for Edges) |
Row |
Vertex |
Vertex |
Column |
Vertex and Edge property |
Vertex and Edge property |
Relationship |
Edge |
Edge |
The Key/Value Model
键/值模型表示数据可以以键/值对的形式存储,其中值可以是简单类型和复杂类型。它可以支持文档和图形元素作为值。
The Key/Value model means that data can be stored in the form of key/value pair where the values can be of simple and complex types. It can support documents and graph elements as values.
下表说明了关系模型、键/值模型和 OrientDB 键/值模型之间的比较。
The following table illustrates the comparison between relational model, key/value model, and OrientDB key/value model.
Relational Model |
Key/Value Model |
OrientDB Key/Value Model |
Table |
Bucket |
Class or Cluster |
Row |
Key/Value pair |
Document |
Column |
Not available |
Document field or Vertex/Edge property |
Relationship |
Not available |
Link |
The Object Model
此模型由面向对象编程继承,并且支持类型(子类型扩展超类型)之间的 Inheritance 、类型指的是基础类时的 Polymorphism 以及编程语言中使用的对象来自/至的 Direct binding 。
This model has been inherited by Object Oriented programming and supports Inheritance between types (sub-types extends the super-types), Polymorphism when you refer to a base class and Direct binding from/to Objects used in programming languages.
下表说明了关系模型、对象模型和 OrientDB 对象模型之间的比较。
The following table illustrates the comparison between relational model, Object model, and OrientDB Object model.
Relational Model |
Object Model |
OrientDB Object Model |
Table |
Class |
Class or Cluster |
Row |
Object |
Document or Vertex |
Column |
Object property |
Document field or Vertex/Edge property |
Relationship |
Pointer |
Link |
在详细讨论之前,最好了解与 OrientDB 相关的基本术语。以下是一些重要的术语。
Before go ahead in detail, it is better to know the basic terminology associated with OrientDB. Following are some of the important terminologies.
Record
可以从数据库加载和存储的最小单位。记录可以存储在四种类型中。
The smallest unit that you can load from and store in the database. Records can be stored in four types.
-
Document
-
Record Bytes
-
Vertex
-
Edge
Record ID
当 OrientDB 生成记录时,数据库服务器会自动为该记录分配一个单元标识符,称为 RecordID (RID)。RID 看起来像 #<cluster>:<position>。 <cluster> 表示集群标识号,<position> 表示集群中记录的绝对位置。
When OrientDB generates a record, the database server automatically assigns a unit identifier to the record, called RecordID (RID). The RID looks like #<cluster>:<position>. <cluster> means cluster identification number and the <position> means absolute position of the record in the cluster.
Documents
文档是 OrientDB 中可用的最灵活的记录类型。文档是软类型,由具有定义约束的模式类定义,但你也可以在没有任何模式的情况下插入文档,即它也支持无模式模式。
The Document is the most flexible record type available in OrientDB. Documents are softly typed and are defined by schema classes with defined constraint, but you can also insert the document without any schema, i.e. it supports schema-less mode too.
文档可以通过 JSON 格式轻松地导出和导入。例如,看一看以下 JSON 示例文档。它定义了文档详细信息。
Documents can be easily handled by export and import in JSON format. For example, take a look at the following JSON sample document. It defines the document details.
{
"id" : "1201",
"name" : "Jay",
"job" : "Developer",
"creations" : [
{
"name" : "Amiga",
"company" : "Commodore Inc."
},
{
"name" : "Amiga 500",
"company" : "Commodore Inc."
}
]
}
RecordBytes
记录类型与 RDBMS 中的 BLOB 类型相同。OrientDB 可以加载和存储文档记录类型以及二进制数据。
Record Type is the same as BLOB type in RDBMS. OrientDB can load and store document Record type along with binary data.
Vertex
OrientDB 数据库不仅是文档数据库,也是图形数据库。使用顶点和边等新概念以图形的形式存储数据。在图形数据库中,最基本的数据单位是节点,在 OrientDB 中称为顶点。顶点为数据库存储信息。
OrientDB database is not only a Document database but also a Graph database. The new concepts such as Vertex and Edge are used to store the data in the form of graph. In graph databases, the most basic unit of data is node, which in OrientDB is called a vertex. The Vertex stores information for the database.
Edge
存在一种称为边(Edge)的独立记录类型,该类型将一个顶点连接到另一个顶点。边是双向的,并且只能连接两个顶点。OrientDB 中有两种类型的边,一种是常规的,另一种是轻量的。
There is a separate record type called the Edge that connects one vertex to another. Edges are bidirectional and can only connect two vertices. There are two types of edges in OrientDB, one is regular and another one lightweight.
Class
类是一种数据模型类型和从面向对象编程范例中汲取的概念。基于传统的文档数据库模型,数据以集合的形式存储,而在关系数据库模型中,数据存储在表中。OrientDB 遵循文档 API 以及 OPPS 范例。作为一个概念,OrientDB 中的类与关系数据库中的表的关系最密切,但是(与表不同)类可以是无模式的,全模式的或混合的。类可以继承自其他类,从而创建类的树。每个类都有自己的集群,(如果未定义,则默认创建)。
The class is a type of data model and the concept drawn from the Object-oriented programming paradigm. Based on the traditional document database model, data is stored in the form of collection, while in the Relational database model data is stored in tables. OrientDB follows the Document API along with OPPS paradigm. As a concept, the class in OrientDB has the closest relationship with the table in relational databases, but (unlike tables) classes can be schema-less, schema-full or mixed. Classes can inherit from other classes, creating trees of classes. Each class has its own cluster or clusters, (created by default, if none are defined).
Cluster
集群是一个重要的概念,用于存储记录、文档或顶点。简单来说,集群是存储一组记录的地方。默认情况下,OrientDB 将为每个类创建一个集群。一个类的所有记录都存储在具有与类同名的同一集群中。您可以在数据库中创建多达 32,767(2^15-1)个集群。
Cluster is an important concept which is used to store records, documents, or vertices. In simple words, Cluster is a place where a group of records are stored. By default, OrientDB will create one cluster per class. All the records of a class are stored in the same cluster having the same name as the class. You can create up to 32,767(2^15-1) clusters in a database.
CREATE class 是一条用于创建带有特定名称的集群的命令。创建集群后,您可以通过在创建任何数据模型期间指定名称来使用该集群来保存记录。
The CREATE class is a command used to create a cluster with specific name. Once the cluster is created you can use the cluster to save records by specifying the name during the creation of any data model.
Relationships
OrientDB 支持两种类型的关系:引用和嵌入。 Referenced relationships 表示其存储到关系目标对象的直接链接。 Embedded relationships 表示其存储到嵌入记录内的关系。这种关系比引用关系更强。
OrientDB supports two kinds of relationships: referenced and embedded. Referenced relationships means it stores direct link to the target objects of the relationships. Embedded relationships means it stores the relationship within the record that embeds it. This relationship is stronger than the reference relationship.
Database
数据库是访问真实存储的接口。它了解高级概念,例如查询、模式、元数据、索引等。OrientDB 还提供了多个数据库类型。有关这些类型的更多信息,请参阅数据库类型。
The database is an interface to access the real storage. IT understands high-level concepts such as queries, schemas, metadata, indices, and so on. OrientDB also provides multiple database types. For more information on these types, see Database Types.