Skip to main content

jPOS-EE Things

· 2 min read
Alejandro Revilla

Inspired by this talk, I got reminded to play with EAVs in jPOS-EE. I've created a jPOS-EE modules called "things" that I believe it's a good thing to have in most applications. I don't think this is a one-size-fits-all solution, you probably don't want to store your core tables (such as the transaction log, miniGL stuff, whatever) using this open schema approach, but for everything else, having this open schema can save your day (in the same way a 'flags' field in most tables can help at some point). Using it is very simple, you create a "thing" using the ThingsManager:

DB db = new DB();
ThingsManager mgr = new ThingsManager(db); Thing t = mgr.create("MyThing");

Then you can put Strings, Longs, Dates, Timestamps, long Strings and BigDecimals to your thing, i.e:

t.put ("AString", "This is a string"); t.put ("ALong", Long.MAX_VALUE); t.put ("MyInteger", i); t.put ("Date", d); t.put ("Timestamp", new Timestamp(now)); t.put ("BigDecimal", ONE_THOUSAND); t.putText("Text", "The quick brown fox is brown and the dog is lazy, and jumps.");

The ThingsManager has some handy methods already, and we'll add more as the need arise.

public List getAll (String type) ; public Thing getLast (String type); public List listByStringName (String type, String name); public List listByStringValue (String type, String value); public List listByStringNameValue (String type, String name,String value); public List listByTextName (String type, String name); public List listByTextValue (String type, String value); ... ...

Some immediate use comes to mind, we could use this to provide a more type-safe, versionable version of our existing SysConfig table (i.e. we could have a thing called 'SysConfig' and keep previous versions as 'SysConfig;1', 'SysConfig;2', etc. (or another numbering scheme if you find this one too VMS-eske). It's also good to handle extremely proprietary stuff such as fee configuration, currency exchange, etc. found in many jPOS applications. The things module is available in jPOS-EE as of r307