/** * 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); } }
DataSourceConfig dsConfig = (readOnly) ? config.getReadOnlyDataSourceConfig() : config.getDataSourceConfig(); if (dsConfig == null) { throw new PersistenceException("No DataSourceConfig defined for " + config.getName()); dsConfig.setDefaults(config.getDataSourceConfig()); dsConfig.setIsolationLevel(config.getDataSourceConfig().getIsolationLevel());
/** * 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); } }
@Override public DataSource createDataSource(DataSourceConfig conf) { ServerConfig ebeanConfig = new EbeanConfigAdaptor().adaptFrom(actConfig, conf, svc); DataSourceFactory factory = ebeanConfig.service(DataSourceFactory.class); if (factory == null) { throw new IllegalStateException("No DataSourceFactory service implementation found in class path." + " Probably missing dependency to avaje-datasource?"); } DataSourceAlertFactory alertFactory = ebeanConfig.service(DataSourceAlertFactory.class); io.ebean.datasource.DataSourceConfig dsConfig = ebeanConfig.getDataSourceConfig(); if (alertFactory != null) { dsConfig.setAlert(alertFactory.createAlert()); } if (conf.readOnly) { // setup to use AutoCommit such that we skip explicit commit dsConfig.setAutoCommit(true); } String poolName = ebeanConfig.getName() + (conf.readOnly ? "-ro" : ""); return new EbeanDataSourceWrapper(ebeanConfig, factory.createPool(poolName, dsConfig)); }
/** * 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); } }
DataSourceConfig dsConfig = (readOnly) ? config.getReadOnlyDataSourceConfig() : config.getDataSourceConfig(); if (dsConfig == null) { throw new PersistenceException("No DataSourceConfig defined for " + config.getName()); dsConfig.setDefaults(config.getDataSourceConfig()); dsConfig.setIsolationLevel(config.getDataSourceConfig().getIsolationLevel());