@Override public void postInit(KeycloakSessionFactory factory) { this.factory = factory; checkJtaEnabled(factory); }
String schema = getSchema(); if (schema != null) { properties.put(JpaUtils.HIBERNATE_DEFAULT_SCHEMA, schema); MigrationStrategy migrationStrategy = getMigrationStrategy(); boolean initializeEmpty = config.getBoolean("initializeEmpty", true); File databaseUpdateFile = getDatabaseUpdateFile(); Connection connection = getConnection(); try { prepareOperationalInfo(connection); String driverDialect = detectDialect(connection); if (driverDialect != null) { properties.put("hibernate.dialect", driverDialect); migration(migrationStrategy, initializeEmpty, schema, databaseUpdateFile, connection, session); startGlobalStats(session, globalStatsInterval);
properties.put("hibernate.format_sql", config.getBoolean("formatSql", true)); connection = getConnection(); try{ prepareOperationalInfo(connection);
@Override public JpaConnectionProvider create(KeycloakSession session) { logger.trace("Create JpaConnectionProvider"); lazyInit(session); EntityManager em; if (!jtaEnabled) { logger.trace("enlisting EntityManager in JpaKeycloakTransaction"); em = emf.createEntityManager(); } else { em = emf.createEntityManager(SynchronizationType.SYNCHRONIZED); } em = PersistenceExceptionConverter.create(em); if (!jtaEnabled) session.getTransactionManager().enlist(new JpaKeycloakTransaction(em)); return new DefaultJpaConnectionProvider(em); }
} else if (status == JpaUpdaterProvider.Status.EMPTY) { if (initializeEmpty) { update(connection, schema, session, updater); } else { switch (strategy) { case UPDATE: update(connection, schema, session, updater); break; case MANUAL: export(connection, schema, databaseUpdateFile, session, updater); throw new ServerStartupError("Database not initialized, please initialize database with " + databaseUpdateFile.getAbsolutePath(), false); case VALIDATE: switch (strategy) { case UPDATE: update(connection, schema, session, updater); break; case MANUAL: export(connection, schema, databaseUpdateFile, session, updater); throw new ServerStartupError("Database not up-to-date, please migrate database with " + databaseUpdateFile.getAbsolutePath(), false); case VALIDATE:
@Override public JpaConnectionProvider create(KeycloakSession session) { lazyInit(session); EntityManager em = emf.createEntityManager(); em = PersistenceExceptionConverter.create(em); session.getTransaction().enlist(new JpaKeycloakTransaction(em)); return new DefaultJpaConnectionProvider(em); }