
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