-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for customizing quarkus jpa connection
- Loading branch information
1 parent
d2c518f
commit 27c9b36
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
.../github/thomasdarimont/keycloak/custom/jpa/CustomQuarkusJpaConnectionProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.github.thomasdarimont.keycloak.custom.jpa; | ||
|
||
import com.google.auto.service.AutoService; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import lombok.extern.jbosslog.JBossLog; | ||
import org.keycloak.connections.jpa.JpaConnectionProviderFactory; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.quarkus.runtime.storage.legacy.database.QuarkusJpaConnectionProviderFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@JBossLog | ||
@AutoService(JpaConnectionProviderFactory.class) | ||
public class CustomQuarkusJpaConnectionProviderFactory extends QuarkusJpaConnectionProviderFactory { | ||
|
||
@Override | ||
protected EntityManagerFactory getEntityManagerFactory() { | ||
// apply tuning suggestions from https://github.com/keycloak/keycloak/issues/26162 | ||
|
||
Map<String, String> tuningProperties = new HashMap<>(); | ||
tuningProperties.put("hibernate.jdbc.batch_size", "50"); | ||
tuningProperties.put("hibernate.order_inserts", "true"); | ||
tuningProperties.put("hibernate.order_updates", "true"); | ||
tuningProperties.put("hibernate.jdbc.fetch_size", "50"); | ||
tuningProperties.put("hibernate.query.in_clause_parameter_padding", "true"); | ||
log.infof("apply custom hibernate tuning properties: %s", tuningProperties); | ||
|
||
EntityManagerFactory emf = super.getEntityManagerFactory(); | ||
emf.getProperties().putAll(tuningProperties); | ||
|
||
return emf; | ||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory factory) { | ||
log.info("### Using custom Quarkus JPA Connection factory"); | ||
super.postInit(factory); | ||
} | ||
} |