Saturday, October 31, 2009

Gachi - "ORM" for Google App Engine

I've been working on a framework for Google App Engine, the Java version.

Gachi as I've named it, is a tiny framework where I've taken some ideas from QI4J and hence domain driven development for storing entities (POJO's) in the Google App Engine Datastore using the low-level API.

This is one of my testcases:

public void testCreateWishlistAndAddRecipient() {
UnitOfWork uow = new GAEUnitOfWork();

Date created = new Date();

Wishlist wishlist = uow.newEntity(Wishlist.class);
wishlist.title().set("Wishlist for christmas 2009");
wishlist.comment().set("No soft presents");


uow = new GAEUnitOfWork();
wishlist = uow.get(wishlist.getEntityReference());
assertEquals("Wishlist for christmas 2009", wishlist.title().get());
assertEquals("No soft presents", wishlist.comment().get());
assertEquals(created, wishlist.created().get());

Recipient recipient1 = uow.newEntity(wishlist, Recipient.class);"Test Person #1"); Email(""));

Recipient recipient2 = uow.newEntity(wishlist, Recipient.class);"Test Person #2"); Email(""));



uow = new GAEUnitOfWork();
wishlist = uow.get(wishlist.getEntityReference());
ManyAssociation recipients = wishlist.recipients();
assertEquals(2, recipients.getCount());
assertEquals("Test Person #1", recipients.get(0).name().get());
assertEquals("", recipients.get(0).email().get().getEmail());
assertEquals("Test Person #2", recipients.get(1).name().get());
assertEquals("", recipients.get(1).email().get().getEmail());

... more to come