Class JpaUtils
- java.lang.Object
- 
- org.keycloak.connections.jpa.util.JpaUtils
 
- 
 public class JpaUtils extends Object - Author:
- Marek Posolda
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringHIBERNATE_DEFAULT_SCHEMAstatic StringQUERY_JPQL_SUFFIXstatic StringQUERY_NATIVE_SUFFIX
 - 
Constructor SummaryConstructors Constructor Description JpaUtils()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseEntityManager(javax.persistence.EntityManager em)Helper to close the entity manager.static voidconfigureNamedQuery(String queryName, String querySql, javax.persistence.EntityManager entityManager)Configures a named query to Hibernate.static javax.persistence.EntityManagerFactorycreateEntityManagerFactory(KeycloakSession session, String unitName, Map<String,Object> properties, boolean jta)static StringgetCustomChangelogTableName(String jpaEntityProviderFactoryId)Get the name of custom table for liquibase updates for give ID of JpaEntityProviderstatic StringgetDatabaseType(String productName)static List<Class<?>>getProvidedEntities(KeycloakSession session)Get a list of all provided entities by looping over all configured entity providers.static StringgetTableNameForNativeQuery(String tableName, javax.persistence.EntityManager em)static PropertiesloadSpecificNamedQueries(String databaseType)Method that adds the different query variants for the database.static PropertiesloadSqlProperties(URL url)Loads the URL as a properties file.
 
- 
- 
- 
Field Detail- 
HIBERNATE_DEFAULT_SCHEMApublic static final String HIBERNATE_DEFAULT_SCHEMA - See Also:
- Constant Field Values
 
 - 
QUERY_NATIVE_SUFFIXpublic static final String QUERY_NATIVE_SUFFIX - See Also:
- Constant Field Values
 
 - 
QUERY_JPQL_SUFFIXpublic static final String QUERY_JPQL_SUFFIX - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getTableNameForNativeQuerypublic static String getTableNameForNativeQuery(String tableName, javax.persistence.EntityManager em) 
 - 
createEntityManagerFactorypublic static javax.persistence.EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName, Map<String,Object> properties, boolean jta) 
 - 
getProvidedEntitiespublic static List<Class<?>> getProvidedEntities(KeycloakSession session) 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)
 
 - 
getCustomChangelogTableNamepublic static String getCustomChangelogTableName(String jpaEntityProviderFactoryId) Get the name of custom table for liquibase updates for give ID of JpaEntityProvider- Parameters:
- jpaEntityProviderFactoryId-
- Returns:
- table name
 
 - 
loadSqlPropertiespublic static Properties loadSqlProperties(URL url) 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
 
 - 
loadSpecificNamedQueriespublic static Properties loadSpecificNamedQueries(String databaseType) 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:
- em- The entity manager to use
- databaseType- The database type as managed in
- Returns:
 
 - 
configureNamedQuerypublic static void configureNamedQuery(String queryName, String querySql, javax.persistence.EntityManager entityManager) Configures a named query to Hibernate.- Parameters:
- queryName- the query name
- querySql- the query SQL
- entityManager- the entity manager
 
 - 
closeEntityManagerpublic static void closeEntityManager(javax.persistence.EntityManager em) Helper to close the entity manager.- Parameters:
- em- The entity manager to close
 
 
- 
 
-