Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()));
- getDataFolder().mkdirs();
- ClassLoader previous = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(classLoader);
- ebean = EbeanServerFactory.create(db);
- Thread.currentThread().setContextClassLoader(previous);
- }
- 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("");
- }
- config.setDataSourceConfig(ds);
- }
- private String replaceDatabaseString(String input) {
- input = input.replaceAll("\\{DIR\\}", getDataFolder().getPath().replaceAll("\\\\", "/") + "/");
- input = input.replaceAll("\\{NAME\\}", getDescription().getName().replaceAll("[^\\w_-]", ""));
- return input;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement