Which db4o feature provides you with the ability to ensure that specific constraints are not violated whenever objects are to be committed to a database file?

Which db4o feature allows you to keep your client-side object cache in sync with whatever changes are committed to a server in a client-server setting?

Yeah, you got that right, commit time callbacks.

Two new events are being added to our event interface:
  • Committing: event subscribers are notified before the container starts any meaningful commit work and are allowed to cancel the entire operation by throwing an exception; the ObjectContainer instance is completely blocked while subscribers are being notified which is both a blessing because subscribers can count on a stable and safe environment and a curse because it prevents any parallelismwith the container;
  • Committed: event subscribers are notified in a separate thread after the container has completely finished the commit operation; exceptions if any will be ignored; still a working in progress to hit a development version near you soon;
The following snippet shows how to subscribe to the Committing event and add some application specific validation:

41:        private IObjectContainer _container;
42:
43: public Program()
44: {
45: _container = Db4oFactory.OpenFile("c:/test.db4o");
46: EventRegistry().Committing += new CommitEventHandler(Container_Committing);
47: }
48:
49: // CommitEventArgs includes information about
50: // the objects being added, updated and deleted in the
51: // current transaction
52: void Container_Committing(object sender, CommitEventArgs args)
53: {
54: CheckSSN(args.Added);
55: CheckSSN(args.Updated);
56: }
57:
58: private void CheckSSN(IObjectInfoCollection collection)
59: {
60: foreach (IObjectInfo info in collection)
61: {
62: Person p = info.GetObject() as Person;
63: if (p == null) continue;
64:
65: IQuery query = _container.Query();
66: query.Constrain(typeof(Person));
67: query.Descend("_ssn").Constrain(p.SSN);
68: IObjectSet found = query.Execute();
69: if (1 != found.Count)
70: {
71: throw new Db4oException("SSN must be unique: " + p.SSN);
72: }
73: }
74: }
75:
76: private IEventRegistry EventRegistry()
77: {
78: return EventRegistryFactory.ForObjectContainer(_container);
79: }


This feature landed in our repository pretty recently but it is already available in the 6.2 release.

And by the way, you don't have to write unique constraint code yourself!