Advertisement
morganm

Untitled

Nov 21st, 2011
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. if (description.isDatabaseEnabled()) {
  2. ServerConfig db = new ServerConfig();
  3.  
  4. db.setDefaultServer(false);
  5. db.setRegister(false);
  6. db.setClasses(getDatabaseClasses());
  7. db.setName(description.getName());
  8. server.configureDbConfig(db);
  9.  
  10. DataSourceConfig ds = db.getDataSourceConfig();
  11.  
  12. ds.setUrl(replaceDatabaseString(ds.getUrl()));
  13. getDataFolder().mkdirs();
  14.  
  15. ClassLoader previous = Thread.currentThread().getContextClassLoader();
  16.  
  17. Thread.currentThread().setContextClassLoader(classLoader);
  18. ebean = EbeanServerFactory.create(db);
  19. Thread.currentThread().setContextClassLoader(previous);
  20. }
  21.  
  22.  
  23.  
  24. public void configureDbConfig(ServerConfig config) {
  25. DataSourceConfig ds = new DataSourceConfig();
  26. ds.setDriver(configuration.getString("database.driver"));
  27. ds.setUrl(configuration.getString("database.url"));
  28. ds.setUsername(configuration.getString("database.username"));
  29. ds.setPassword(configuration.getString("database.password"));
  30. ds.setIsolationLevel(TransactionIsolation.getLevel(configuration.getString("database.isolation")));
  31.  
  32. if (ds.getDriver().contains("sqlite")) {
  33. config.setDatabasePlatform(new SQLitePlatform());
  34. config.getDatabasePlatform().getDbDdlSyntax().setIdentity("");
  35. }
  36.  
  37. config.setDataSourceConfig(ds);
  38. }
  39.  
  40. private String replaceDatabaseString(String input) {
  41. input = input.replaceAll("\\{DIR\\}", getDataFolder().getPath().replaceAll("\\\\", "/") + "/");
  42. input = input.replaceAll("\\{NAME\\}", getDescription().getName().replaceAll("[^\\w_-]", ""));
  43. return input;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement