private EbeanServer initializeDatabase(boolean dropAndCreateDatabase, String dbName) {
    ServerConfig config = new ServerConfig();
    config.setName(dbName);
    DataSourceConfig hdDB = new DataSourceConfig();
    hdDB.setDriver("org.h2.Driver");
    hdDB.setUsername("test");
    hdDB.setPassword("test");
    hdDB.setUrl("jdbc:h2:mem:tests;DB_CLOSE_DELAY=-1");
    hdDB.setHeartbeatSql("select 1 ");
    config.setDataSourceConfig(hdDB);

    config.setDefaultServer(false);
    config.setRegister(false);

    if (dropAndCreateDatabase) {
      config.setDdlGenerate(true);
      config.setDdlRun(true);
      // config.setDebugSql(true);
    }

    config.addClass(Viite.class);
    config.addClass(Attribuutti.class);

    return EbeanServerFactory.create(config);
  }
  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);
  }