DataMapper in rap for domain model
Rapper is a Reactive Data Mapper library for Java, which provides an implementation of a Data Mapper for a domain entity. This implementations follows the principles stated by Martin Fowler in [Fowler, 2002] about Object-Relational Behavioral and Data Source Architectural Patterns, but applied to a reactive approach. Thus the Rapper API is asynchronous and the data mapper effects are strongly typed in Promises [Friedman and Wise, 1976].
The Rapper implementation use the following design patterns:
-
There will be one Work Unit for each request received in the Web API. So each request will know what has been changed and what needs to be written to the BD.
-
Connection pool to establish links with the DB. This allows the re-use of connections already made to the DB, avoiding the creation of multiple connections.
-
Each entity mapper will have an Identity Map, which holds the recents objects read/altered from the DB.
-
The objects in the Identity Map are immutable, to change the data, a new immutable object will be created to be on the map. If writing in the DB is successful, the object will be placed on the map.
-
The Identity Map implements a LRU cache. They have a limit of what they can hold in memory, and when it reaches the limit, they will delete the least-read elements.
- You must create an environment variable to connect to the DB.
The environment variable must have the following format:
Name:
DB_CONNECTION_STRINGValue:
servername;database;user;password-
All domain objects must implement interface
DomainObjectand each domain object must have a field called version and the same for the DB tables. -
The domain object classes must have the same name as respective DB table, same for the fields/rows.
-
The field corresponding to the primary key must have the annotation
@Idand if it's auto-generated by the DB,isIdentity()must return true. If it is a composed key it is needed to create a class that contains the keys and respective names, the domain object must have field of that class and mark it with the annotation@EmbeddedId. -
If a
DomainObjectcontains aList<DomainObject>as a reference to another table, the field must be annotated with@ColumnName, in which is passed thenameof the column of the referenced table where the ID of theDomainObjecttakes place, thetablein case of N-N relation and theforeignNamewhich tells the name of the column of the referenced table where the ID of the otherDomainObjecttakes place.foreignNameis only needed whentableis setted -
A
DomainObjectand the class that contains the keys and respective names must have a 0 arguments constructor