Additional Tasks and Quiz

In this chapter you have learned how to create an OrientDB graph database using the Java API of OrientDB which is based on Tinkerpop Blueprints, a general API for graph databases. Now you should do some programming tasks yourself.

  • Add some more unit tests to LocationTests.java .
  • Create a Java class ObjectTests.java with unit tests for the OrientDB classes MobileObject, ObjectConcept, IS_A, IS_PART_OF and PROB_IS_AT.
  • Develop the Schema for Property, PropertyConcept and HAS_PROPERTY as described in Motivation. Then add intructions to CreateDBSchema.java which create these OrientDB classes.

Which alternatives does OrientDB offer regarding a database schema?

Schema-less mode: Each vertex or edge may have different properties Automatic-schema mode: OrientDB creates and updates a schema automatically when new vertices are inserted Schema-full mode: All vertices of a vertex- or edge-class must have the same predefined structure Schema-mixed mode: Some properties of a vertex- or edge-class are predifined, others may be added arbitrarily for each object OrientDB offers a set of predefined schemas, e. g. Business, Routing, Finance or WaterSupply. You can choose one that fits for your problem. OrientDB supports schema-less, schema-full and schema-mixed mode (see documentation for details)

Which tools or languages can you use to define a schema for OrientDB?

OrientDB Studio with a graphical user interface OrientDB OXML Schema Creator OrientDB Studio with SQL OrientDB Console Java with Tinkerpop Blueprints Oracle designer To define a schema for OrientDB you can use Studio with the Schema Manager or Studio with SQL 'Create Class' and 'Create Property' commands, OrientDB Console or in Java the createVertexType() and createEdgeType() methods.

If you want to create a database and define a database schema, should you open the database in

transactional mode: OrientGraph db = factory.getTx(); non transactional mode: OrientGraphNoTx db = factory.getNoTx(); Transactions with the possibility to rollback a transaction are useful if you insert, update, or delete data. A schema is usually defined before the application is used. Transaction are not necessary in this case. If the schema is not correct you can delete it correct the errors in your script and rebuild the schema.

You want to create a database schema using db.createVertexType() and db.createEdgeType(). In which mode do you connect to the database?

remote connection to an OrientDB server plocal mode If you want to use Tinkerpop Blueprints API you have to open the database locally on the database server in plocal mode. If you want to use a remote connection you have to use the underlying document database.

Which is the correct syntax if you want to create a new class "Account" using the Java API with SQL?

db.executeSQL(new OCommandSQL ("create class Account extends V")); db.command(new OCommandSQL ("create class Account extends V")).execute(); db.command(new OSQLSynchQuery ("create class Account extends V")).execute(); db.command("create class Account extends V").execute(); See documentation for db.command()

You want to create the property "accountNr" of the OrientDB class "Account" which should exist for every record of the class and must not be empty (null). Which constraint(s) is/are necessary?

mandatory constraint not null constraint obligate constraint both constraints: mandatory and not null The mandatory constraint ensures that every record has a field accountNr but this field need not have a value. Not null means that if a field accountNr is present it must have a value other than NULL but there may be records without this field. Only both constraints together guarantee that each record has an accountNr with a value. There is no constraint "obligate".