DataAccess Layer in Airlog

 

This document describes the data access layer used in the application Airlog. This layer makes the data access to the database more generic, not just for more entities, but also for more database engines, e.g. the core application does not handle how an entity is created, updated or deleted in the database, and the layer even hides the specific way in different databases.

 

Class Diagram

 

 

SmartConnection

This class extends java.sql.Connection, but handles reconnection of the connection in case it is lost. Also is refuses to use Statements, it will only allow PreparedStatements. If wanted this would be a logic place to put cache of PrepareStatements.

 

SmartPreparedStatement

This class has a java.sql.PreparedStatement (which is given with the constructor). The main goal for this class is, it handles objects, instead of primitives, e.g. set-methods (set(Long l)) has been added.

 

SmartResultSet

This class has a java.sql.ResultSet (which is given with the constructor). The main goal for this class is, it handles objects, instead of primitives, e.g. getLong returns Long, not long.

 

DataAccess

This interface insures DataAccessObject and DataAccessDelegator have the same methods.

 

DataAccessObject

This class uses the template pattern, e.g. when calling the create-method it executes some generic code, e.g. generate the SQL, then calls the data access specific doCreate-methods to set the actually data. This class reads the property file for the specific data access, for mapping the given entity names to the field in the database.

The following key can/must be used in the property-file:

Alias.<entity-name>=<field name>

Tablename=<tablename>

Sequence.<entity-name>=<sequence-name>

 

DataAccessObject (DBMS specific)

This class extends DataAccessObject, and overwrites methods that are DBMS-specific, e.g. how to resolve a sequence number.

 

DataAccessDelegator

This class delegate method calls to the right DataAccessObject instance.

 

EntityObject

This class handles the generic create, update, delete and findByKey-methods.

 

How-To

 

To implement a new data access for an entity these step must be taken.

 

  1. The new class must extend DataAccessDelegator, and resides in the package dk.highflier.airlog.dataaccess.
  2. A new property-file must be created with the mapping from entity name to database field name.
  3. The constructor needs to use the setKeyField, setMutableFields etc. It also has to call the setProperties method.
  4. Then it has to implement the fillInsertStatement, and fillUpdateStatement.

 

Pit falls