Key-value Coding in Java

I would like to introduce a guide to the key-value architecture of domain objects where their attributes are provided using objects called Keys only. The Key-value approach simplifies and accelerates the development of applications. Practical use is demonstrated in the Demo-Hotels project linked at the end of the original article. The chapter list follows:
  • Writing and reading values
  • Restoring default values
  • Shallow copy of an object
  • Validation attributes when writing
  • Composite Keys
  • Criterion as a condition model
  • Criterion for filtering collection
  • Collection sorting
  • Serialization of Keys
  • Import from CSV format

Short examples are based on the Ujorm library.


Link to the original article:


Ujorm version 1.44

there is available a new version Ujorm in Maven repositories with a long-awaited support for creating hierarchical queries for a database relations to itself. Previously it was necessary to use a native SQL commands, however it can be modeled using Ujorm key type by an extended alias name for relation now. The next example shows a query for all Customers with a surename "Brown" and grandparent called "Smith":

     Criterion<Customer> crn1, crn2, crn3;
     crn1 = Customer.PARENT.alias("parent1")
     crn2 = Customer.SURENAME.whereEq("Brown");
     crn3 = crn1.and(crn2);

     Customer customer = session.createQuery(crn3).uniqueResult();

aliases can be used also in some cases where one entity contains multiple keys to the same entity, an example may be two relations Person.MOTHER, Person.FATHER.

Other features of the Ujorm series 1.4x:
  • XML configuration of an ORM meta-model can be validated using a XSD file
  • and there is available a new module (ujo-xsd) to generate XSD files accoridng an UJO class
  • ORM supports native DB sequences using the class NativeDbSequencer
  • ORM lazy loading can be enabled (optionally by a parameter) on the closed session too, for the case an action opens a new DB connection for a necessary short time only
  • there was removed the interfaces Property, which has been deprecated since version 1.30 and should be replaced by a new interface Key (including related methods)

more detailed description is in the release notes.


The CRUD application for Ujorm and Wicket

The java library Ujorm was introduced in 2008 under the old name UJO Framework. Since then, five years have passed and the source code has been modified many times but the basic idea - accessing to the properties by constants called keys - remains.

I would like to present a small web project for hotel booking to show an interesting features of the Ujorm library. Graphical interface is rendered by the  Apache Wicket framework.

See the next screenshot of the form dialog including a source code:



To be continued ...


Ujorm 1.32 released

The new release of Ujorm framework is released with two major features:
  • the new validators are available for checking a consistency of the input values. The Ujorm validators have got a similar meaning for Ujo object how the Bean Validation (JSR 303) implementation for the JavaBeans.  For more information see the the documentation or a jUnit tests.
  •  the ORM supports reading a related database tables by the one SQL request using an extended implementation of the Query object. More information are described in ORM user guide.
See a more information on the release notes page.


Ujorm 1.31 released

There is available a new release of Ujorm framework, the major changes are:
  • database statements UPDATE or DELETE supports entity relations in the Criterion - including batch mode
  • SQL entity and column names can be "quoted" optionally in the real SQL statements, for more information see the method: MetaParams.setQuotedSqlNames()
  • the one critical bug is fixed for some cases of the lazy loading
  • explicitly defined Key name created using a factory is fixed now
  • there is available the new great plugging to NetBeans IDE to generate getters and setters easy for UJO - thanks to Martin Mahr
See a more information on the release notes page.