One part is very easy : IOODB adds a method,
public void commit();
and the two implementations, Db4oDB and NeoDatisDB implement that with calls to commit.
A little bit more work is needed in GenericController.
After the three calls that modify the database (add, update and delete), we add a check. Here is add:
public void onClick$add() { if (current != null) { current = (T) Objects.clone(current); getDB().store(current); if (shouldCommit(current)) getDB().commit(); } }
I then added a new method, shouldCommit(). For now, it just returns true. In a "real" app, this might vary. You could keep a thread-safe counter and commit every N, you could keep a timer and commit based on that. You could commit after certain "important" classes, e.g. stored in a HashSet
protected boolean shouldCommit(T current) { return (important.contains(current.getClass()); }
You could have a separate thread working with a timer to trigger commits, in which case shouldCommit() would just return false.
In a "really real" app, there'd be a CommitmentStrategy, a CommitmentFactory, and some Spring framework to inject some commitment into the relationship. :-)
I will upload the new files.
BTW, I'm using Alex Gorbatchev's syntax highlighter. Thanks Alex!
No comments:
Post a Comment