Projects:Read Only Pool/Specs
The main functional goal is to provide the ability to configure a second database that will be used by the Openbravo reports to retrieve their data. A new read-only pool will be available to provide the connections required during report generation.
Read-Only Pool Configuration
To read-only pool configuration will be done through the Openbravo.properties file.
In Openbravo.properties for each
db.pool.* it will be possible to add new
db.readonly.pool.* properties to configure the read-only database connection and specific pool properties for it.
If those new properties are set, a new connection pool will be created to be used from the code that explicitly decides to. In case they are not set, no new pool will be created and the code marked to use the read-only pool, will use the standard one.
The only required property to use the read-only pool is
bbdd.readonly.url which is used to define the read-only database url. The rest of properties for the read-only pool are optional, if not set, read-only pool will take the definition from the standard one.
- This feature will only be available when using the Apache JDBC Connection Pool.
- The implemented infrastructure does not support reading data (ie. MasterData) from the read-only database to use it to create objects and persist them into the writable database. This is because Hibernate is not allowing to share objects between the two sessions.
The infrastructure designed for this project will allow to have two pools at most (standard and read-only), but it is designed also to make it easy to extend in the future to provide more pools.
The read-only pool is intended to retrieve connections from a secondary (backup) database which only allow read operations.
JdbcExternalConnectionPool class manages all the functionality of the Apache JDBC Connection Pool. This is the class in charge to retrieve the configuration from the Openbravo.properties file and together with the standard pool, generate the read-only pool (if defined).
Along with the above, the
SessionHandler keeps the Hibernate Session and Transaction in a
ThreadLocal and it is in charge to make it available throughout the application. When the Apache JDBC Connection Pool is enabled, this class will retrieve the connections from the pool explicitly requested by the SessionHandler class.
All the connections retrieved from the read-only pool will be marked as read-only. This means that the connection will be put in read-only mode as a hint to the JDBC driver to enable database optimizations.
This new feature works both for DAL and SQLC queries, to make use of the read-only pool both the
DalConnectionProvider classes has been adapted accordingly.
To access to the read-only database (pool) with DAL, the following method will be available:
For SQLC queries that want to use the read-only pool, the connection provider must be defined as follows:
ConnectionProvider cp = DalConnectionProvider.getReadOnlyConnectionProvider();
Any query performed in OBDal/ConnectionProvider obtained in these ways, will be executed in read-only mode.
Standard Report Implementation
As part of this project, the standard reports must be configured to use the read-only pool by default. Thus:
- The reporting engine (
ReportingUtils) will use the read-only pool. Therefore, reports printed from the toolbar and process definition based reports will use the read-only database.
- Standard reports based on
HttpSecureAppServlet which make use of the renderJR method to generate the report will use the read-only database.
ShowImage API is frequently used by the reports that display images. For this reason, this API will also take the read-only pool in order to retrieve the image information from the database.
Other reports, for example those that provide their own datasource (not using a query in the jrxml template) must be reviewed and updated in order to retrieve their data with the new API.
The read-only pool could be especially suitable to retrieve static information from the database, i.e., information that usually does not change along the normal usage of the application. For example, it could be used to retrieve information from the Application Dictionary.