JMinor Application Framework

As simple as possible but not simpler

User Tools

Site Tools


documentation:tutorials:empdept

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
documentation:tutorials:empdept [2018/09/24 13:43]
darri
documentation:tutorials:empdept [2018/10/26 16:16] (current)
darri
Line 28: Line 28:
  
 We start by creating a class named EmpDept in a package of our choosing, extending Entities. This first section contains a few optional fields, which are included here for demonstration purposes, **bundle** and the i18n constants. We start by creating a class named EmpDept in a package of our choosing, extending Entities. This first section contains a few optional fields, which are included here for demonstration purposes, **bundle** and the i18n constants.
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #16-31>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #16-32>
  
 Next we define the constants required for the department [[documentation:​manual#​entity|entity]],​ which is based on the SCOTT.DEPT table. One constant defines the entity itself and will be referred to as the **entityId** (here prefixed with T_), the other three represent the columns in the table and will be referred to as **propertyIds**. The entityId in this example contains the actual table name (scott.dept),​ but the table name can be specified if that is preferred. The propertyIds contain the actual column names from the table. Next we define the constants required for the department [[documentation:​manual#​entity|entity]],​ which is based on the SCOTT.DEPT table. One constant defines the entity itself and will be referred to as the **entityId** (here prefixed with T_), the other three represent the columns in the table and will be referred to as **propertyIds**. The entityId in this example contains the actual table name (scott.dept),​ but the table name can be specified if that is preferred. The propertyIds contain the actual column names from the table.
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #32-39>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #33-40>
 Next we define the constants required for the employee entity, which is based on the EMP table. Here there are two additional propertyIDs with _FK suffixes, we'll use these later when we specify the foreign key properties for the employee entity. Next we define the constants required for the employee entity, which is based on the EMP table. Here there are two additional propertyIDs with _FK suffixes, we'll use these later when we specify the foreign key properties for the employee entity.
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #40-61>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #41-62>
 In this section we add a constructor,​ calling the two methods which define the domain entities In this section we add a constructor,​ calling the two methods which define the domain entities
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #62-67>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #63-68>
  
 Next we add the method defining the department entity. **EntityDefinition** instances are provided by the [[http://​www.jminor.org/​data/​media/​project/​docs/​api/​org/​jminor/​framework/​domain/​Entities.html|Entities]] class, via the **define** method which comes in two flavours, one which assumes the **entityID** contains the underlying table name and one which does not, and therefore requires an additional **tableName** parameter. We use the latter below. Note that we fetch caption strings for the properties from the i18n bundle via **getString()**. In a single language model we would simply use "​Caption"​ instead, see [[documentation:​tutorials:​chinook#​domain_model|Chinook domain model]]. For an overview of the **Property** class see [[documentation:​manual#​property|JMinor manual:​Property]]. The **EntityDefinition** class provides chained setters for setting entity attributes, such as the primary key value source. Here we set **idSource** to **IdSource.NONE** since the department number is chosen manually, the so-called **stringProvider** which is responsible for providing **toString()** implementations for entities, the **smallDataset** attribute which hints that it is OK to automatically base ComboBoxes on the entity and we also set the **caption**. In this case we simply have the department string provider return the department name. Next we add the method defining the department entity. **EntityDefinition** instances are provided by the [[http://​www.jminor.org/​data/​media/​project/​docs/​api/​org/​jminor/​framework/​domain/​Entities.html|Entities]] class, via the **define** method which comes in two flavours, one which assumes the **entityID** contains the underlying table name and one which does not, and therefore requires an additional **tableName** parameter. We use the latter below. Note that we fetch caption strings for the properties from the i18n bundle via **getString()**. In a single language model we would simply use "​Caption"​ instead, see [[documentation:​tutorials:​chinook#​domain_model|Chinook domain model]]. For an overview of the **Property** class see [[documentation:​manual#​property|JMinor manual:​Property]]. The **EntityDefinition** class provides chained setters for setting entity attributes, such as the primary key value source. Here we set **idSource** to **IdSource.NONE** since the department number is chosen manually, the so-called **stringProvider** which is responsible for providing **toString()** implementations for entities, the **smallDataset** attribute which hints that it is OK to automatically base ComboBoxes on the entity and we also set the **caption**. In this case we simply have the department string provider return the department name.
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #68-82>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #69-83>
 Next we define the employee entity. Here we set the **keyGenerator** to **Entities.incrementKeyGenerator(T_EMPLOYEE,​ EMPLOYEE_ID)** which, as the name suggests, simply increments the maximum column value by one (//N.B. this is a very simplistic implementation which is absolutely not transaction safe//). Here we also introduce the [[documentation:​manual#​foreignkeyproperty|ForeignKeyProperty]],​ the **orderByClause**,​ as well as a **BackgroundColorProvider** which is responsible for providing a custom color for a entity instance. Next we define the employee entity. Here we set the **keyGenerator** to **Entities.incrementKeyGenerator(T_EMPLOYEE,​ EMPLOYEE_ID)** which, as the name suggests, simply increments the maximum column value by one (//N.B. this is a very simplistic implementation which is absolutely not transaction safe//). Here we also introduce the [[documentation:​manual#​foreignkeyproperty|ForeignKeyProperty]],​ the **orderByClause**,​ as well as a **BackgroundColorProvider** which is responsible for providing a custom color for a entity instance.
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #83-116>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #84-117>
 At last there is the **getString()** method for retrieving i18n strings from the resource bundle. At last there is the **getString()** method for retrieving i18n strings from the resource bundle.
-<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #117-121>+<source org/​jminor/​framework/​demos/​empdept/​domain/​EmpDept.java #118-122>
  
 ====== Domain model unit test ====== ====== Domain model unit test ======
documentation/tutorials/empdept.txt ยท Last modified: 2018/10/26 16:16 by darri