Skip to main content

Jelly Beans 1: Mock Persistence

Posted by evanx on January 12, 2007 at 4:02 AM PST

This "Jelly Beans" series deals with data entities, as required for the "Gooey Beans" series' demos. Together with "Hyper Beans", i'm calling them the "Foundation Trilogy" :)

And yes, it's a scifi/fantasy trilogy in 42 parts, essentially about writing database applications using Swing.

So we create our "database" as an in-memory-only object graph, which is populated with test data when we startup our app. That is, we "save" our entity beans in a TreeMap, without actually persisting them to a database. For GUI prototyping and demos, this is not as useless as it sounds ;)

Mock Persistence: A part of the "Jelly Beans" part of a trilogy in 42 parts"

We create test data at startup as follows.

public class ContactTestData {
    DPerson jackSparrow =
            createPerson("jsparrow", "Jack Sparrow", "captjs@blackpearl");
    DCountry jamaicaCountry =
            createCountry("jm", "Jamaica", "jm", 1876, jmd);
    DRegion portRoyalRegion =
            createCityRegion(jamaicaRegion, "Port Royal");
    protected DPerson createPerson(String personId, String personName,
            String emailAddress) {
        DPerson person = new DPerson();
        return person;

where entityManager declares our "entity info" objects e.g. DPersonInfo, which serve as "data access objects" e.g. for DPerson entities.

Resources - where i will collate these articles and their code.

Related Topics >>