Class JpaUtils
java.lang.Object
org.keycloak.connections.jpa.util.JpaUtils
- Author:
- Marek Posolda
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
closeEntityManager
(jakarta.persistence.EntityManager em) Helper to close the entity manager.static void
configureNamedQuery
(String queryName, String querySql, jakarta.persistence.EntityManager entityManager) Configures a named query to Hibernate.static jakarta.persistence.EntityManagerFactory
createEntityManagerFactory
(KeycloakSession session, String unitName, Map<String, Object> properties, boolean jta) static String
getCustomChangelogTableName
(String jpaEntityProviderFactoryId) Get the name of custom table for liquibase updates for give ID of JpaEntityProviderstatic String
getDatabaseType
(String productName) getProvidedEntities
(KeycloakSession session) Get a list of all provided entities by looping over all configured entity providers.static String
getTableNameForNativeQuery
(String tableName, jakarta.persistence.EntityManager em) static Properties
loadSpecificNamedQueries
(String databaseType) Method that adds the different query variants for the database.static Properties
loadSqlProperties
(URL url) Loads the URL as a properties file.
-
Field Details
-
HIBERNATE_DEFAULT_SCHEMA
- See Also:
-
QUERY_NATIVE_SUFFIX
- See Also:
-
QUERY_JPQL_SUFFIX
- See Also:
-
-
Constructor Details
-
JpaUtils
public JpaUtils()
-
-
Method Details
-
getTableNameForNativeQuery
-
createEntityManagerFactory
public static jakarta.persistence.EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName, Map<String, Object> properties, boolean jta) -
getProvidedEntities
Get a list of all provided entities by looping over all configured entity providers.- Parameters:
session
- the keycloak session- Returns:
- a list of all provided entities (can be an empty list)
-
getCustomChangelogTableName
Get the name of custom table for liquibase updates for give ID of JpaEntityProvider- Parameters:
jpaEntityProviderFactoryId
-- Returns:
- table name
-
loadSqlProperties
Loads the URL as a properties file.- Parameters:
url
- The url to load, it can be null- Returns:
- A properties file with the url loaded or null
-
loadSpecificNamedQueries
Method that adds the different query variants for the database. The method loads the queries specified in the files META-INF/queries-{dbType}.properties and the default META-INF/queries-default.properties. At least the default file should exist inside the jar file. The default file contains all the needed queries and the specific one can overload all or some of them for that database type.- Parameters:
databaseType
- The database type as managed in- Returns:
-
configureNamedQuery
public static void configureNamedQuery(String queryName, String querySql, jakarta.persistence.EntityManager entityManager) Configures a named query to Hibernate.- Parameters:
queryName
- the query namequerySql
- the query SQLentityManager
- the entity manager
-
getDatabaseType
-
closeEntityManager
public static void closeEntityManager(jakarta.persistence.EntityManager em) Helper to close the entity manager.- Parameters:
em
- The entity manager to close
-