Entity (element)

From JRapid

Jump to: navigation, search

entity is an element, child of app.


Contents

Description

JRapid entities are the key elements for modeling your application. They are strongly related to the database tables in your app, although they are not limited to these tables only. With this in mind, we may make reference to the definition of entity used by Wikipedia in their ER model article: "An entity may be a physical object such as a house or a car, an event such as a house sale or a car service, or a concept such as a customer transaction or order".

When working with JRapid, entities may be persistent objects strongly related to one or more database tables like a company, a seller, a user or a product, or they can be transient entities (also referred as "verb" entities) like login, change password, discard sale or run ruffle. Transient entities differ in that they do not generate any persistence code.

Entities can specify attributes and have properties that define their structure. A property can be a name for a company, a price for a product, a file, an image, etc.

By default, every entity is created with an id property as its primary key even if this is not explicitly defined. This default id is of type long and automatically incremented. You can always define your own primary keys if you prefer to.

A default Form and Listing are created for the UI representation of every entity. The application REST controller registers services for the default CRUD operations and maps them to the generated services class that implements the methods. A POJO is also created together with the corresponding hibernate mapping files, and the marshalling and unmarshalling logic. At the database layer, the corresponding tables are created according to the Hibernate files.

In short, every layer required for your application is generated:

In the case of transient entities, the Hibernate files are not generated and this avoids the creation of any database tables. Every other layer is still generated, so that you can take advantage of the forms and services when writing your custom operations.

Usage

<app>
  <entity
       name = NAME
       label = LABEL
       menu = MENU
       stereotype = (User|Email|Language|LangValue|SavedFilter|Role|Login|Async)
       size = (small|medium|large)
       defaultlisting = LISTING
       transient = "transient"
       order = COMMA_SEPARATED_ORDER
       comboproperty = COMBOPROPERTY
       auditlevel = AUDIT_LEVEL
       optimisticlock = "deny | warn"
       navigator = "navigator"
       cache = "cache"
       mainaction = MAIN_ACTION_NAME
       displayactions = COMMA_SEPARATED_ACTIONS
       displayactiongroups = COMMA_SEPARATED_ACTIONGROUPS
       (restrict?, description?, usescript|usestylesheet|(subset|listing|defaultset|
       (property|tab|columns|row|html|embeddedlisting)*|filter|action|next)*)>
  </entity>
</app>

Example

Lets take a simple example to show how entities are used for modeling a School. This application will have only three very simple entities:

  • Student: represents a student and stores a first name, a last name and a birth date.
  • Teacher: represents a teacher and stores first name and last name.
  • Subject: represents a subject, with a name, and a reference to the Teacher for that subject, and a collection holding the students that are taking that class.

The JRapid web-based designer represents these entities in the Entity diagram in the following way.

School example

This diagram is a visual representation of the AML code in the underlying XML file.

<entity label="Student" menu="Menu" name="Student">
        <property display="primary" label="First Name" name="firstName"/>
        <property display="primary" label="Last Name" name="lastName"/>
        <property label="Date of birth" name="dateOfBirth" type="date" widget="jdatepicker"/>
</entity>

<entity label="Teacher" menu="Menu" name="Teacher">
        <property display="primary" label="First Name" name="firstName"/>
        <property display="primary" label="Last Name" name="lastName"/>
</entity>

<entity label="Subject" menu="Menu" name="Subject">
        <property display="primary" label="Name" name="name"/>
        <property entity="Teacher" label="Teacher" name="teacher"/>
        <property collection="set" entity="Student" label="Students" name="students"/>
</entity>

Once this application definition is run through the code generator, the generated application looks like this. For each JRapid entity, a default Form and Listing are created. There are a lot of ways in which you may customize these generated files.


School example generated app

For the entities in this example, this are the tables automatically generated.

School example generated database tables

See also

Personal tools