本文整理匯總了Java中org.dbunit.operation.DatabaseOperation.execute方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseOperation.execute方法的具體用法?Java DatabaseOperation.execute怎麽用?Java DatabaseOperation.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dbunit.operation.DatabaseOperation
的用法示例。
在下文中一共展示了DatabaseOperation.execute方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.dbunit.operation.DatabaseOperation; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
initialDataSet = new FlatXmlDataSetBuilder().build(new File("src/test/resources/test-data.xml"));
connection = new DatabaseConnection(DriverManager.getConnection(CONNECTION_URL, USER_NAME, PASSWORD));
final DatabaseOperation operation = DatabaseOperation.CLEAN_INSERT;
operation.execute(connection, initialDataSet);
connection.getConnection().createStatement().execute(
"insert into XML_TABLE_1(id, version, value_1, value_2, value_3, value_4, value_5) values(10, 'Record 10 version', 'Record 10 Value 1', 'Record 10 Value 2', 'Record 10 Value 3', 'Record 10 Value 4', 'Record 10 Value 5');");
connection.getConnection().commit();
connection.getConnection().createStatement().execute(
"merge into XML_TABLE_3(id, version, value_8, value_9) values(11, 'Record 11 version', 'Record 11 Value 8', 'Record 11 Value 9');");
connection.getConnection().commit();
assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(4));
assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1));
assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1));
}
示例2: execute
import org.dbunit.operation.DatabaseOperation; //導入方法依賴的package包/類
/**
* 對XML文件中的數據在H2數據庫中執行Operation.
*
* @param xmlFilePaths 符合Spring Resource路徑格式的文件列表.
*/
private static void execute(DatabaseOperation operation, DataSource dataSource, String... xmlFilePaths)
throws DatabaseUnitException, SQLException {
//注意這裏HardCode了使用H2的Connetion
IDatabaseConnection connection = new H2Connection(dataSource.getConnection(), null);
for (String xmlPath : xmlFilePaths) {
try {
InputStream input = resourceLoader.getResource(xmlPath).getInputStream();
IDataSet dataSet = new FlatXmlDataSetBuilder().setColumnSensing(true).build(input);
operation.execute(connection, dataSet);
} catch (IOException e) {
logger.warn(xmlPath + " file not found", e);
}finally{
connection.close();
}
}
}
示例3: createSeedDataFeature
import org.dbunit.operation.DatabaseOperation; //導入方法依賴的package包/類
@Override
protected DbFeature<IDatabaseConnection> createSeedDataFeature(final DataSeedStrategy dataSeedStrategy,
final List<IDataSet> initialDataSets) {
return (final IDatabaseConnection connection) -> {
try {
final DatabaseOperation operation = dataSeedStrategy.provide(providerFactory.createDataSeedStrategyProvider());
operation.execute(connection, mergeDataSets(initialDataSets));
} catch (DatabaseUnitException | SQLException e) {
throw new DbFeatureException("Could not execute DB seed feature", e);
}
};
}
示例4: with
import org.dbunit.operation.DatabaseOperation; //導入方法依賴的package包/類
/**
* @author Wasiq B
* @since 24-Nov-2015 8:51:44 pm
* @param operation
* @throws FrameworkException
*/
public void with (final DatabaseOperation operation) throws FrameworkException {
try {
log.entry ();
final DatabaseOperation refresh = new InsertIdentityOperation (operation);
refresh.execute (getConnection (), getDataSet ());
}
catch (final Exception e) {
log.catching (e);
throw new FrameworkException ("with", e);
}
finally {
log.exit ();
}
}
示例5: execute
import org.dbunit.operation.DatabaseOperation; //導入方法依賴的package包/類
/**
* Executes DbUnit <code>operation</code> on dataset
* <code>dataSetSource</code>.
*/
protected void execute(DatabaseOperation operation, DataSetSource dataSetSource) {
IDatabaseConnection dbconn = null;
try {
dbconn = connectionCreator.create();
operation.execute(dbconn, findDataSet(dataSetSource));
} catch (Exception e) {
throw new IllegalStateException(
"It's not possible to execute DbUnit operation: "
+ e.getMessage(), e);
} finally {
connectionCreator.close(dbconn);
}
}