Skip to main content

Jelly Beans 1: Mock Persistence

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

This series is about defining, styling and/or generating documents and reports,
using Java code, eg. as an alternative to XML or even HTML/CSS templates,
even though the primary target is typically HTML/CSS. But later we wanna
output PDF also (eg. for business documents and reports, eg. using iText),
maybe LaTeX for articles (altho i think HTML is fine, and printing from
Firefox and using PDFCreator is quite OK), and Excel is really great for reports
(and we can use Apache POI), and of course we wanna support ODF cos it's nice,
and OpenOffice it's nice. For starters we'll look at how articles can be styled
and processed using quitehyper. This first article looks at style objects (for CSS).
The next article will look at generating CSS using those styles.
Later we'll look at processing HTML eg. to apply those styles using CSS,
but most importantly, to perform syntax highlighting of preformatted code snippet blocks.
-->

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

href="http://aptframework.dev.java.net/jelly/mockPersistence.html">

border="0" width="32" height="32" align="left" hspace="8"/>
Click here to read "Mock Persistence"

The debut of the "Jelly Beans" data survival series

style="text-decoration: none;">



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.


style="text-decoration: none;">
style='text-decoration: none;'>
style="text-decoration: none;">
style="text-decoration: none;">
Related Topics >>