Skip to content

Instantly share code, notes, and snippets.

@guillaumebort
Created September 30, 2011 10:22
Show Gist options
  • Save guillaumebort/1253368 to your computer and use it in GitHub Desktop.
Save guillaumebort/1253368 to your computer and use it in GitHub Desktop.
public static class ManagedDatasource {
final BoneCPDataSource ds;
final String url;
public ManagedDatasource(BoneCPDataSource ds, String url) {
this.ds = ds;
this.url = url;
}
}
private DBApi dbs = null;
private DBApi getDbs() {
synchronized(dbs) {
if(dbs == null) {
Configuration dbConf = app.configuration.getSub("db");
Map<String,ManagedDatasource> datasources = new HashMap<String,ManagedDatasource>();
if(dbConf != null) {
for(String key: dbConf.subkeys()) {
ManagedDatasource ds = DBApi.createDataSource(dbConf.getSub(key), app.classloader);
datasources.put(key, new ManagedDatasource(ds));
}
}
dbs = new DBApi(datasources);
}
return dbs;
}
}
lazy val dbs = {
DBApi(app.configuration.getSub("db").map { dbConf =>
dbConf.subKeys.map { db =>
db -> DBApi.createDataSource(dbConf.getSub(db).get, app.classloader)
}.toMap
}.getOrElse(Map.empty))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment