/** * Return true if autoCommit mode is on. */ private boolean isAutoCommitMode() { if (serverConfig.isAutoCommitMode()) { // explicitly set return true; } DataSource dataSource = serverConfig.getDataSource(); return dataSource instanceof DataSourcePool && ((DataSourcePool) dataSource).isAutoCommit(); }
/** * Check the autoCommit and Transaction Isolation levels of the DataSource. * <p> * If autoCommit is true this could be a real problem. * </p> * <p> * If the Isolation level is not READ_COMMITTED then optimistic concurrency * checking may not work as expected. * </p> */ private boolean checkDataSource(ServerConfig serverConfig) { if (isOfflineMode(serverConfig)) { return false; } if (serverConfig.getDataSource() == null) { if (serverConfig.getDataSourceConfig().isOffline()) { // this is ok - offline DDL generation etc return false; } throw new RuntimeException("DataSource not set?"); } try (Connection connection = serverConfig.getDataSource().getConnection()) { if (!serverConfig.isAutoCommitMode() && connection.getAutoCommit()) { logger.warn("DataSource [{}] has autoCommit defaulting to true!", serverConfig.getName()); } return true; } catch (SQLException ex) { throw new PersistenceException(ex); } }
/** * Create the appropriate database specific platform. */ public DatabasePlatform create(ServerConfig serverConfig) { try { String offlinePlatform = DbOffline.getPlatform(); if (offlinePlatform != null) { logger.info("offline platform [{}]", offlinePlatform); return byDatabaseName(offlinePlatform); } if (serverConfig.getDatabasePlatformName() != null) { // choose based on dbName return byDatabaseName(serverConfig.getDatabasePlatformName()); } if (serverConfig.getDataSourceConfig().isOffline()) { throw new PersistenceException("You must specify a DatabasePlatformName when you are offline"); } // guess using meta data from driver return byDataSource(serverConfig.getDataSource()); } catch (Exception ex) { throw new PersistenceException(ex); } }
/** * Start any services after registering with the ClusterManager. */ public void start() { if (TenantMode.DB != serverConfig.getTenantMode()) { serverConfig.runDbMigration(serverConfig.getDataSource()); } }
/** * Check the autoCommit and Transaction Isolation levels of the DataSource. * <p> * If autoCommit is true this could be a real problem. * </p> * <p> * If the Isolation level is not READ_COMMITTED then optimistic concurrency * checking may not work as expected. * </p> */ private boolean checkDataSource(ServerConfig serverConfig) { if (isOfflineMode(serverConfig)) { return false; } if (serverConfig.getDataSource() == null) { if (serverConfig.getDataSourceConfig().isOffline()) { // this is ok - offline DDL generation etc return false; } throw new RuntimeException("DataSource not set?"); } try (Connection connection = serverConfig.getDataSource().getConnection()) { if (!serverConfig.isAutoCommitMode() && connection.getAutoCommit()) { logger.warn("DataSource [{}] has autoCommit defaulting to true!", serverConfig.getName()); } return true; } catch (SQLException ex) { throw new PersistenceException(ex); } }
/** * Return the DataSource supplier based on the tenancy mode. */ private DataSourceSupplier dataSource() { switch (serverConfig.getTenantMode()) { case DB: case DB_WITH_MASTER: return new MultiTenantDbSupplier(serverConfig.getCurrentTenantProvider(), serverConfig.getTenantDataSourceProvider()); case SCHEMA: return new MultiTenantDbSchemaSupplier(serverConfig.getCurrentTenantProvider(), serverConfig.getDataSource(), serverConfig.getReadOnlyDataSource(), serverConfig.getTenantSchemaProvider()); case CATALOG: return new MultiTenantDbCatalogSupplier(serverConfig.getCurrentTenantProvider(), serverConfig.getDataSource(), serverConfig.getReadOnlyDataSource(), serverConfig.getTenantCatalogProvider()); default: return new SimpleDataSourceProvider(serverConfig.getDataSource(), serverConfig.getReadOnlyDataSource()); } }
/** * Create the appropriate database specific platform. */ public DatabasePlatform create(ServerConfig serverConfig) { try { String offlinePlatform = DbOffline.getPlatform(); if (offlinePlatform != null) { logger.info("offline platform [{}]", offlinePlatform); return byDatabaseName(offlinePlatform); } if (serverConfig.getDatabasePlatformName() != null) { // choose based on dbName return byDatabaseName(serverConfig.getDatabasePlatformName()); } if (serverConfig.getDataSourceConfig().isOffline()) { throw new PersistenceException("You must specify a DatabasePlatformName when you are offline"); } // guess using meta data from driver return byDataSource(serverConfig.getDataSource()); } catch (Exception ex) { throw new PersistenceException(ex); } }
/** * Set the DataSource if it has not already been set. */ private void setDataSource(ServerConfig config) { if (config.getDataSource() == null) { config.setDataSource(getDataSourceFromConfig(config, false)); } if (config.getReadOnlyDataSource() == null && config.isAutoReadOnlyDataSource()) { config.setReadOnlyDataSource(getDataSourceFromConfig(config, true)); } }
/** * Start any services after registering with the ClusterManager. */ public void start() { if (TenantMode.DB != serverConfig.getTenantMode()) { serverConfig.runDbMigration(serverConfig.getDataSource()); } }
/** * Return true if autoCommit mode is on. */ private boolean isAutoCommitMode() { if (serverConfig.isAutoCommitMode()) { // explicitly set return true; } DataSource dataSource = serverConfig.getDataSource(); return dataSource instanceof DataSourcePool && ((DataSourcePool) dataSource).isAutoCommit(); }
this.docStoreFactory = config.getDocStoreFactory(); this.backgroundExecutor = config.getBackgroundExecutor(); this.dataSource = serverConfig.getDataSource(); this.encryptKeyManager = serverConfig.getEncryptKeyManager(); this.databasePlatform = serverConfig.getDatabasePlatform();
/** * Return the DataSource supplier based on the tenancy mode. */ private DataSourceSupplier dataSource() { switch (serverConfig.getTenantMode()) { case DB: case DB_WITH_MASTER: return new MultiTenantDbSupplier(serverConfig.getCurrentTenantProvider(), serverConfig.getTenantDataSourceProvider()); case SCHEMA: return new MultiTenantDbSchemaSupplier(serverConfig.getCurrentTenantProvider(), serverConfig.getDataSource(), serverConfig.getReadOnlyDataSource(), serverConfig.getTenantSchemaProvider()); case CATALOG: return new MultiTenantDbCatalogSupplier(serverConfig.getCurrentTenantProvider(), serverConfig.getDataSource(), serverConfig.getReadOnlyDataSource(), serverConfig.getTenantCatalogProvider()); default: return new SimpleDataSourceProvider(serverConfig.getDataSource(), serverConfig.getReadOnlyDataSource()); } }
/** * Set the DataSource if it has not already been set. */ private void setDataSource(ServerConfig config) { if (config.getDataSource() == null) { config.setDataSource(getDataSourceFromConfig(config, false)); } if (config.getReadOnlyDataSource() == null && config.isAutoReadOnlyDataSource()) { config.setReadOnlyDataSource(getDataSourceFromConfig(config, true)); } }
@Override protected DataSource createDataSource() { ebeanConfig = new EbeanConfigAdaptor().adaptFrom(this.config, this.config.dataSourceConfig, this); app().eventBus().trigger(new EbeanConfigLoaded(ebeanConfig)); ebean = EbeanServerFactory.create(ebeanConfig); return ebeanConfig.getDataSource(); }
this.docStoreFactory = config.getDocStoreFactory(); this.backgroundExecutor = config.getBackgroundExecutor(); this.dataSource = serverConfig.getDataSource(); this.encryptKeyManager = serverConfig.getEncryptKeyManager(); this.databasePlatform = serverConfig.getDatabasePlatform();