Category: orientdb

  • Khóa học miễn phí OrientDB – Connect Database nhận dự án làm có lương

    OrientDB – Connect Database



    This chapter explains how to connect to a particular database from the OrientDB command line. It opens a database.

    The following statement is the basic syntax of the Connect command.

    CONNECT <database-url> <user> <password>
    

    Following are the details about the options in the above syntax.

    <database-url> − Defines the URL of the database. URL contains two parts one is <mode> and the second one is <path>.

    <mode> − Defines the mode, i.e. local mode or remote mode.

    <path> − Defines the path to the database.

    <user> − Defines the user you want to connect to the database.

    <password> − Defines the password for connecting to the database.

    Example

    We have already created a database named ‘demo’ in the previous chapters. In this example, we will connect to that using the user admin.

    You can use the following command to connect to demo database.

    orientdb> CONNECT PLOCAL:/opt/orientdb/databases/demo admin admin
    

    If it is successfully connected, you will get the following output −

    Connecting to database [plocal:/opt/orientdb/databases/demo] with user ''admin''…OK
    Orientdb {db = demo}>
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Info Database nhận dự án làm có lương

    OrientDB – Info Database



    This chapter explains how to get information of a particular database from the OrientDB command line.

    The following statement is the basic syntax of the Info command.

    info
    

    Note − You can use this command only after connecting to a particular database and it will retrieve the information of only the currently running database.

    Example

    In this example, we will use the same database named ‘demo’ that we created in the previous chapter. We will retrieve the basic information from demo database.

    You can use the following command to disconnect the database.

    orientdb {db = demo}> info
    

    If it is successfully disconnected, you will get the following output.

    Current database: demo (url = plocal:/opt/orientdb/databases/demo)
    
    DATABASE PROPERTIES
    --------------------------------+---------------------------------------------+
     NAME                           | VALUE                                       |
    --------------------------------+---------------------------------------------+
     Name                           | null                                        |
     Version                        | 14                                          |
     Conflict Strategy              | version                                     |
     Date format                    | yyyy-MM-dd                                  |
     Datetime format                | yyyy-MM-dd HH:mm:ss                         |
     Timezone                       | Asia/Kolkata                                |
     Locale Country                 | IN                                          |
     Locale Language                | en                                          |
     Charset                        | UTF-8                                       |
     Schema RID                     | #0:1                                        |
     Index Manager RID              | #0:2                                        |
     Dictionary RID                 | null                                        |
    --------------------------------+---------------------------------------------+
    
    DATABASE CUSTOM PROPERTIES:
     +-------------------------------+--------------------------------------------+
     | NAME                          | VALUE                                      |
     +-------------------------------+--------------------------------------------+
     | strictSql                     | true                                       |
     +-------------------------------+--------------------------------------------+
    CLUSTERS (collections)
    ---------------------------------+-------+-------------------+----------------+
     NAME                            | ID    | CONFLICT STRATEGY | RECORDS        |
    ---------------------------------+-------+-------------------+----------------+
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – List Database nhận dự án làm có lương

    OrientDB – List Database



    This chapter explains how to get the list of all databases in an instance from the OrientDB command line.

    The following statement is the basic syntax of the info command.

    LIST DATABASES
    

    Note − You can use this command only after connecting to a local or remote server.

    Example

    Before retrieving the list of databases, we have to connect to the localhost server through the remote server. It is required to remind that the username and password for connecting to the localhost instance is guest and guest respectively, which is configured in the orintdb/config/orientdb-server-config.xml file.

    You can use the following command to connect to the localhost database server instance.

    orientdb> connect remote:localhost guest
    

    It will ask the password. As per the config file password for guest is also guest. If it is successfully connected, you will get the following output.

    Connecting to remote Server instance [remote:localhost] with user ''guest''...OK
    orientdb {server = remote:localhost/}>
    

    After connecting to the localhost database server you can use the following command to list the databases.

    orientdb {server = remote:localhost/}> list databases
    

    If it is successfully executed, you will get the following output −

    Found 6 databases:
    * demo (plocal)
    * s2 (plocal)
    * s1 (plocal)
    * GratefulDeadConcerts (plocal)
    * s3 (plocal)
    * sample (plocal)
    orientdb {server = remote:localhost/}>
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Config Database nhận dự án làm có lương

    OrientDB – Config Database



    In this chapter, you can learn how to display the configuration of a particular database through OrientDB command line. This command is applicable for both local and remote databases.

    Configuration information contains default cache either enabled or not, the size of that cache, the load factor value, max memory for map, node page size, pool minimum and maximum size, etc.

    The following statement is the basic syntax of the config database command.

    CONFIG
    

    Note − You can use this command only after connecting to a particular database.

    Example

    In this example, we will use the same database named ‘demo’ that we created in the previous chapter.

    You can use the following command to display the configuration of demo database.

    Orientdb {db = demo}> CONFIG
    

    If it is successfully executed, you will get the following output.

    LOCAL SERVER CONFIGURATION:
    +---------------------------------------+-------------------------+
    | NAME                                  | VALUE                   |
    +---------------------------------------+-------------------------+
    | environment.dumpCfgAtStartup          | false                   |
    | environment.concurrent                | true                    |
    | environment.allowJVMShutdown          | true                    |
    | script.pool.maxSize                   | 20                      |
    | memory.useUnsafe                      | true                    |
    | memory.directMemory.safeMode          | true                    |
    | memory.directMemory.trackMode         | false                   |
    |………………………………..                         |                         |
    | storage.lowestFreeListBound           | 16                      |
    | network.binary.debug                  | false                   |
    | network.http.maxLength                | 1000000                 |
    | network.http.charset                  | utf-8                   |
    | network.http.jsonResponseError        | true                    |
    | network.http.json                     | false                   |
    | tx.log.fileType                       | classic                 |
    | tx.log.synch                          | false                   |
    | tx.autoRetry                          | 1                       |
    | client.channel.minPool                | 1                       |
    | storage.keepOpen                      | true                    |
    | cache.local.enabled                   | true                    |
    +---------------------------------------+-------------------------+
    orientdb {db = demo}>
    

    In the above list of configuration parameters, if you want to change any of the parameter value then you can do it from the command line easily using config set and get command.

    Config Set

    You can update the configuration variable value by using the CONFIG SET command.

    The following statement is the basic syntax of the config set command.

    CONFIG SET <config-variable> <config-value>
    

    Note − You can use this command only after connecting to a particular database.

    Example

    In this example, we will use the same database named ‘demo’ that we created in the previous chapter. We will modify the ‘tx.autoRetry’ variable value to 5.

    You can use the following command to set the configuration of demo database.

    orientdb {db = demo}> CONFIG SET tx.autoRetry 5
    

    If it is successfully executed, you will get the following output.

    Local configuration value changed correctly
    

    Config Get

    You can display the configuration variable value by using the CONFIG GET command.

    The following statement is the basic syntax of the config get command.

    CONFIG GET <config-variable>
    

    Note − You can use this command only after connecting to a particular database.

    Example

    In this example, we will use the same database named ‘demo’ that we created in the previous chapter. We will try to retrieve the ‘tx.autoRetry’ variable value.

    You can use the following command to display the configuration of demo database.

    orientdb {db = demo}> CONFIG GET tx.autoRetry
    

    If it is successfully executed, you will get the following output.

    Local configuration: tx.autoRetry = 5
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Console Modes nhận dự án làm có lương

    OrientDB – Console Modes



    The OrientDB Console is a Java Application made to work against OrientDB databases and Server instances. There are several console modes that OrientDB supports.

    Interactive Mode

    This is the default mode. Just launch the console by executing the following script bin/console.sh (or bin/console.bat in MS Windows systems). Make sure to have execution permission on it.

    OrientDB console v.1.6.6 www.orientechnologies.com
    Type ''help'' to display all the commands supported.
    
    orientdb>
    

    Once done, the console is ready to accept commands.

    Batch Mode

    To execute commands in batch mode run the following bin/console.sh (or bin/console.bat in MS Windows systems) script passing all the commands separated with semicolon “;”.

    orientdb> console.bat "connect remote:localhost/demo;select * from profile"
    

    Or call the console script passing the name of the file in text format containing the list of commands to execute. Commands must be separated with semicolon “;”.

    Example

    Command.txt contains the list of commands which you want to execute through OrientDB console. The following command accepts the batch of commands from the command.txt file.

    orientdb> console.bat commands.txt
    

    In batch mode, you can ignore errors to let the script continue the execution by setting the “ignoreErrors” variable to true.

    orientdb> set ignoreErrors true
    

    Enable Echo

    When you run console commands in pipeline, you will need to display them. Enable “echo” of commands by setting it as property at the beginning. Following is the syntax to enable echo property in OrientDB console.

    orientdb> set echo true
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Basic Concepts nhận dự án làm có lương

    OrientDB – Basic Concepts



    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

    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 uses the concepts such as classes, clusters, and link for storing, grouping, and analyzing the documents.

    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

    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.

    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.

    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

    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.

    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

    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

    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

    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.

    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

    Record Type is the same as BLOB type in RDBMS. OrientDB can load and store document Record type along with binary data.

    Vertex

    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

    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

    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

    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.

    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 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

    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.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Home nhận dự án làm có lương

    OrientDB Tutorial

    OrientDB Tutorial







    OrientDB is an Open Source NoSQL Database Management System, which contains the features of traditional DBMS along with the new features of both Document and Graph DBMS. It is written in Java and is amazingly fast. It can store 220,000 records per second on commodity hardware.

    In the following chapters of this tutorial, we will look closely at OrientDB, one of the best open-source, multi-model, next generation NoSQL product.

    Audience

    This tutorial is designed for software professionals who are willing to learn NoSQL Database in simple and easy steps. This tutorial will give a great understanding on OrientDB concepts.

    Prerequisites

    OrientDB is NoSQL Database technologies which deals with the Documents, Graphs and traditional database components, like Schema and relation. Thus it is better to have knowledge of SQL. Familiarity with NoSQL is an added advantage.

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Overview nhận dự án làm có lương

    OrientDB – Overview



    OrientDB is an Open Source NoSQL Database Management System. NoSQL Database provides a mechanism for storing and retrieving NO-relation or NON-relational data that refers to data other than tabular data such as document data or graph data. NoSQL databases are increasingly used in Big Data and real-time web applications. NoSQL systems are also sometimes called “Not Only SQL” to emphasize that they may support SQL-like query languages.

    OrientDB also belongs to the NoSQL family. OrientDB is a second generation Distributed Graph Database with the flexibility of Documents in one product with an open source of Apache 2 license. There were several NoSQL databases in the market before OrientDB, one of them being MongoDB.

    MongoDB vs OrientDB

    MongoDB and OrientDB contains many common features but the engines are fundamentally different. MongoDB is pure Document database and OrientDB is a hybrid Document with graph engine.

    Features MongoDB OrientDB
    Relationships Uses the RDBMS JOINS to create relationship between entities. It has high runtime cost and does not scale when database scale increases. Embeds and connects documents like relational database. It uses direct, super-fast links taken from graph database world.
    Fetch Plan Costly JOIN operations. Easily returns complete graph with interconnected documents.
    Transactions Doesn’t support ACID transactions, but it supports atomic operations. Supports ACID transactions as well as atomic operations.
    Query language Has its own language based on JSON. Query language is built on SQL.
    Indexes Uses the B-Tree algorithm for all indexes. Supports three different indexing algorithms so that the user can achieve best performance.
    Storage engine Uses memory mapping technique. Uses the storage engine name LOCAL and PLOCAL.

    OrientDB is the first Multi-Model open source NoSQL DBMS that brings together the power of graphs and flexibility of documents into a scalable high-performance operational database.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Data Types nhận dự án làm có lương

    OrientDB – Data Types



    OrientDB supports several data types natively. Following is the complete table on the same.

    Sr. No. Type Description
    1 Boolean

    Handles only the values True or False.

    Java types: java.lang.Boolean

    Min: 0

    Max: 1

    2 Integer

    32-bit signed integers.

    Java types: java.lang.Interger

    Min: -2,147,483,648

    Max: +2,147,483,647

    3 Short

    Small 16-bit signed integers.

    Java types: java.lang.short

    Min: -32,768

    Max: 32,767

    4 Long

    Big 64-bit signed integers.

    Java types: java.lang.Long

    Min: -263

    Max: +263-1

    5 Float

    Decimal numbers.

    Java types: java.lang.Float

    Min: 2-149

    Max: (2-2-23)*2,127

    6 Double

    Decimal numbers with high precision.

    Java types: Java.lang.Double.

    Min: 2-1074

    Max: (2-2-52)*21023

    7 Date-time

    Any date with the precision up to milliseconds.

    Java types: java.util.Date

    8 String

    Any string as alphanumeric sequence of chars.

    Java types: java.lang.String

    9 Binary

    Can contain any value as byte array.

    Java types: byte[ ]

    Min: 0

    Max: 2,147,483,647

    10 Embedded

    The record is contained inside the owner. The contained record has no RecordId.

    Java types: ORecord

    11 Embedded list

    The records are contained inside the owner. The contained records have no RecordIds and are reachable only by navigating the owner record.

    Java types: List<objects>

    Min: 0

    Max: 41,000,000 items

    12 Embedded set

    The records are contained inside the owner. The contained records have no RecordId and are reachable only by navigating the owner record.

    Java types: set<objects>

    Min: 0

    Max: 41,000,000 items

    13 Embedded map

    The records are contained inside the owner as values of the entries, while the keys can only be strings. The contained records have no RecordId and are reachable only by navigating the owner Record.

    Java types: Map<String, ORecord>

    Min: 0

    Max: 41,000,000 items

    14 Link

    Link to another Record. It”s a common one-to-one relationship

    Java Types: ORID, <? extends ORecord>

    Min: 1

    Max: 32767:2^63-1

    15 Link list

    Links to other Records. It”s a common one-to-many relationship where only the RecordIds are stored.

    Java types: List<? Extends ORecord>

    Min: 0

    Max: 41,000,000 items

    16 Link set

    Links to other records. It”s a common one-to-many relationship.

    Java types: Set<? extends ORecord>

    Min: 0

    Max: 41,000,000 items

    17 Link map

    Links to other records as value of the entries, while keys can only be strings. It”s a common one-to-many relationship. Only the RecordIds are stored.

    Java types: Map<String, ? extends Record>

    Min: 0

    Max: 41,000,000 items

    18 Byte

    Single byte. Useful to store small 8-bit signed integers.

    Java types: java.lang.Byte

    Min: -128

    Max: +127

    19 Transient Any value not stored on database.
    20 Date

    Any date as year, month and day.

    Java Types: java.util.Date

    21 Custom

    Used to store a custom type providing the Marshall and Unmarshall methods.

    Java types: OSerializableStream

    Min: 0

    Max: x

    22 Decimal

    Decimal numbers without rounding.

    Java types: java.math.BigDecimal

    23 LinkBag

    List of RecordIds as specific RidBag.

    Java types: ORidBag

    24 Any

    Not determinate type, used to specify collections of mixed type, and null.

    In the following chapters, how to use these data types in OrientDB is discussed.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí OrientDB – Backup Database nhận dự án làm có lương

    OrientDB – Backup Database



    Like RDBMS, OrientDB also supports the backup and restore operations. While executing the backup operation, it will take all files of the current database into a compressed zip format using the ZIP algorithm. This feature (Backup) can be availed automatically by enabling the Automatic-Backup server plugin.

    Taking backup of a database or exporting a database is the same, however, based on the procedure we have to know when to use backup and when to use export.

    While taking backup, it will create a consistent copy of a database, all further write operations are locked and waiting to finish the backup process. In this operation, it will create a read-only backup file.

    If you need the concurrent read and write operation while taking a backup you have to choose exporting a database instead of taking backup of a database. Export doesn’t lock the database and allows concurrent writes during the export process.

    The following statement is the basic syntax of database backup.

    ./backup.sh <dburl> <user> <password> <destination> [<type>]
    

    Following are the details about the options in the above syntax.

    <dburl> − The database URL where the database is located either in the local or in the remote location.

    <user> − Specifies the username to run the backup.

    <password> − Provides the password for the particular user.

    <destination> − Destination file location stating where to store the backup zip file.

    <type> − Optional backup type. It has either of the two options.

    • Default − locks the database during the backup.

    • LVM − uses LVM copy-on-write snapshot in background.

    Example

    Take a backup of the database demo which is located in the local file system /opt/orientdb/databases/demo into a file named sample-demo.zip and located into the current directory.

    You can use the following command to take a backup of the database demo.

    $ backup.sh plocal: opt/orientdb/database/demo admin admin ./backup-demo.zip
    

    Using Console

    The same you can do using the OrientDB console. Before taking the backup of a particular database, you have to first connect to the database. You can use the following command to connect to the database named demo.

    orientdb> CONNECT PLOCAL:/opt/orientdb/databases/demo admin admin
    

    After connecting you can use the following command to take backup of the database into a file named ‘backup-demo.zip’ in the current directory.

    orientdb {db=demo}> BACKUP DATABASE ./backup-demo.zip
    

    If this command is executed successfully, you will get some success notifications along with following message.

    Backup executed in 0.30 seconds
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc