Category:Entity
From JRapid
JRapid entities are the key elements for modeling data. Entities can be database tables like a company, a seller, a user, a product, etc or they can be transient entities (also called "verb" entities) like login, change password, discard, etc.
Entities can specify attributes and have properties which will define it's structure. A property can be a name for a company, a price for a product, a file, a image, etc.
Example:
In the following example we modeled a college where we have three entities. JRapid properties can specify a collection attribute which connects entities.
For each JRapid entity a default Form and Listing is created. You can easily extend the Listings and Forms visual interface by adding extra CSS files or XSL templates.
For the "Subject" entity we have the following generated files:
- "Subject" Form:
- "Subject" Listing:
- Generated hbm:
A many-to-many relationship with the "Subject" entity is created as JRapid CodeGenerator detects no childproperty between the two entities.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.sooa.entities">
<class name="Student" table="student" lazy="true">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="name" column="`name`" type="string"/>
<property name="surname" column="`surname`" type="string"/>
<property name="birthdate" column="`birthdate`" type="calendar_date"/>
<set name="subjects" table="student_subjects">
<key column="`student`"/>
<many-to-many column="`subjects`" class="Subject"/>
</set>
</class>
</hibernate-mapping>
- Generated java class:
For each Abstract java class which are generated by the code generator there is a non abstract java class which extends the abstract so as to override or add extra business rules.
/* AUTO GENERATED FILE: DO NOT EDIT!!! EDIT Subject.java INSTEAD! */
package com.sooa.entities;
import org.apache.commons.el.ExpressionEvaluatorImpl;
import javax.servlet.jsp.el.ELException;
import com.jrapid.services.ExpressionVariableResolver;
import com.jrapid.dao.DAO;
import com.jrapid.entities.Entity;
import com.sooa.dao.MainDAOLocator;
import com.sooa.services.FunctionMapper;
public abstract class SubjectAbstract extends com.jrapid.entities.Entity {
private Long id;
private String name;
private java.util.Set<Student> students = new java.util.HashSet<Student>();
private java.util.Set<Teacher> teachers = new java.util.HashSet<Teacher>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public java.util.Set<Student> getStudents() {
return students;
}
public void setStudents(java.util.Set<Student> students) {
this.students = students;
}
public java.util.Set<Teacher> getTeachers() {
return teachers;
}
public void setTeachers(java.util.Set<Teacher> teachers) {
this.teachers = teachers;
}
public static DAO<Subject> DAO() {
return MainDAOLocator.get().getSubjectDAO();
}
@Override
protected com.jrapid.dao.DAO<? extends Entity> myDAO() {
return Subject.DAO();
}
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(name + " ");
return buf.toString();
}
}
- Generated Java service
For each entity, a Java service is generated which you can extend and override it.
package com.sooa.services;
import org.apache.commons.el.ExpressionEvaluatorImpl;
import javax.servlet.jsp.el.ELException;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import com.sooa.entities.*;
import com.sooa.dao.MainDAOLocator;
import com.jrapid.dao.Restriction;
import com.jrapid.dao.Order;
import com.jrapid.dao.DAO;
import com.jrapid.dao.hibernate.HibernateRestriction;
import com.jrapid.dao.hibernate.HibernateUtil;
import com.jrapid.services.Page;
import com.jrapid.services.ExpressionVariableResolver;
import com.jrapid.exception.ServiceException;
import com.jrapid.exception.ConfirmationException;
import com.jrapid.controller.Session;
import com.jrapid.entities.Entity;
public abstract class SubjectServicesAbstract extends com.jrapid.services.Services {
protected ExpressionEvaluatorImpl el = new ExpressionEvaluatorImpl();
protected MainDAOLocator locator = MainDAOLocator.get();
protected static Map<String, ListFilter> filters = new HashMap<String, ListFilter>();
static {
setFilters();
}
public Boolean remove(String id) {
Subject.DAO().findById(id).remove();
return true;
}
public Boolean removeMany(Collection<String> ids) {
for (String id:ids) {
this.remove(id);
}
return true;
}
// code for find
public Subject find(String id) throws ELException {
Subject obj = null;
// step 1: build map
ExpressionVariableResolver evr = new ExpressionVariableResolver();
FunctionMapper fm = new FunctionMapper();
Session session = Session.getMySession();
if (id.equals("0")) {
// step 2: new object
obj = new Subject();
// step 3: setvalues
} else {
obj = Subject.DAO().findById(id);
}
// step 5: foreach
// step 6: return
return obj;
}
// code for store
public Object store(String id, Subject voobj) {
Subject obj;
if (id.equals("0")) {
obj = new Subject();
} else {
obj = Subject.DAO().findById(id);
}
boolean isNewSubjectN65571 = obj.getId() == null || obj.getId().equals(0L);
obj.setName(voobj.getName());
Collection<Student> currentN65581 = new HashSet<Student>();
for (Student itemN65581:voobj.getStudents()) {
Student newStudentN65581 = Student.DAO().findBy(itemN65581);
obj.getStudents().add(newStudentN65581);
currentN65581.add(newStudentN65581);
}
obj.getStudents().retainAll(currentN65581);
Collection<Teacher> currentN65587 = new HashSet<Teacher>();
for (Teacher itemN65587:voobj.getTeachers()) {
Teacher newTeacherN65587 = Teacher.DAO().findBy(itemN65587);
obj.getTeachers().add(newTeacherN65587);
currentN65587.add(newTeacherN65587);
}
obj.getTeachers().retainAll(currentN65587);
return obj.store();
}
// code for findall
public Collection<Subject> findPage(String storedFilter, String page, String pattern, String order) {
// prepare order
Order orders = null;
if (order != null) {
int index = (order.indexOf("d") > 0) ? Integer.valueOf(order.substring(0, order.indexOf("d"))) : Integer.valueOf(order);
String[] columns = new String[]{"name",""};
orders = new Order(columns[index] + ((order.indexOf("d") > 0) ? " desc": ""));
}
return findPageRestricted(storedFilter, page, pattern, null, orders);
}
protected interface ListFilter {
public List<Restriction> getRestrictions(DAO<Subject> dao, String param);
}
protected static void addFilter(String name, ListFilter filter) {
filters.put(name, filter);
}
protected static void setFilters() {
}
(...more generated methods...)
// code for subsets
// code for dynamic values
// code for dynamic foreach
// code for suggest
// code for conditionals
// code for unique
// code for defaultsets
}
- Generated app source code:
Entities and properties are translated to the xml language in the "Main.xml" file. The JRapid CodeGenerator reads this class for generating the applications layers.
<?xml version="1.0" encoding="UTF-8"?>
<app basepackage="com.sooa" name="Main">
<panel name="Index" title="Default main page">
<menu/>
</panel>
<entity label="Student" menu="School" name="Student">
<property display="primary" label="Name" name="name"/>
<property display="primary" label="Surname" name="surname"/>
<property display="secondary" label="Birthdate" name="birthdate" type="date"/>
</entity>
<entity label="Subject" menu="Subjects" name="Subject">
<property display="primary" label="Name" name="name"/>
<property collection="set" entity="Student" label="Students" name="students"/>
<property collection="set" entity="Teacher" label="Teachers" name="teachers"/>
</entity>
<entity label="Teacher" menu="School" name="Teacher">
<property display="primary" label="Name" name="name"/>
<property display="primary" label="Surname" name="surname"/>
</entity>
</app>
Usage:
<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"
(restrict?, description?, usescript|usestylesheet|(subset|listing|defaultset|
(property|tab|columns|row|html|embeddedlisting)*|filter|action|next)*)>
</entity>
See also:
Subcategories
This category has the following 7 subcategories, out of 7 total.
AD |
EFL |
PS |
Pages in category "Entity"
The following 17 pages are in this category, out of 17 total.
ACD |
ILMN |
ORST |

