Last night, I was lucky enough to attend a Scottish Developers meeting in Glasgow. It worked out rather well actually: upon arriving in Glasgow I had beer and a burger with top bloke and colleague Alan. Then the event itself. To finish, a beer with fellow Scottish Developers Colin, Frank and with SQLBits organiser supremo Martin. All in all a great trip, and a great event – you should have been there!
Anyway, the session itself was impressive stuff. Whilst I had thought that the session was going to be all about an object database in Java, it turns out that db4o has a .NET implementation too. And it supports the .NET Compact Framework, i.e. mobile devices. Speaker Jim Paterson did a really good job of explaining db4o, its use, its positives and its negatives.
Of course, the first thing I did today was go off and download db4o and set about a simple “hello world” style example. True enough, everything that I saw last night worked like a charm. In fact, here’s the C# that I threw together in about 5 minutes:
[code lang=”C#”]
using Db4objects.Db4o;
namespace db40Ex
{
public partial class Form1 : Form
{
IObjectContainer db;
public Form1()
{
InitializeComponent();
db = Db4oFactory.OpenFile(@”D:\data\_test\db4o\data.db4o”);
}
private void button1_Click(object sender, EventArgs e)
{
myRecord mr = new myRecord();
mr.Name = “Frank Butcher”;
mr.Telephone = “123 456 789”;
db.Set(mr);
}
private void button2_Click(object sender, EventArgs e)
{
myRecord mr = new myRecord();
IObjectSet res = db.Get(mr);
listBox1.Items.Clear();
foreach (myRecord s in res)
listBox1.Items.Add(s.Name);
}
private void button3_Click(object sender, EventArgs e)
{
myRecord mr = new myRecord();
mr.Name = “Butcher Frank”;
mr.Telephone = “123 456 789”;
db.Set(mr);
}
}
public class myRecord
{
public string Name;
public string Telephone;
}
}
[/code]
Object databases aren’t without their pitfalls, I will use db4o in a “real” project – I am sure it’ll perform perfectly well. Expect to see a more detailed follow up post here shortly.
Technorati Tags: Jim Paterson, object database, db4o
I’d be interested to see how this scales. Scaling for relational databases has some well tried and tested patterns and the ORM is now trivial thanks to tools like Hibernate etc. Not sure how mature this aspect of OO databases are. Having said that, I was using a Smalltalk based OO database called Gem Stone back in the early ’90s so it’s nice to see the real world catching up with Smalltalk once again. 🙂
This particulal implementation doesn’t scale well. It is designed for embedded systems, mobile devices, single user applications and such. It can and has been used on low-medium usage websites successfully (the single user being the process running the web application). I don’t remember the speaker explicitly saying, but I’d guess the architecture of this implementation doesn’t allow scaling across servers.