Saturday, October 27, 2012

Ujorm 1.30 released

After a long pause I would like to introduce a new version, Ujorm 1.30, with several important changes in the API - in the first place I should mention that the original interface called UjoProperty was renamed to Key. The original interface is kept as @Deprecated now, however, its implementation classes remain. The reasons for the change are the following:
  • the original interface name UjoProperty was a little confusing due his immutable features and it was sometimes difficult to explain its meaning. The new name reflects the parameter names of the common interface java.util.Map.
  • the original name was too long and therefore the source code was difficult to read
  • several new classes have been created recently and it was useful to make the decision quickly. Particularly there are two new classes, KeyRing and KeyFactory.

The new KeyRing object is a serializable collection of Keys. Know that any instance of the Key is not serializable directly because it must have a unique instance in the class-loader. Yet sometimes we need to serialize some Keys, and the KeyRing can be the right solution. An example of this real use can be a use with the Wicket framework.

The second class is called KeyFactory and is used to create new instances Keys. An advantage of the factory is that it can also be used to create static Keys in an interface. The factory can create the Key name according to its field name, optionally the name can be converted to camel-case. Now there is no need to send the key’s data type as a parameter when creating it because this framework can obtain the value from the meta-model of the field when the factory is locked (or when the getKeys() method is called for the first time). Each Key contains a new attribute with its domain class now. An example of the use:

public class Person extends AbstractUjo {
private static final KeyFactory f = newFactory(Person.class);
   
public static final Key<Person,String > NAME = f.newKey();
public static final Key<Person,Boolean> MALE = f.newKey();
public static final Key<Person,Double > CASH = f.newKey();
   
@Override public KeyList<?> readKeys() {
    return f.getKeys();
}
}

The Ujorm framework offers a new, simplified key called WeakKey, which does not have a generic domain parameter. It can be used instead of constants for working with Map, List objects, or for reading parameters from the HttpRequest object, where it converts to the desired data type. The instance is created using the WeakKeyFactory class.

Ujorm can be connected with a Maven project using:

<dependency>
    <groupId>org.ujorm</groupId>
    <artifactId>ujo-core</artifactId>
    <version>1.30</version>
</dependency>


in case of use of the ORM module use:

<dependency>
    <groupId>org.ujorm</groupId>
    <artifactId>ujo-orm</artifactId>
    <version>1.30</version>
</dependency>


To use UJO objects in Wicket framework, an implementation of the KeyModel class is necessary. The KeyModel class is similar to the standard implementation of a Wicket class called PropertyModel. The class can be joined using the following depenency:

<dependency>
    <groupId>org.ujorm</groupId>
    <artifactId>ujo-wicket/artifactId>
    <version>1.30</version>
</dependency>

The Wicket-support module does not contain a wide range of services, yet I am enclosing a simple example of creating a simple table for inspiration:

List<ICellPopulator> columns = KeyPopulator.list
    ( Employee.ID
    , Employee.FIRSTNAME
    , Employee.LASTNAME
    , Employee.ADDRESS.add(Address.CITY)
    );

final WebMarkupContainer table = new WebMarkupContainer("table");
final DataGridView grid = new DataGridView("gridPanel", columns,
     new  InnerPeopleProvicer());
table.setOutputMarkupId(true);
grid.setItemsPerPage(20);
add(table);
table.add(grid);
add(new AjaxPagingNavigator("tableNavigator", grid));


I apologize for significant API changes to all users of the Ujorm framework, however, all the chages are necessary for further development of this library.

Further information can be found in:

No comments: