| By Stefan Edlich, Daniel Oltmanns | Article Rating: |
|
| February 16, 2008 12:15 PM EST | Reads: |
9,480 |
The API
Listing 1 is a simple example illustrating
how to create, store, modify, and finally delete a Customer object.
Developers familiar with EJB 3/JPA (the Java Persistence API) or
Hibernate shouldn't have a problem adapting.
In db4o, an object container is initially created. This is an object analog to the JPA/Entity Manager responsible for object administration.
The JPA/Entity Manager, however, gets its environment from a configuration of diverse factories and, if applicable, even from the Spring Bean repository. In db4o, only one file or server (via TCP/IP) has to be named.
In the first case, db4o uses just one proprietary file. This makes db4o the ideal choice for mobile devices. But the exchange of db4o database files, for example, by e-mail, is also a benefit that many companies appreciate even though the data isn't available in an independent format.
With the ObjectContainer, the user has implicitly opened a transaction. That's why there's no need for a call like entityManager.getTransaction() in Hibernate or JPA.
Taking the notion of CRUD functionality, we notice many differences but also similarities.
- db.set() stores an object. In JPA this equals em.persist(...). In an ActiveRecord environment like Ruby on Rails, creating an object would be sufficient to persist it.
- db.delete() deletes an object, analogous to em.remove() in JPA.
- In JPA, one would update modified objects with em.merge(...). In db4o this is done simply by modifying and storing the object with set(). In this case it's necessary for the object to be found via a previous query; a "weak reference" between the object and the ObjectContainer will have been established. So an update command isn't necessary. In JPA, the object just needs to be attached, which can be done with em.refresh().
Object Management
Without a doubt the biggest benefit of object databases such as db4o is that all objects can be stored just the way they are.
The Customer object stored in Listing 1 could just as easily be extremely complex:
- It could be at the end of a long inheritance hierarchy
- It could contain many sub-objects that in turn can be as deep as required
Using OR-mappers is a lot more complex. The mapping of deep objects and especially the management of schema changes is much more time-consuming. Nevertheless JPA or Hibernate 3.2 already have a strong implementation and are well on their way to improving their ease of use. The annotation of classes with Java annotations (e.g., @Entity) strongly reduces time and effort. This used to be very difficult in big projects with deep XML classes.
Only the notation of JPA relations (@one-to-one, @one-to-many, @many-to-many), the bi-directionality, and the special cases (e.g., the database differs from the object schema) are still a little annoying.
When storing, updating, and loading objects in db4o or JPA/EJB/Hibernate, one previously had to consider similar aspects: Up to what object depth are objects to be stored, updated, or activated? What is the default depth? In db4o all this can be adjusted with just a single line of code. Sub-objects that aren't active can also be activated with activate().
In versions 6.2 and 6.3, db4o introduced transparent activation (TA). With TA, objects are only retrieved when requested. Initially sub-objects aren't retrieved. In case these sub-objects are required, db4o will automatically activate and retrieve them.
This isn't as fast as manual activation but in exchange the application developer doesn't need to worry about update levels.
Transactions
As shown in Listing 1, the
ObjectContainer implicitly starts a transaction. This transaction can
be completed or undone with commit() or rollback(). Actions in the
transaction or single commands are always ACID in db4o. In db4o this is
achieved by quasi-serialising all operations. As a result db4o is
extremely transaction-safe but on the other hand inappropriate for
multithreaded access. A Web application with dozens of database queries
a second isn't as easily realizable as other replicated and highly
scalable database architectures (e.g., as in Oracle/DB2) even if
single-threaded access is extremely fast.
db4o has only implemented read-committed access mode. Switching to a different isolation level isn't possible.
Query Languages
The most interesting analysis
might be the comparison of query languages. Even here db4o, EJB, JPA,
and Hibernate resemble each other more than one might think.
Depending on db4o's implementation, queries are either executed in the application itself or in the db4o server instance.
Let's go through the requirements step-by-step:
Published February 16, 2008 Reads 9,480
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Stefan Edlich
Stefan Edlich is professor of software engineering at the Technical University of Applied Sciences in Berlin. The focus of his research includes enterprise applications, object databases, and mobile applications. The results of his research have produced many books on open source, Web frameworks, J2EE, and db4o. Stefan is organizing the object database conference ICOODB.org 2008.
More Stories By Daniel Oltmanns
Daniel Oltmanns is a research assistant at the Technical University of Applied Sciences in Berlin and an expert in the field of AJAX-technologies, databases, and Spring-architectures.
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications




























