db4o Blogs

db4o News

How good is your favourite programming language?

...it depends... Well yeah, of course it does. "Good" means nothing at all without "good at what". Three of the key metrics are of course: speed memory consumption size of the code base Here is a very nice website that let's you weight what you are interested in most to race your favourite languages against eachother. I recommend that you spend some time to play with the parameters. What happens if you rate CPU time (performance) to be most important? Which language is a good choice if you want the smallest codebase? Thanks to Miguel for the pointer on his blog and for his interpretations. When you choose a language for your next software project you may want to think beyond three simple metrics that are easily measurable. Here are some more factors that need consideration: Potential user base for libraries that you write Availability of educated and experienced developers Strong IDE support Tool support (profilers, code coverage, obfuscators, build) Productivity (time needed to write ...

Read the rest of entry »

Pluggable sockets for db4o and Import data to db4o code snippets

We're glad to share two new valuable code snippets with you:

  • Pluggable sockets for db4o: this reference documentation topic shows you how to hook your own socket implementation for db4o C/S communications. This is pretty useful for plugging SLL sockets and have a secure C/S channel (examples and source code included)
  • Import external data to db4o: is a code snippet by Edwin Sanchez which shows you how to extract data from a stream (e.g. a text file) and dump it to db4o

Enjoy!

Interview with Martin Odersky (Scala)

If you are interested in Scala, make sure you watch this interview with Martin Odersky, the key designer of the language. In case you don't know Scala yet: It's a fusion of functional programming and object-orientation, taking the very best of both worlds. It compiles to Java byte code and .NET IL code, so you can mix Scala with your existing Java or .NET libraries. Java support appears to be slightly better. Plugins for Eclipse and Netbeans are being worked on but of course they are not yet as mature as JDT. The first Scala book just came out. The Scala documentation that comes with the download is very good. I recommend to work through "ScalaByExample.pdf" to get a grasp of the language. Scala provides strong advanced concepts for concurrent programming, "Actors" for example. From what I can see, the Scala crew is doing a brilliant job at designing the language. I can see Scala superseding Java as the most popular programming language. (...and of course, Scala and db4o play together very ni ...

Read the rest of entry »

How to use db4o with Mozilla Rhino Script Engine

I've just uploaded code snippet by Jim Morris that shows us how to use db4o with Mozilla Rhino Script Engine.

Mozilla Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users. Among its features Rhino supports:

Thanks Jim!

JPOX "DB4O" plugin 1.2.0-beta-5 released

JPOX "DB4O" plugin version 1.2.0-beta-5 is now released.
This provides persistence to DB4O datastores using either the JDO1.0/2.0/2.1 API or the JPA1.0 API. Changes in this release include :-

  • Querying using JDOQL - initial release, supporting the majority of available JDOQL features
  • Bug fixes for transaction handling, and application identity.
  • Addition of support for auto-start mechanisms, notifying JPOX of "known" classes for efficiency
  • Minimised the memory overhead of collection/map wrappers
  • Support for relative file paths in file-based DB4O persistence.

In addition to this plugin release, JPOX "Core" module provides support for many new features for JDO2.1.

(For the details of the changes in this release go to JPOX JIRA and for details of the status of JDOQL with JPOX see JPOX JIRA DBFO-6)

Andy Jefferson
Java Persistent Objects (http://www.jpox.org/)

Object activation (in depth) ;)

In this post I'll discuss a key concept of db4o and how it improved in our latest versions: object activation. I'll focus mainly on the .Net version but these concepts apply equally well to the Java version.

In order to access some resources listed in this post you will be required to register (for free) in http://developer.db4o.com.

Activation in depth

Activation in db4o parlance is the process of loading object data from the database to memory. You can see this concept in practice by asking db4o to not activate objects at all and having a look at them. Objects that are not activated will have only its object identity loaded from the database (In order to see the identifier for an object stored in db4o you can IObjectContainer.Ext().GetId(obj);)

After building the graph of candidates (objects that satisfies a query's conditions), db4o needs to know how deep in this graph it must go activating (i.e, reading the object's data into memory). At this point it may seems that we have two contradictory objectives: i) we want to make db4o as transparent as possible to developers (making it easier to be used); ii) we do want to make sure that db4o will use computational resources (in this case memory) as efficiently as possible.

The simple approach to achieve i is to activate the whole graph but this clearly contrasts to ii because it may exhaust all free memory if the query returned a lot of objects. By the other hand, the easiest way to achieve ii (from the perspective of memory utilization) is to read only the identity of the objects in the graph and leave to the developer the responsibility to activate them when needed. Again, this strategy goes against the other one (i.e, simplicity of use). db4o latest versions includes a new functionality (conceptually called Transparent Activation, or simple TA for brevity) aimed to achieve both goals (i and ii) without sacrificing each other.

The following image shows the result of the sample program (instructions on how to get it in the end of the post) when querying for "Caroline" at different activation depths (with Transparent Activation disabled):

Note that at depth 0 (zero) only the object identifier for "Caroline" (1336) was loaded from the database; at depth 1 Caroline's value types were fully loaded and reference fields were initialized (to null) but not activated (see Caroline's address and parent fields). At depth 2 Caroline's parent object was also loaded (and activated) but its reference fields (for instance Caroline's grand father) were not activated yet.

 

Related Concepts

The same trade-of (simplicity/performance) applies when updating objects in a db4o database; I mean, usually you'll not want to update the whole set of objects reachable from the one you are currently updating because this would probably end up updating a lot of objects needlessly. To control this behavior you may configure the update depth through IConfiguration.UpdateDepth() method which takes an integer meaning how deep db4o will go when updating objects (keep in mind that when inserting, db4o will follow all references and insert all of then).

This configuration may be globally (i.e, to all classes) or selectively applied (i.e, to specific classes). As of the current version db4o sets the default update depth to 0 that means that only value types and strings fields will be updated when an object is updated (i.e, reference fields will not be updated). Optionally it's possible to propagate updates to all objects reachable from the object being updated by configuring cascade on update for the specific classes you want to propagate updates.

 

IConfiguration.ObjectClass(typeof(your_type)).CascadeOnUpdate(true);

When configured this way, db4o will go down, updating all objects reachable from your_type until it reaches an object not configured for cascade updating (note that this may impact performance severely if this object references a lot of objects also configured for cascade updating).

 

Transparent Activation

Transparent Activation is a functionality that enables developers to handle objects returned by queries as if they were fully activated without incurring the cost of activating a whole graph of objects. In other words, when TA is enabled, developers may code as if activation depth was set to infinity without having to worry about the whole set of objects being loaded into memory.

Basically, Transparent Activation transfers the responsibility of object activation from developers to db4o allowing them to focus on their business logic. Configuring your db4o projects to use TA is 2 steps process:

 

    • Configure TA support (prior to opening the database): IConfiguration.Add(new TransparentActivationSupport());

    • implement IActivatable interface in classes you want to be TA aware. You can implement it by yourself or let us (ok, our tools) to do this work for you through Db4oTool (the old Db4oAdmin) application.

Keep in mind that when transparent activation support is enabled IConfiguration.ActivationDepth() is ignored; also, all objects that are note TA aware (i.e, that doesn't implement IActivatable interface) will be fully activated; so, we don't recommend to enable TA if you have lots of objects that doesn't implement this interface.

While activating objects db4o will stop following references as soon as it reaches an TA aware object (after all it will be activated
when needed). More technical details about TA can be found here and a full sample along with details about it can be found here.

 

Putting it all together

Here you can checkout the sample application that shows the points discussed above. It inserts a simple graph of objects into a database and then queries for the root of the objects using different activation depth configurations. Also, you can ask the application to pretend that it's objects supports TA through the -ta command line option. I recommend you to download it and do the following:

    • Poke around, looking into the code :)
    • Give it a try, i.e, run it without any parameter and see what you get;
    • Try to run it again, but this time passing -ta parameter, and, again, see what you get;
    • Make its classes TA aware (see here the easy way) and try to run it with and without -ta parameter.

If you have any question don't hesitate to ask them here!

Adriano

db4o: straight-forward persistence for Wicket

"A Little Persistence Framework for Wicket" by Tim Boudreau has been made available in our code snippets section here and shows us how to leverage db4o in Wicket web applications. Apache Wicket is a web application framework that features a proper mark-up/logic separation, a POJO data model, and a refreshing lack of XML focused on providing reusable components written with plain Java and HTML (certainly a perfect fit for db4o!). Here Tim shows us a framework which simplifies database access - i.e. get rid of far too much persistence related code dotted all over the application, which contains fairly similar code for looking up POJOs for Users, Events, Presentations, etc - centered around the concept of Wicket's detachable models (a model which looks up an object, but can dispose of it when it is not needed any more) and a proper handling of POJOs lifecycle via db4o. The challenge that this framework tries to match is how to transparently and easily create IModels for POJOs on demand, keep the database look ...

Read the rest of entry »

Android maps application enhanced by db4o

Hi! Our previous db4o powered sample application for Android was pretty popular so we decided to provide a second one called MapMe. MapMe basically lets you browse 2D Google maps on Android but also has additional features such as: Zoom in and out Toggle traffic and satellite view Find location Bookmark location to db4o (full map persistence including zoom levels, and satellite and traffic views) Browse list of bookmarks Edit bookmark Navigate to location on map from bookmark Center map on current GPS reported location Planned for the next version: Track GPS movement dynamically on the screen Full text search on bookmarks In this project space you will have access to the following: an explanation of db4o persistence on the application complete source code for the Android sample application a video showing the application in action plus a walkthrough of the source code Enjoy! Related Content on this site Android Password Manager powered by db4o Android brings handsets to the next leve ...

Read the rest of entry »