本文整理汇总了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);
}
}