@Override public void configureDbConfig(ServerConfig config) { DataSourceConfig ds = new DataSourceConfig(); ds.setDriver(configuration.getString("database.driver")); ds.setUrl(configuration.getString("database.url")); ds.setUsername(configuration.getString("database.username")); ds.setPassword(configuration.getString("database.password")); ds.setIsolationLevel( TransactionIsolation.getLevel(configuration.getString("database.isolation"))); if (ds.getDriver().contains("sqlite")) { config.setDatabasePlatform(new SQLitePlatform()); config.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } else if (ds.getDriver().contains("mysql")) { theLogger.warning("MySQL is presently unsupported for CraftForge"); } config.setDataSourceConfig(ds); }
private void prepareDatabase( String driver, String url, String username, String password, String isolation) { // Setup the data source DataSourceConfig ds = new DataSourceConfig(); ds.setDriver(driver); ds.setUrl(replaceDatabaseString(url)); ds.setUsername(username); ds.setPassword(password); ds.setIsolationLevel(TransactionIsolation.getLevel(isolation)); // Setup the server configuration ServerConfig sc = new ServerConfig(); sc.setDefaultServer(false); sc.setRegister(false); sc.setName(ds.getUrl().replaceAll("[^a-zA-Z0-9]", "")); // Get all persistent classes List<Class<?>> classes = getDatabaseClasses(); // Do a sanity check first if (classes.size() == 0) { // Exception: There is no use in continuing to load this database throw new RuntimeException("Database has been enabled, but no classes are registered to it"); } // Register them with the EbeanServer sc.setClasses(classes); // Check if the SQLite JDBC supplied with Bukkit is being used if (ds.getDriver().equalsIgnoreCase("org.sqlite.JDBC")) { // Remember the database is a SQLite-database usingSQLite = true; // Modify the platform, as SQLite has no AUTO_INCREMENT field sc.setDatabasePlatform(new SQLitePlatform()); sc.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } prepareDatabaseAdditionalConfig(ds, sc); // Finally the data source sc.setDataSourceConfig(ds); // Store the ServerConfig serverConfig = sc; }
/** * Populates a given {@link com.avaje.ebean.config.ServerConfig} with values attributes to this * server * * @param dbConfig ServerConfig to populate */ public void configureDbConfig(com.avaje.ebean.config.ServerConfig dbConfig) { com.avaje.ebean.config.DataSourceConfig ds = new com.avaje.ebean.config.DataSourceConfig(); ds.setDriver(config.getString("database.driver", "org.sqlite.JDBC")); ds.setUrl(config.getString("database.url", "jdbc:sqlite:{DIR}{NAME}.db")); ds.setUsername(config.getString("database.username", "glow")); ds.setPassword(config.getString("database.password", "stone")); ds.setIsolationLevel( com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation.getLevel( config.getString("database.isolation", "SERIALIZABLE"))); if (ds.getDriver().contains("sqlite")) { dbConfig.setDatabasePlatform(new com.avaje.ebean.config.dbplatform.SQLitePlatform()); dbConfig.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } dbConfig.setDataSourceConfig(ds); }
@Override public void configureDbConfig(com.avaje.ebean.config.ServerConfig dbConfig) { com.avaje.ebean.config.DataSourceConfig ds = new com.avaje.ebean.config.DataSourceConfig(); ds.setDriver(config.getString(ServerConfig.Key.DB_DRIVER)); ds.setUrl(config.getString(ServerConfig.Key.DB_URL)); ds.setUsername(config.getString(ServerConfig.Key.DB_USERNAME)); ds.setPassword(config.getString(ServerConfig.Key.DB_PASSWORD)); ds.setIsolationLevel( com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation.getLevel( config.getString(ServerConfig.Key.DB_ISOLATION))); if (ds.getDriver().contains("sqlite")) { dbConfig.setDatabasePlatform(new com.avaje.ebean.config.dbplatform.SQLitePlatform()); dbConfig.getDatabasePlatform().getDbDdlSyntax().setIdentity(""); } dbConfig.setDataSourceConfig(ds); }
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); }