About Data Modeling
Data Modeling uses the Entity Modeling Language (EML) to define a project-specific data model and its support within the application model. You can specify a data model using a Java-like syntax, including syntax highlighting, auto-completion, and formatting.
Every EML data model consists of entities and enumerations. An enumeration consists of a list of literals and is represented by a Java class that contains a public static member for each literal. Each member is identified by an int value (starting with 0). An entity represents a Java class and may own a number of variables, collections, and operations, such as:
Variable: Integer, Float, Double, Char, Byte, String, Object, Image, Boolean, Long
Collection: List<Type>, Map<Type, Type>, Stack<Type>
Operations:
void print(String[] args); Variables can also be used as an array. The language supports cross-referencing (using another entity as variable type) and inheritance (using the extends keyword) of entities to build a hierarchical data model.
A convenient way to model a bi-directional cross-referencing relationship is to use the @Opposite annotation. If at run time the reference to an entity is changed, the generated code also changes the opposite reference of that relationship. The following use cases are supported:
1:1 relation between variables of type entity
1:Many relation between variable of type entity and list of type entity
Many:Many relation between two lists of type entity
Two convenience methods are generated if the opposite is a list:
addItemOn<Entity>(final Abstract<Entity> item) removeItemOn<Entity>(final Abstract<Entity> item) In this case, a setter is not generated.
The @Opposite annotation is not supported for:
Arrays, enums, maps, and stacks
Variables using a simple type (e.g., int, boolean, etc.)
After code generation, entities and enumerations can be used as normal Java classes. An entity must have a name, which will be taken as name for the resulting Java class. As an example, the entities:
package entities;
entity ProcessInstance {
String id;
String name;
int status;
@Opposite(member=processInstance)
List taskInstances;
void print(String[] args)
}
entity TaskInstance {
String description;
@Opposite(member=taskInstances)
ProcessInstance processInstance;
}
will result in the Java class ProcessInstance.java and TaskInstances.java, located in your src/your_bundle_namemodel/entities package. The resulting Java class will then be generated to include each of the variables and collections as Java class properties:
public abstract class AbstractProcessInstance implements IEntity {
private String id;
private String name;
private Integer status;
private Vector taskinstances = new Vector();
public abstract void print(final String[] args);
public AbstractProcessInstance setTaskInstancesAtIndex
(final AbstractTaskInstance item, final int index){
if (taskinstances != null && taskinstances.size() > index && index >= 0){
final AbstractTaskInstance oldItem = (AbstractTaskInstance)
taskinstances.elementAt(index);
taskinstances.setElementAt(item, index);
item.setProcessInstance(this);
oldItem.setProcessInstance(null);
}
return this;
}
}
The class will also contain getter and setter methods for your properties and helper methods to access contents of collections. Furthermore, convenience methods like updateFromJson(), getAppController(), and a constructor with a JSONObject parameter are generated. With these, it is easily possible to create or update an entity based on a JSONObject/JSONString and access the AppController.
Data Modeling also includes two entity based data sources that are called
EntityDataSource and
EntityStore. An
EntityDataSource can be configured to request a remote JSON resource. The JSON document is automatically parsed into an entity. Furthermore, the entity is transformed back into a JSON document so that it can send back the data to a remote JSON resource. The entities will be used as a list data source for
ListView and
ListViewElement objects. For more information, see
EntityDataSource Properties. The
EntityStore provides a single entity and can be used to bind a single data object against user interface elements. For instance, having a login mask with input fields for user name and password, you can bind both input fields against a
Credentials Entity using a
DataBinding object.
Related Topics