Anyway, I started plugging away at a small project some of you might be interested in. Inspired by XStream and my mud, I've written a spin off project that could be quite useful. I wrote it in plain Java but tested it with Groovy, which was fun :)
Simple-x is a small fast xml database like ORM tool that allows you to persist an object tree easily. The objects you wish to keep track of can be given an ID annotated field and loaded independently from their parents. You can even lazyload fields with the lazyload annotation. It persists the xml in a directory of your choice, as one file per Id allocated object, much like a FilePersistentStrategy would do but with bells on (no separate collection classes for example).
I wrote it mainly because I was tired of ORM tools being configuration heavy, and having to specify joins in complicated xml or other files and didn't want to have all that heavy lifting to do.
An example of how to use it:
import org.corbym.simplex.persistence.annotations.Id
...
class SomeObjectWithId(){
@Id
def id
}
...
class SomeObjectWithDefFieldAndId{
@Id
def id
def somefield
}
...
final idObject = new SomeObjectWithId()
final someObject = new SomeObjectWithDefFieldAndId(somefield: ["thingy": idObject])
someObject.somefield.put "thing2", new SomeObjectWithoutId()
SimplexDao dao = SimplexDaoFactory.getInstance()
dao.save(someObject)
assert someObject.id != null
assert idObject.id != null
def loaded = dao.load(SomeObjectWithId, idObject.id)
assert loaded, "object should be loaded but was $loaded"
def otherThatContainedIdObject = dao.load(SomeObjectWithDefFieldAndId, someObject.id)
assert otherThatContainedIdObject.somefield.values().size() == 2
It's a little incomplete, requires lazyloadable collections and needs a decent caching implementation to prevent slowness but it works ok.

0 comments:
Post a Comment