Configuring Persistence
Configuration
Atoti Limits provides a set of services that allow you to manage objects that exist within the application at runtime.
Managed objects
Atoti Limits manages three types of objects:
These objects may be loaded from an external database, where they can be managed from within Atoti Limits and any changes will be propagated to the external database of choice.
To work with persistent data in Atoti Limits, you need to specify the load mode and configure the connection to the external datasource.
1. Specifying the load mode
You can specify one of three modes when loading data into Atoti Limits:
CSV
PERSISTENT
CSV_TO_PERSISTENT
CSV load mode
This is the default load mode for Atoti Limits. In this mode, data is loaded from CSV files,
similar to previous versions of Atoti Limits. You don’t need to configure the external datasource
in this mode.
You don’t need to explicitly enable this mode, however it can be done so by setting the property
limits.data.mode=csv
.
Persistent load mode
This is the load mode required to work with persistent data in Atoti Limits. In this mode, data is loaded from an external database using JPA (Java Persistence API), specifically Spring’s Data JPA. To use this load mode:
- Enable it by setting the property
limits.data.mode=persistent
- Configure the external datasource
2. Configuring the connection to the external datasource
The connection to an external datasource is configured using properties. The default properties are as follows:
limits:
application:
datasource:
url: "jdbc:h2:mem:limits-application;DB_CLOSE_DELAY=-1;"
username: app
password:
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
format_sql: true
hbm2ddl:
auto: update
globally_quoted_identifiers: true
hikari:
connectionTimeout: 30000
idleTimeout: 60000
minimumIdle: 1
maximumPoolSize: 10
poolName: "limits-application"
Let’s discuss some of these in more detail:
-
The properties are prefixed by
limits.application.datasource
. This follows the Spring Boot convention for configuring datasources and is what we expect when the datasources are configured inLimitsJpaConfig.java
. -
The
url
property specifies the JDBC URL for the database. In this case, we are using an in-memory H2 database namedlimits-application
.warning
This is not recommended in production. H2 is only intended for development purposes and is not a production grade database. We expect users to use another database. See the MSSQL example for an example of how to configure a connection to a Microsoft SQL Server database.
-
The
hibernate.hbm2ddl.auto
property specifies the behavior of the database schema. In this case, we are usingupdate
, which means that the schema will be updated based on the entities in the application.warning
This is not recommended in production. We expect users to manage their own database schema.
-
The
globally_quoted_identifiers
property is set totrue
. This is to escape reserved keywords in the database when defining columns. For example, the LimitStructure fieldgroup
will be mapped to the column namegroup
, which is a reserved keyword in H2, so we delegate to Hibernate to escape.
For more information on the available properties, please see the Spring documentation.
CSV to Persistent load mode
This mode is used to migrate limits from the CSV sources to the external database. For more information, see Limits Data Migration.
For information on extending persistence in Atoti Limits, see Adding Custom Persistence.