Annotations are the basis for the communication between your application and LML. The are used for the engine to know about your entities, their relationships and how they are reflected in the database.
First of all, a summary of the annotations:
| Name | Attributes | Description |
|---|---|---|
| PersistentEntity | String: tableName, updateControlAttribute, generateKey | Marks the entit as persistent |
| PersistentAttribute | columnName, primaryKey, associated, required, cascade | Marks an entity attribute as persistent |
| AssociatedEntityList | required, externalKey, cascade | Marks an entity attribute as an associated persistent entities list |
| AssociationType (enumeration) | NONE, OPTIONAL, REQUIRED | Enumeration which gruops different type of associations betweemn entities |
This annotation must be used to mark your domain entities who reflect a database table.
| Attribute | Descripcion | Default value |
|---|---|---|
| tableName | String: Table name for this entity. | Empty string. The name of the class is used (uppercase) |
| updateControlAttribute | String: A dateTime attribute you use to check dirty updates | Empty string |
| generateKey | boolean: Tells the library to generate identifiers for this entity (true) or to leave that task to the database (false) | false (database generation) |
You must use this annotation to mark the entity attributes that reflects table columns.
| Attribute | Descripcion | Default value |
|---|---|---|
| columnName | String: Name of the corresponding table column. | Empty string. The name of the attribute is used (uppercase) |
| primaryKey | boolean: Is thie attribute the identifier for the entity? | false |
| entity | boolean: attribute is an associated entity | false |
| readAssociationType | AssociationType: What to do with this associated entity when main one is read | AssociationType.OPTIONAL |
| saveAssociationType | AssociationType: What to do with this associated entity when main one is created | AssociationType.NONE |
| updateAssociationType | AssociationType: What to do with this associated entity when this one is updated | AssociationType.OPTIONAL |
| removeAssociationType | AssociationType: What to do with this associated entity when this one is removed | AssociationType.NONE |
You must use this annotation to mark an attribute that is an associated entities list.
| Attribute | Descripcion | Default value |
|---|---|---|
| externalKey | String: Name of the column in the assoiated table with the Foreign Key to main one | Required field |
| readAssociationType | AssociationType: What to do with this associated entity when main one is read | AssociationType.OPTIONAL |
| saveAssociationType | AssociationType: What to do with this associated entity when main one is created | AssociationType.NONE |
| updateAssociationType | AssociationType: What to do with this associated entity when this one is updated | AssociationType.OPTIONAL |
| removeAssociationType | AssociationType: What to do with this associated entity when this one is removed | AssociationType.NONE |
Thie enumeration stores the association types entities use.
| Name | Description |
|---|---|
| NONE | Associated entity or collection DOESN'T HAVE TO BE PERSISTED when main one does |
| OPTIONAL | Associated entity or collection must be persisted when main one does, but the operation does not have to be successful |
| REQUIRED | Associated entity or collection must be persisted when main one does, and the operation have to be successful |
Annotated POJO sample:
@PersistentEntity(tableName="CUSTOMER", generateKey=true) public class Customer implements Serializable { @PersistentAttribute(primaryKey=true, columnName="customer_id") private Integer customerId; @PersistentAttribute(columnName = "ZIP") private String zip; @PersistentAttribute(columnName = "NAME") private String name; @PersistentAttribute(columnName = "ADDRESSLINE1") private String addressLine1; @PersistentAttribute(columnName = "ADDRESSLINE2") private String addressLine2; @PersistentAttribute // It's not necessary to write column name when its equal to attribute name private String city; @PersistentAttribute(columnName = "STATE") private String state; @PersistentAttribute(columnName = "PHONE") private String phone; @PersistentAttribute(columnName = "FAX") private String fax; @PersistentAttribute(columnName = "EMAIL") private String email; @PersistentAttribute(columnName = "CREDIT_LIMIT") private Integer creditLimit; @PersistentAttribute(columnName = "DISCOUNT_CODE", entity=true, readAssociationType=AssociationType.REQUIRED, updateAssociationType=AssociationType.NONE) private DiscountCode discountCode; @AssociatedEntityList(externalKey="CUSTOMER_id", saveAssociationType=AssociationType.OPTIONAL, removeAssociationType=AssociationType.REQUIRED) private Collection<PurchaseOrder> purchaseOrders; public Customer() { } }