How to switch Oracle EBR editions with your JPA datasource
Decoupling allows having different release cycles for the application and the database. One way of decoupling your Java application from your Oracle database can be done by using Oracles’ Edition Based Redefinition (EBR) feature. This article shows how to use EBR and switch editions when using JPA.
EBR Basics
Upgrading database applications can be demanding. A significant challenge is that long downtimes cannot be scheduled often or during office hours. Therefore, such applications require online upgrades so that changes can be rolled out and monitored during the business day. Online upgrades require that the database and the associated application support online upgrades.
Oracle’s Edition Based Redefinition (EBR) allows updating database objects at runtime without causing interruptions. EBR uses the possibility of versioning the Oracle database objects (so-called editions).
Each time database objects are changed, a new edition is created, which can then be consumed by the application. If you want to learn more about EBR, head to Oren’s EBR Blog Post Series.
Decoupled Release Cycles
Decoupling the database from the application makes it possible to roll out database changes without redeploying them simultaneously. We thus have a versioned API, which is consumed by the application and can upgrade to new API versions.
This decoupling creates separate release cycles and allows two teams to implement features independently without having to coordinate adjustments.
Switching Versions
With Oracles’ EBR, there are different ways to define the edition when accessing the database. I present here four that can be used alone or in combination.
Before an edition can be accessed, it must be made available to users — learn more in the Oracle documentation about it.
1️⃣ Default Database Edition
Once an edition is created inside the database, the easiest way to make all applications use it is to make it the default edition. The default edition is used for all incoming database connections that do not explicitly specify the edition they want to access.
ALTER DATABASE DEFAULT EDITION = myEditionName
2️⃣ Database Service
If several versions need to be accessed simultaneously, one possibility is to create different database services with preset editions. This can be done with Oracles’ DBMS_SERVICE.CREATE_SERVICE
procedures edition
parameter.
If the new database service was created with the edition, it could be used by the application to establish connections to the database. By default, it always connects to the set edition.
3️⃣ JPA Datasource with Edition
The application side can also set the edition via JPA data sources. The name of the edition can be specified in the property oracle.jdbc.editionName
. This edition will then be used when establishing a connection through the JPA data source.
properties.setProperty("oracle.jdbc.editionName", "myEditionName");
An example of a data source with the editionName property is shown below.
@Bean
@Primary
protected DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUsername(user);
dataSource.setPassword(pwd);
dataSource.setUrl(url);
Properties properties = new Properties();
properties.setProperty("oracle.jdbc.editionName", edition);
dataSource.setConnectionProperties(properties);
log.debug("dataSource:{}", dataSource);
return dataSource;
}
The application can use multiple editions simultaneously with multiple JPA data sources with different editions set.
4️⃣ Manually setting the edition
An edition can also be set manually during a session. To do this, an ALTER SESSION
command is issued in the session.
ALTER SESSION SET EDITION = myEditionName
After the alter session command, no commit is necessary; the new edition is immediately available.
Conclusion
The application and use of editions can be designed in many different ways. Therefore, it is essential to use the method that best harmonises with your release cycle and work methodology to avoid possible barriers.