25. Schema-less
schema is not mandatory, relaxed model,
collect heterogeneous documents all together
www.orientechnologies.com
26. Schema-full
schema with constraints on fields and validation rules
Customer.age > 17
Customer.address not null
Customer.surname is mandatory
Customer.email matches 'b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b'
www.orientechnologies.com
27. Schema-mixed
schema with mandatory and optional fields + constraints
the best of schema-less and schema-full modes
www.orientechnologies.com
29. Complex types
collections, maps (key/value)
native support for
and embedded documents
no more additional tables to handle them
www.orientechnologies.com
30. Relationships
are direct links
no Relational JOINS to connect multiple tables
Load trees and graphs in few ms!
www.orientechnologies.com
31. SQL
select * from employee where name like '%Jay%' and status=0
www.orientechnologies.com
32. For the most of the queries
everyday a programmer needs
SQL is simpler,
more readable and
compact then
Scripting (Map/Reduce)
www.orientechnologies.com
33. SELECT SUM(price) as prices, SUM(cost) as costs, prices-costs, margin/price
FROM Balance
VS
function (key, values) {
var price = 0.0, cost = 0.0, margin = 0.0, marginPercent = 0.0;
for (var i = 0; i < values.length; i++) {
price += values[i].price;
cost += values[i].cost;
}
margin = price - cost;
marginPercent = margin / price;
return {
price: price,
cost: cost,
margin: margin,
marginPercent: marginPercent
};
}
www.orientechnologies.com
34. Asynchronous Query
invoke callback when a record matches the condition
doesn't collect the result set
perfect for immediate results
useful to compute aggregates
www.orientechnologies.com
35. ®
runs
Java
everywhere is available JRE1.5+
robust engine
www.orientechnologies.com
36. Language bindings
Java as native
JRuby, Scala and Javascript ready
C, C++, Ruby, Node.js in progress
www.orientechnologies.com
37. Your language is
not supported (yet)?
Write an adapter using the
C, Java or HTTP binding
www.orientechnologies.com
38. HTTP RESTful
firewall friendly
use it from the webbrowser
use it from the ESB (SOA)
www.orientechnologies.com
42. RB+Tree index
the best of B+Tree and RB-Tree
fast on browsing, low insertion cost
It's a new algorithm (soon public)
www.orientechnologies.com
43. OO Inheritance
Definition of Classes of documents
Classes can extend others classes
Queries are polymorphics
Contact
name : string
surname : string
Customer Provider
orders : List<Order> products : List<Product>
www.orientechnologies.com
44. Hooks
similar to triggers
catch events against records, database and transactions
implement custom cascade deletion algorithm
enforce constraints
www.orientechnologies.com
45. Fetch plans
Choose what to fetch on query and document loading
Documents not fetched will be lazy-loaded on request
Invoice
3:100
|
| customer
+---------> Customer
| 5:233
| city country
+---------> City ---------> Country
| 11:2 12:3
| orders
+--------->* [OrderItem OrderItem OrderItem]
[ 8:12 8:19 8:23 ]
www.orientechnologies.com
52. User API
Document Database
Key/Value Database Graph Database
Object Database
www.orientechnologies.com
53. Document Database
the base of all DB implementations
documents have dynamic structure
something like a smart Map<String,Object>
www.orientechnologies.com
54. Open the database
ODatabaseDocumentTx db = new ODatabaseDocumentTx( "remote:localhost/demo" );
db.open("admin", "admin");
try{
…
} finally { Open the database 'demo'
db.close(); from a remote server
}
www.orientechnologies.com
55. Create a document
ODocument doc = new ODocument( db, "Person" );
doc.field( "name", "Luke" ); Relationship
doc.field( "surname", "Skywalker" );
doc.field( "city", new ODocument("City" ).fields("name","Rome") );
doc.save();
www.orientechnologies.com
56. SQL Query
List<ODocument> result = db.query(
new OSQLSynchQuery( "select * from person where city.name = 'Rome'" ) );
for( ODocument d : result ) {
System.out.println( "Person: " + d.field( "name" ) + d.field( "surname" ) );
}
www.orientechnologies.com
57. Native Query
List<ODocument> result = new ONativeSynchQuery<ODocument,
OQueryContextNativeSchema<ODocument>>(
db, "Profile", new OQueryContextNativeSchema<ODocument>()) {
@Override
public boolean filter(OQueryContextNativeSchema<ODocument> iRecord) {
return iRecord.field("city").field("name").eq("Rome").and().field("name").like("G%").go();
};
}.setLimit(20).execute();
www.orientechnologies.com
58. Update a document
List<ODocument> result = db.query(
new OSQLSynchQuery( "select * from person where city.name = 'Rome'"));
for( ODocument d : result ) {
d.field( "local", true );
d.save();
}
// IT'S THE SAME OF:
int changed = db.command(
new OSQLCommand( "update person set local = true where city.name = 'Rome'"))
.execute();
www.orientechnologies.com
59. Delete a document
List<ODocument> result = db.query(
new OSQLSynchQuery( "select * from person where city.name = 'Rome'" ) );
for( ODocument d : result ) {
d.delete();
// IT'S THE SAME OF:
int deleted = db.command(
new OSQLCommand( "delete person where city.name = 'Rome'")).execute();
www.orientechnologies.com
61. Use hooks (triggers)
public class HookTest extends ORecordHookAbstract {
public saveProfile(){
ODatabaseObjectTx database = new ODatabaseObjectTx("remote:localhost/demo");
database.open("writer", "writer");
database.registerHook(this);
...
}
@Override
public void onRecordAfterCreate(ORecord<?> iRecord){
System.out.println("Record created successfully");
}
}
www.orientechnologies.com
62. Key/Value Database
bucket / key / value
HTTP RESTful protocol
Hazelcast plug-in to distribute database
www.orientechnologies.com
63. Key/Value = RB+Tree
works mainly using RB+Tree custom indexes
sort of Map<String,Map<String,Record>>
www.orientechnologies.com
64. Object Database
wrapper on top of Document Database
binds POJO from/to the database
no OR-Mapping complexity
no enhancement, no Java Proxies
www.orientechnologies.com
65. POJO mapping
Uses the reflection to bind POJO fields
at start-up caches reflection meta-data
1-to-1 binding
configurable options by @annotations
www.orientechnologies.com
66. Open the database
ODatabaseObjectTx db = new ODatabaseObjectTx( "remote:localhost/demo" );
db.open("admin", "admin");
try{
… Same usage of Document
Database, but the class
} finally { is different
db.close();
}
www.orientechnologies.com
67. Create a persistent POJO
Person person = new Person();
person.setName( "Luke" );
Relationship
person.setSurname( "Skywalker" );
person.setCity( new City( "Rome" ) );
db.save( person );
www.orientechnologies.com
68. Polymorphics SQL Query
List<Person> result = database.query(
new OSQLSynchQuery("select from person where city.name = 'Rome'"));
Queries are polymorphics
and subclasses of Person can be
part of result set
for( Person p : result ) {
if( p instanceof Customer )
System.out.println("Customer: " + p.getName() + “ “ + p.getSurname() );
}
www.orientechnologies.com
69. Graph Database
wrapper on top of Document Database
Few simple concepts: Vertex, Edge,
Property and Index
www.orientechnologies.com
71. TinkerPop technologies
sort of “standard” for GraphDB
a lot of free open-source projects
http://tinkerpop.com
www.orientechnologies.com
72. TinkerPop Blueprints
basic API to interact with GraphDB
implements transactional and
indexable property graph model
bidirectional edges
www.orientechnologies.com
73. GraphDB & Blueprints API
OrientGraph graph = new OrientGraph("local:/tmp/db/graph”);
Vertex actor = graph.addVertex(null);
actor.setProperty("name", "Leonardo");
actor.setProperty("surname", "Di Caprio");
Vertex movie = graph.addVertex(null);
movie.setProperty("name", "Inception");
Edge edge = graph.addEdge(null, actor, movie, "StarredIn");
graph.shutdown();
www.orientechnologies.com
74. TinkerPop
scripting language
easy to learn and understand
Used for operations against graphs
www.orientechnologies.com
75. Graph example
graph-example-1.xml
www.orientechnologies.com
76. Load graph
Run the console, open the database and load a graph in xml format
marko:~/software/gremlin$ ./gremlin.sh
,,,/
(o o)
-----oOOo-(_)-oOOo-----
gremlin> $_g := orientdb:open('/tmp/graph/test')
==>orientgraph[/tmp/graph/test]
gremlin> g:load('data/graph-example-1.xml')
==>true
gremlin> $_g
==>orientgraph[/tmp/graph/test]
www.orientechnologies.com
77. Search
Displays outgoing edges of vertices with name equals to 'marko',
then the name of inbound vertices
gremlin> g:key-v('name','marko')/outE
==>e[6:0][5:2-knows->5:1]
==>e[6:1][5:2-knows->5:4]
==>e[6:4][5:2-created->5:0]
gremlin> g:key-v('name','marko')/outE/inV/@name
==>vadas
==>josh
==>lop
gremlin> g:close()
==>true
www.orientechnologies.com
78. API resume
object, key/value and graph elements all work on top of Document
you can always access to the underlying document
changes to the document are reflected to the
object, key/value and graph elements
and viceversa
www.orientechnologies.com
79. High-Availability
Cluster of distributed server nodes
Synchronous, Asynchronous and Read-Only
replication
Load-balancing between client ↔ servers and
Servers ↔ Servers
www.orientechnologies.com
80. Synchronous scenario
Server #1 owns all the data, used for reads/writes
Server #2 is the backup replica, can be used for reads
Clients receive ack only when both are updated
Server #1 and #2 are Always Consistent
Client A Client B Client A Client B
Server #1 Server #2
(Leader+Owner) (Synchronous)
DB DB
www.orientechnologies.com
81. Asynchronous scenario
As for synchronous, but:
Server #2 is Eventually Consistent
Clients receive ack just when Server #1 is updated
Client A Client B Client A Client B
Server #1 Server #2
(Leader+Owner) (Asynchronous)
update-delay=x
DB DB
www.orientechnologies.com
82. Fail-over
Server #1 logs changes while Server #2 is disconnected
Transparent client switch to good servers (alpha status)
Running transactions will be repeated transparently (v0.9.26)
Client A Client B Client A Client B
Server #1 Server #2
(Leader+Owner) (Asynchronous)
Log
changes
DB DB
www.orientechnologies.com
83. Mixed scenario
Strict Consistency is acceptable
Use Server #1 and #2 for cases when
Use Server #3 for cases when Eventually Consistency is acceptable
Server #1
(Leader+Owner)
Server #2 Server #3
(Synchronous) update-delay=0 (Asynchronous)
DB
DB DB
www.orientechnologies.com
84. Partitioning
Cluster level granularity
Place the “owner” close to the clients to reduce latency
Server main Server USA
(Leader)
Customers
Customers
Europe
Asynchronous (update-delay=0) Europe
(owner)
Customers
Customers
Asynchronous (update-delay=0) USA
USA
(owner)
www.orientechnologies.com
85. Real world scenario I
Distribute data across multiple sites
Play with sync/asynch+delay
Keep synchronous copies close and propagate in asynch
Customers
Server Farm Europe USA
Server China
(Owner) Customers
Customers Asia
USA Server Main China Copy
(Synchronous) Customers
(Owner) Asynchronous Europe
Customers
Asia propagation
Main Copy
Customers (Synchronous)
Europe Customers
Server USA USA
(Owner)
Customers
Asia
USA Copy
(Synchronous) Customers
Europe
www.orientechnologies.com
86. Real world scenario II
Put server nodes in chain
Load-balance requests
China East
Server Copy Read-only
(Synchronous)
China West
Read-only
Server China China North
(Asynchronous) Read-only
Server Main
(Leader-Owner)
Server USA USA South
(Asynchronous) Read-only
Canada
Update European Customer: Read-only
Propagate the change
www.orientechnologies.com
87. Choose the best strategy
for your use-case
Server Copy Client B
(Synchronous)
consistent reads, Client D
delegated writes ev. consistent reads,
no writes
Server Main Server China China North
(Leader-Owner) (Asynchronous) Read-only
Client A Client C
consistent reads, ev. consistent reads,
direct writes delegates writes
www.orientechnologies.com
88. Enhanced SQL
SQL is not enough for collections, maps, trees and graphs
need to enhance SQL syntax
Easy syntax derived from JDO/JPA standards
www.orientechnologies.com
89. SQL & relationships
select from Account where address.city.country.name = 'Italy'
select from Account where addresses contains (city.country.name = 'Italy')
www.orientechnologies.com
90. SQL & trees/graphs
select from Profile where friends traverse(0,7) ( sex = 'female' )
(Soon new specific operators for trees and graphs)
www.orientechnologies.com
91. SQL & strings
select from Profile where name.toUpperCase() = 'LUCA'
select from City where country.name.substring(1,3).toUpperCase() = 'TAL'
select from Agenda where phones contains ( number.indexOf( '+39' ) > -1 )
select from Agenda where email matches 'bA-Z0-9._%+-?+@A-Z0-9.-?+.A-Z?{2,4}b'
www.orientechnologies.com
92. SQL & conversions
select from Shapes where area.toFloat() > 3.14
select from Agenda where birthDate.toDateTime() > '1976-10-26 07:00:00'
select from Workflow where completed.toBoolean() = true
www.orientechnologies.com
93. SQL & schema-less
select from Profile where any() like '%Jay%'
select from Stock where all() is not null
www.orientechnologies.com
94. SQL & collections
select from Tree where children contains ( married = true )
select from Tree where children containsAll ( married = true )
select from User where roles containsKey 'shutdown'
select from Graph where edges.size() > 0
www.orientechnologies.com
95. SQL & documents
select from Vehicle where @class = 'Car'
select from Friend where @version > 100
select from File where @size > 1000000
www.orientechnologies.com
96. Console
ORIENT database v.0.9.23 www.orientechnologies.com
Type 'help' to display all the commands supported.
> connect remote:localhost/demo admin admin
Connecting to database [remote:localhost/demo] with user 'admin'...OK
> select from profile where nick.startsWith('L')
---+--------+--------------------+--------------------+--------------------+
#| REC ID |NICK |SEX |AGE |
---+--------+--------------------+--------------------+--------------------+
0| 10:0|Lvca |male |34
1| 10:3|Leo |male |22
2| 10:7|Luisa |female |27
3 item(s) found. Query executed in 0.013 sec(s).
> close
Disconnecting from the database [demo]...OK
> quit
www.orientechnologies.com
97. OrientDB Studio/SQL query
Resultset is editable and
changes are immediately
persistent!
www.orientechnologies.com
100. Always Free
Open Source Apache 2 license
free for any purposes,
even commercials
www.orientechnologies.com
101. Prof€$$ional
$€rvic€$
by a network of companies through
Orient Technologies
support, training, consulting, mentoring
www.orientechnologies.com
102. OrientDB OrientDB
for Java developers Master Development
8 hours 14 hours
OrientDB OrientDB
for SOA and the power of graphs
6 hours 6 hours
OrientDB OrientPlanet
for DBA for Web Developers
6 hours 6 hours
www.orientechnologies.com
103. Certification Program
to be part of the network
do courses
share revenues for support
work as consultant
Contact
commercial@orientechnologies.com
www.orientechnologies.com
104. Luca Garulli
Author of OrientDB and
Roma <Meta> Framework
Open Source projects,
Member of JSR#12 (jdo 1.0) and
JSR#243 (jdo 2.0)
CTO at Asset Data and Orient
www.twitter.com/lgarulli Technologies
@Rome, Italy Technical Manager at
Romulus consortium
www.orientechnologies.com