* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Download IT Boxing Championship
Survey
Document related concepts
Transcript
Svetoslav Kapralov
Contents
1. DB4O Overview
• OODBMS vs. RDBMS
• What is DB4O
2. DB4O Basics
• Object Container
• CRUD
• Activation
• Transactions
DB4O Overview
OОDBMS (db4o) vs. RDBMS
• Object-oriented programming (OOP) and
relational databases (RDBMS) do not match up
• An object database (ODBMS) stores objects
directly
What is db4o?
• Open source object database
• Designed for embedded
• 1,000,000 downloads,
• 20,000 registered community members
• 200 customers
• Dual license model (GPL / commercial)
• db4o is up to 55x faster than Hibernate +
RDBMS!
What is db4o?
• No Database Administrator required
• No conversion or mapping needed since
objects are stored as they are
• Only one line of code to store objects of
any complexity natively
• Installation by adding a single library file
DB4O Basics
Object Container
• Represents db4o databases
• Supports local file mode or client
connections to db4o server
• All operations are executed transactional
• Maintains references to stored and
instantiated objects
Storing Objects
• Objects stored using method set of
ObjectContainer
• Stores objects of arbitrary complexity
ObjectContainer database = Db4o.openFile("test.db");
// create a publication
Book book = new Book(“db4o");
// create authors
Author lambo = new Author(“Lambo");
Author gruiu = new Author(“Gruiu");
// assign authors to book
book.addAuthor(lambo);
book.addAuthor(gruiu);
//store complex object
database.set(book);
Retrieving Objects
• db4o supports three query languages
• QBE
• Native query
• SODA
Query by Example
• simple method based on
prototype objects
ObjectContainer database = Db4o.openFile("test.db");
// get author “Lambo"
Author proto = new Author(“Lambo");
ObjectSet<Author> authors = database.get(proto);
for (Author author: authors) {
System.out.println(author.getName());
}
// get all books
ObjectSet<Book> books = database.get(Book.class);
for (Book book: books) {
System.out.println(book.getTitle());
}
Native Queries
• type safe
• transformed to SODA and optimized
ObjectContainer database = Db4o.openFile("test.db");
// find all books after 1995
ObjectSet<Book> books = database.query(
new Predicate<Book>() {
public boolean match(Book book) {
return book.getYear() > 1995;
}
}
);
for (Book book: books) {
System.out.println(book.getTitle());
}
Update / Delete Objects
• Update procedure for persistent object
• retrieve desired object from the database
• perform the required changes and
modification
• store object back to the database by
calling the set method
• Delete procedure for persistent object
• retrieve desired object from the database
• method delete of ObjectContainer removes
objects
CRUD Summary
• Storing of new objects using the set method
• object graph is traversed and all
referenced objects are stored
• Updating of existing objects using the set
method
• by default update depth is set to one
• only primitive and string values are
updated
• object graph is not traversed for reasons
of performance
CRUD Summary
• Deleting existing objects using the delete
method
• by default delete operations are not
cascaded
• referenced objects have to be deleted
manually
• cascading delete can be configured for
individual classes
Activation
• Activation controls instantiation of object
fields
• object field values are loaded into
memory only to a certain depth when a
query retrieves objects
• activation depth denotes the length of the
reference chain from an object to another
• fields beyond the activation depth are set
to null for object references or to default
values for primitive types
Activation
• Activation depth trade-off
• set to maximum
• set to minimum
• Controlling activation
• default activation depth is 5
• methods activate and deactivate of
ObjectContainer
• per class configuration
Transactions
• ACID transaction model
• Data transaction journaling
• zero data loss in case of system failure
• automatic data recovery after system
failure
• db4o core is thread-safe for
simultaneous operations
• db4o uses the read committed isolation
level