Generic Attributes


The features described in this chapter have not evolved for a while now and therefore tend to be a little out of date.

Beside the standard mapping explained in the Introduction, there can also be generic extension attributes defined in entity classes which are stored in the database in a separate table. This table can be accessed either the ordinary way using the entity class de.mathema.pride.Attribute or by extended descriptors to embed the generic attributes in specific entity types. The following example shows an extension of class Customer from the introduction by a generic attribute solvency:
 
class Customer extends MappedObject {
    // attributes, descriptor and access methods like above

    // Additional datamember and its access methods
    private String solvency;
    public String getSolvency() { return solvency; }
    public void setSolvency(String val) { solvency = val; }

    // Extension descriptor and its access method
    protected static ExtensionDescriptor xd = new ExtensionDescriptor
        (red, new String[][] {
            { "solvency", "getSolvency", "setSolvency" }
          });
    protected ExtensionDescriptor getXDescriptor() { return xd; }
}

Reading and writing of generic attributes is not performed automatically during reading and writing of other attributes but must explicitely be called by the functions fetchx(), createx() and updatex(). The function updatex(String) allows to update a single attribute to minimize database interactions. The class ExtensionDescriptor allows to map generic attributes to data members of an entity class. Its structure is pretty similar to the one for standard mappings. Its constructor requires

  1. The RecordDescriptor if the entity type
  2. A 2-dimensional string array in the same style as for standard mapping
Although seldomly used, generic attributes are much more flexible and have some advantages: As a drawback, generic attributes potentially take a lot more space in the database and a higher number of database interactions. They should therefore only be used if the number of records and attributes is small and interactions are not time-critical.


Home Introduction Javadoc