use of org.unidal.dal.jdbc.datasource.DataSourceManager in project x-pipe by ctripcorp.
the class AbstractConsoleH2DbTest method setUpTestDataSource.
private void setUpTestDataSource() throws ComponentLookupException, SQLException, IOException {
DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);
DataSource dataSource = dsManager.getDataSource(DATA_SOURCE);
String driver = dataSource.getDescriptor().getProperty("driver", null);
if (driver != null && driver.equals("org.h2.Driver")) {
executeSqlScript(FileUtils.readFileAsString(TABLE_STRUCTURE));
executeSqlScript(FileUtils.readFileAsString(TABLE_DATA));
} else {
logger.info("[setUpTestDataSource][do not clean]{}", driver);
}
executeSqlScript(prepareDatas());
}
use of org.unidal.dal.jdbc.datasource.DataSourceManager in project x-pipe by ctripcorp.
the class H2Init method setUpTestDataSource.
private void setUpTestDataSource() throws ComponentLookupException, SQLException, IOException {
DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);
DataSource dataSource = dsManager.getDataSource(DATA_SOURCE);
String driver = dataSource.getDescriptor().getProperty("driver", null);
if (driver != null && driver.equals("org.h2.Driver")) {
executeSqlScript(FileUtils.readFileAsString(TABLE_STRUCTURE));
executeSqlScript(FileUtils.readFileAsString(TABLE_DATA));
executeSqlScript(FileUtils.readFileAsString(DEMO_DATA));
} else {
logger.info("[setUpTestDataSource][do not clean]{}", driver);
}
}
use of org.unidal.dal.jdbc.datasource.DataSourceManager in project x-pipe by ctripcorp.
the class AbstractConsoleH2DbTest method executeSqlScript.
protected void executeSqlScript(String prepareSql) throws ComponentLookupException, SQLException {
DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = dsManager.getDataSource(DATA_SOURCE).getConnection();
conn.setAutoCommit(false);
if (!Strings.isEmpty(prepareSql)) {
for (String sql : prepareSql.split(";")) {
logger.debug("[setup][data]{}", sql.trim());
stmt = conn.prepareStatement(sql);
stmt.executeUpdate();
}
}
conn.commit();
} catch (Exception ex) {
logger.error("[SetUpTestDataSource][fail]:", ex);
if (null != conn) {
conn.rollback();
}
} finally {
if (null != stmt) {
stmt.close();
}
if (null != conn) {
conn.setAutoCommit(true);
conn.close();
}
}
}
use of org.unidal.dal.jdbc.datasource.DataSourceManager in project x-pipe by ctripcorp.
the class H2Init method executeSqlScript.
protected void executeSqlScript(String prepareSql) throws ComponentLookupException, SQLException {
DataSourceManager dsManager = ContainerLoader.getDefaultContainer().lookup(DataSourceManager.class);
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = dsManager.getDataSource(DATA_SOURCE).getConnection();
conn.setAutoCommit(false);
if (!Strings.isEmpty(prepareSql)) {
for (String sql : prepareSql.split(";")) {
logger.debug("[setup][data]{}", sql.trim());
stmt = conn.prepareStatement(sql);
stmt.executeUpdate();
}
}
conn.commit();
} catch (Exception ex) {
logger.error("[SetUpTestDataSource][fail]:", ex);
if (null != conn) {
conn.rollback();
}
} finally {
if (null != stmt) {
stmt.close();
}
if (null != conn) {
conn.setAutoCommit(true);
conn.close();
}
}
}
Aggregations