final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) { this.loader = loader; this.server = server; this.file = file; this.description = description; this.dataFolder = dataFolder; this.classLoader = classLoader; this.configFile = new File(dataFolder, "config.yml"); this.logger = new PluginLogger(this); if (description.isDatabaseEnabled()) { ServerConfig db = new ServerConfig(); db.setDefaultServer(false); db.setRegister(false); db.setClasses(getDatabaseClasses()); db.setName(description.getName()); server.configureDbConfig(db); DataSourceConfig ds = db.getDataSourceConfig(); ds.setUrl(replaceDatabaseString(ds.getUrl())); dataFolder.mkdirs(); ClassLoader previous = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); ebean = EbeanServerFactory.create(db); Thread.currentThread().setContextClassLoader(previous); } }
if (serverConfig.getDataSourceConfig().isOffline()) {
if (serverConfig.getDataSourceConfig().isOffline()) {
if (serverConfig.getDataSourceConfig().isOffline()) {
public Gringotts() { ServerConfig dbConfig = new ServerConfig(); dbConfig.setDefaultServer(false); dbConfig.setRegister(false); dbConfig.setClasses(getDatabaseClasses()); dbConfig.setName(getDescription().getName()); configureDbConfig(dbConfig); DataSourceConfig dsConfig = dbConfig.getDataSourceConfig(); dsConfig.setUrl(replaceDatabaseString(dsConfig.getUrl())); getDataFolder().mkdirs(); ClassLoader previous = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClassLoader()); ebean = EbeanServerFactory.create(dbConfig); Thread.currentThread().setContextClassLoader(previous); }
final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) { this.loader = loader; this.server = server; this.file = file; this.description = description; this.dataFolder = dataFolder; this.classLoader = classLoader; this.configFile = new File(dataFolder, "config.yml"); this.logger = new PluginLogger(this); if (description.isDatabaseEnabled()) { ServerConfig db = new ServerConfig(); db.setDefaultServer(false); db.setRegister(false); db.setClasses(getDatabaseClasses()); db.setName(description.getName()); server.configureDbConfig(db); DataSourceConfig ds = db.getDataSourceConfig(); ds.setUrl(replaceDatabaseString(ds.getUrl())); dataFolder.mkdirs(); ClassLoader previous = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); ebean = EbeanServerFactory.create(db); Thread.currentThread().setContextClassLoader(previous); } }
@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); org.avaje.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()) { String m = "You must specify a DatabasePlatformName when you are offline"; throw new PersistenceException(m); } // guess using meta data from driver return byDataSource(serverConfig.getDataSource()); } catch (Exception ex) { throw new PersistenceException(ex); } }
/** * Create the appropriate database specific platform. */ public DatabasePlatform create(ServerConfig serverConfig) { try { if (serverConfig.getDatabasePlatformName() != null) { // choose based on dbName return byDatabaseName(serverConfig.getDatabasePlatformName()); } if (serverConfig.getDataSourceConfig().isOffline()) { String m = "You must specify a DatabasePlatformName when you are offline"; throw new PersistenceException(m); } // guess using meta data from driver return byDataSource(serverConfig.getDataSource()); } catch (Exception ex) { throw new PersistenceException(ex); } }
/** * Create the appropriate database specific platform. */ public DatabasePlatform create(ServerConfig serverConfig) { try { if (serverConfig.getDatabasePlatformName() != null) { // choose based on dbName return byDatabaseName(serverConfig.getDatabasePlatformName()); } if (serverConfig.getDataSourceConfig().isOffline()) { String m = "You must specify a DatabasePlatformName when you are offline"; throw new PersistenceException(m); } // guess using meta data from driver return byDataSource(serverConfig.getDataSource()); } catch (Exception ex) { throw new PersistenceException(ex); } }
DataSourceConfig dsConfig = config.getDataSourceConfig(); if (dsConfig == null) { throw new PersistenceException("No DataSourceConfig defined for " + config.getName());
private DataSource getDataSourceFromConfig(ServerConfig config) { DataSource ds = null; if (config.getDataSourceJndiName() != null) { ds = jndiDataSourceFactory.lookup(config.getDataSourceJndiName()); if (ds == null) { String m = "JNDI lookup for DataSource " + config.getDataSourceJndiName() + " returned null."; throw new PersistenceException(m); } else { return ds; } } DataSourceConfig dsConfig = config.getDataSourceConfig(); if (dsConfig == null) { String m = "No DataSourceConfig definded for " + config.getName(); throw new PersistenceException(m); } if (dsConfig.isOffline()) { if (config.getDatabasePlatformName() == null) { String m = "You MUST specify a DatabasePlatformName on ServerConfig when offline"; throw new PersistenceException(m); } return null; } if (dsConfig.getHeartbeatSql() == null) { // use default heartbeatSql from the DatabasePlatform String heartbeatSql = getHeartbeatSql(dsConfig.getDriver()); dsConfig.setHeartbeatSql(heartbeatSql); } return DataSourceGlobalManager.getDataSource(config.getName(), dsConfig); }
private DataSource getDataSourceFromConfig(ServerConfig config) { DataSource ds = null; if (config.getDataSourceJndiName() != null) { ds = jndiDataSourceFactory.lookup(config.getDataSourceJndiName()); if (ds == null) { String m = "JNDI lookup for DataSource " + config.getDataSourceJndiName() + " returned null."; throw new PersistenceException(m); } else { return ds; } } DataSourceConfig dsConfig = config.getDataSourceConfig(); if (dsConfig == null) { String m = "No DataSourceConfig definded for " + config.getName(); throw new PersistenceException(m); } if (dsConfig.isOffline()) { if (config.getDatabasePlatformName() == null) { String m = "You MUST specify a DatabasePlatformName on ServerConfig when offline"; throw new PersistenceException(m); } return null; } if (dsConfig.getHeartbeatSql() == null) { // use default heartbeatSql from the DatabasePlatform String heartbeatSql = getHeartbeatSql(dsConfig.getDriver()); dsConfig.setHeartbeatSql(heartbeatSql); } return DataSourceGlobalManager.getDataSource(config.getName(), dsConfig); }