本文整理汇总了Java中play.db.DB.getDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java DB.getDataSource方法的具体用法?Java DB.getDataSource怎么用?Java DB.getDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.db.DB
的用法示例。
在下文中一共展示了DB.getDataSource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStart
import play.db.DB; //导入方法依赖的package包/类
@Override
public void onStart(Application app) {
super.onStart(app);
// DI初期化
List<Module> moduleList = new ArrayList<Module>();
DataSource dataSource = DB.getDataSource();
moduleList.add(new MirageCustomModule(dataSource));
moduleList.add(new TransactionModule(dataSource));
// Create Injector
if (app.isProd())
INJECTOR = Guice.createInjector(Stage.PRODUCTION, moduleList.toArray(new Module[] {}));
else
INJECTOR = Guice.createInjector(Stage.DEVELOPMENT, moduleList.toArray(new Module[] {}));
}
示例2: checkEvolutionsState
import play.db.DB; //导入方法依赖的package包/类
public synchronized static void checkEvolutionsState() {
if (DB.getDataSource() != null && evolutionsDirectory.exists()) {
List<Evolution> evolutionScript = getEvolutionScript();
Connection connection = null;
try {
connection = getNewConnection();
ResultSet rs = connection.createStatement().executeQuery("select id, hash, apply_script, revert_script, state, last_problem from play_evolutions where state like 'applying_%'");
if (rs.next()) {
int revision = rs.getInt("id");
String state = rs.getString("state");
String hash = rs.getString("hash").substring(0, 7);
String script = rs.getString("apply_script");
script = "# --- Rev:" + revision + ",Ups - " + hash + "\n\n" + script;
String error = rs.getString("last_problem");
throw new InconsistentDatabase(script, error, revision);
}
} catch (SQLException e) {
throw new UnexpectedException(e);
} finally {
closeConnection(connection);
}
if (!evolutionScript.isEmpty()) {
throw new InvalidDatabaseRevision(toHumanReadableScript(evolutionScript));
}
}
}
示例3: getBoneCPStatistics
import play.db.DB; //导入方法依赖的package包/类
/**
* Get BoneCP stats
*/
public static com.jolbox.bonecp.Statistics getBoneCPStatistics() {
BoneCPDataSource boneCPdatasource = (BoneCPDataSource) DB.getDataSource();
try {
Field field = boneCPdatasource.getClass().getDeclaredField("pool");
field.setAccessible(true);
BoneCP boneCP = (BoneCP) field.get(boneCPdatasource);
return boneCP.getStatistics();
} catch (Exception e) {
Logger.error(e.toString(), e);
}
return null;
}
示例4: testGetDataSource
import play.db.DB; //导入方法依赖的package包/类
@Test
public void testGetDataSource() {
DataSource ds = DB.getDataSource();
assertNotNull(ds);
}