The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


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 ;)


Demo

We create (and delete et al) test data for the Person Info demo used in the sibling Gooey Beans series.

Launch   (PersonInfo, 150k/500k, unsandboxed, Java6)

personInfoTable


Code Snippet

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();
        person.setPersonId(personId);
        ...
        entityManager.personInfo.save(person); 
        return person;
    }
    ...        
}

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


Related Topics >> Java Desktop      
Comments
Comments are listed in date ascending order (oldest first)