Generate JPA-based Persistence Layers — Fast and Easy - HEDL

treeexcellentΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 6 μήνες)

149 εμφανίσεις

HEDL
HIBERNATE
HEDL (Hibernate Entity Definition Language) ist eine domänenspezifische
Sprache (DSL), die den Umgang mit Hibernate noch einfacher macht. Mit
HEDL können Entitäten kompakt definiert werden – der entsprechende
Java-Code wird automatisch generiert.
HEDL ist ein Produkt der DevBoost GmbH und steht in einer eingeschränk-
ten Version frei zur Verfügung. Für professionelle Anwender steht HEDL mit
dem vollen Funktionsumfang und Support bereit.
Persistenzschichten schnell
und effektiv erzeugen
100 mal weniger Code schreiben
(im Vergleich zur direkten Nutzung
von Hibernate)
Datenzugriffsschichten
konsistent halten
Generate JPA-based Persistence Layers |
Fast and Easy
January 29,2013
1 What is HEDL?3
2 How do I XYZ?3
2.1 How do I initialize a new HEDL le?.........................3
2.2 How do I create a new entity?............................3
2.3 How do I extend an entity?..............................3
2.4 How do I set details like readonly or nullable of a property?.............4
2.5 How do I dene one-to-many,many-to-one,and many-to-many relationships?...4
2.6 How do I dene uniqueness constraints over multiple properties?..........4
2.7 How do I dene enumerations?............................5
2.8 How do I document entities?.............................5
2.9 How do I add comments and TODO items?.....................5
2.10 How do I congure source folder locations and other global options?........5
2.11 How can I provide custom interfaces for entities?..................6
2.12 How can I refer to existing entities dened with plain Hibernate/JPA?.......6
2.13 How can I customize the generated DAO code?...................6
2.14 How can I generate Hibernate/JPA code?......................6
2.15 How can I generated JUnit test code?........................6
2
1 What is HEDL?
HEDL is a Domain-Specic Language (DSL) that can be used to create Object Relational Map-
pings (ORM) based on the Java Persistence API (JPA).HEDL can be used in conjunction with
Hibernate or any other JPA implementation (e.g.,EclipseLink).HEDL supports entities,properties
(read-only,read-write,unique),enumerations and uniqueness constraints over multiple properties.
One can dene 1:1,1:N and N:M references.Inverses are also available.In addition,documenting
entities,properties and enumerations in Javadoc style is supported by HEDL.
The HEDL DSL comes with a builder that automatically transforms the DSL document to Java
entity classes and Data Access Object (DAO) classes.The DAOs contain many default methods for
the creation,deletion and look up of entity objects.HEDL supports to add custom DAO methods
by subclassing the generated les.
The average LOC ratio between the DSL and Java code is 1:100,which means that for every line
in the.hedl le an average of 100 lines of Java code is generated.
2 How do I XYZ?
2.1 How do I initialize a new HEDL le?
To create a new HEDL model,create a le with the le extension.hedl inside a Java source folder.
You can do that inside any existing Java project.
2.2 How do I create a new entity?
To create a new entity,just enter the name of the entity followed by a {...} block.
Producer {
String name;
}
Inside the block,you can add the properties of the entity by stating the property's type followed
by its name and a semicolon.Property types can be primitive or can refer to other properties.
Currently the following primitive types are supported:
 String
 LongString
 Int
 Bool
 Date
 Double
2.3 How do I extend an entity?
You may use the extends keyword to inherit properties from another entity.
SupplierItem extends Item {
}
3
2.4 How do I set details like readonly or nullable of a property?
Properties can be augmented with a modier such as readonly or nullable.You can use code
completion (Ctrl + Space) to select from a list of available modiers.
Supplier {
readonly String name;
nullable Warehouse warehouse;
}
The following modiers are currently supported:
 readonly | to dene a property as read only.
 nullable | to dene that a property can be null.
 unique | to dene a property must be unique.
 persist | to dene that objects referenced by this property are saved when this object is
saved.
 refresh |to dene that objects referenced by this property are refreshed when this object
is refreshed.
 eager | to dene that objects referenced by this property are fetched when this object is
fetched from the database.
2.5 How do I dene one-to-many,many-to-one,and many-to-many relationships?
You can use the
*
symbol to dene many-to-one...
OrderedItem {
Item
*
item;
}
...one-to-many...
OrderedItem {
Item item
*
;
}
...and many-to-many relationships.
OrderedItem {
Item
*
item
*
;
}
2.6 How do I dene uniqueness constraints over multiple properties?
You can use the keyword unique followed by a list of property names inside an entity denition to
dene that combinations of these properties must be unique.
Customer {
String firstName;
String lastName;
String address;
4
unique (firstName lastName address)
}
2.7 How do I dene enumerations?
Use the enum keyword to dene an enumeration and list the literals in its body.
enum WarehouseType {
TYPE1
TYPE2
}
2.8 How do I document entities?
You can add documentation to an entity in Javadoc style.
/
**
*
A Producer is someone who creates items.
*
/
Producer {
String name;
}
The same is possible for properties.
2.9 How do I add comments and TODO items?
HEDL supports single line comments (Java style) to add notes or TODO items.
Customer {
//TODO add name properties
}
TODO items will be automatically recognized by Eclipse and appear in the tasks view.
2.10 How do I congure source folder locations and other global options?
A set of options can be set in the beginning of a.hedl le.For example:
testSourceFolder ="my.company.project/src-test"
congures HEDL to put generated unit test classes into folder src-test of project my.company.project.
The following options are currently supported:
 daoSourceFolder | The folder where to store the DAO classes
 entitySourceFolder | The folder where to store the entity classes
 testSourceFolder | The folder where to store the unit tests
 customSourceFolder | The folder where to store classes that can be customized
 preserveTableNames | If true,table names will not be converted to lower case (which is
default)
5
 preserveColumnNames |If true,column names will not be converted to lower case (which
is default)
2.11 How can I provide custom interfaces for entities?
You can let an entity implement existing Java interfaces by using the implements keyword.Use
code completion (Ctrl + Space) to obtain a list of all interfaces available in the class path.
Producer implements my.company.commons.Named {
}
2.12 How can I refer to existing entities dened with plain Hibernate/JPA?
If Hibernate or another JPA implementation is already used in your project,you can use HEDL to
extend your existing data model.To do so,refer to Java classes that represent entities as type of
a property.Use code completion (Ctrl + Space) to obtain a list of all classes available in the class
path.
Customer {
my.company.project.legacy.Account account;
}
2.13 How can I customize the generated DAO code?
All classes inside the package my.company.project.custom are available for modication.They
are not deleted or overwritten when the.hedl le changes.
2.14 How can I generate Hibernate/JPA code?
The code is generated automatically each time you save a.hedl le after a modication.Make
sure that'Project > Build Automatically'is enabled.
2.15 How can I generated JUnit test code?
Test code (JUnit classes) is generated along with the production code.You can specify alternative
locations for test code by setting the testSourceFolder option.
6