本文整理汇总了Java中org.dbunit.database.QueryDataSet类的典型用法代码示例。如果您正苦于以下问题:Java QueryDataSet类的具体用法?Java QueryDataSet怎么用?Java QueryDataSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryDataSet类属于org.dbunit.database包,在下文中一共展示了QueryDataSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
public static void main(String[] args)
throws Exception
{
//Connect to the database
Class.forName( "com.mysql.jdbc.Driver" );
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/easyrec_test", "root", "root");
IDatabaseConnection connection = new DatabaseConnection( conn );
QueryDataSet partialDataSet = new QueryDataSet(connection);
//Specify the SQL to run to retrieve the data
partialDataSet.addTable("actionarchive1", " SELECT * FROM actionarchive1");
//Specify the location of the flat file(XML)
// file is stored in /target folder
FlatXmlWriter datasetWriter = new FlatXmlWriter(new FileOutputStream("easyrec-testutils/target/temp.xml"));
//Export the data
datasetWriter.write( partialDataSet );
}
示例2: addQueries
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
private void addQueries(final QueryDataSet dataSet) throws AmbiguousTableNameException {
if (queryList == null) {
return;
}
for (Object element : queryList) {
String query = (String) element;
Matcher m = TABLE_MATCH_PATTERN.matcher(query);
if (!m.matches()) {
logger.warn("Unable to parse query. Ignoring '" + query + "'.");
} else {
String table = m.group(1);
// only add if the table has not been added
if (tableList != null && tableList.contains(table)) {
logger.warn("Table '" + table + "' already added. Ignoring '" + query + "'.");
} else {
dataSet.addTable(table, query);
}
}
}
}
示例3: backupCustomTable
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
protected void backupCustomTable(String[] tname) throws DataSetException, IOException {
QueryDataSet ds = new QueryDataSet(dbunitCon);
for(String str:tname) {
ds.addTable(str);
}
writeBackupFile(ds);
}
示例4: writeQueryTablesToFile
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
public void writeQueryTablesToFile(Map<String, String> queries, File output) throws Exception {
QueryDataSet dataSet = new QueryDataSet(this.dbUnitConnection);
for (String table : queries.keySet()) {
dataSet.addTable(table, queries.get(table));
}
if (output.getName().endsWith(".xml")) {
FlatXmlDataSet.write(dataSet, new FileOutputStream(output));
} else if (output.getName().endsWith(".xls")) {
XlsDataSet.write(dataSet, new FileOutputStream(output));
} else {
new CsvDataSetWriter(output).write(dataSet);
}
}
示例5: doWork
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
public static void doWork(Connection conn, TreeMap<String, String> tableQueryMap) throws Exception
{
IDatabaseConnection connection = new DatabaseConnection(conn);
// partial database export
QueryDataSet partialDataSet = new QueryDataSet(connection);
for (String table : tableQueryMap.keySet()) {
partialDataSet.addTable(table, tableQueryMap.get(table));
}
FlatXmlDataSet.write(partialDataSet, System.out);
}
示例6: testCompare
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void testCompare() throws Exception {
QueryDataSet actualDataSet = new QueryDataSet( getConnection() );
liquiBase.update( new Contexts() );
actualDataSet.addTable( TABLE_NAME, "SELECT * from " + TABLE_NAME );
loadedDataSet = getDataSet();
Assertion.assertEquals( loadedDataSet, actualDataSet );
}
示例7: writeExpectedFile
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
protected void writeExpectedFile(IDatabaseConnection dbunitConnection,
File outputFile, String tableName) throws IOException,
DataSetException {
QueryDataSet partialDataSet = new QueryDataSet(dbunitConnection);
partialDataSet.addTable(tableName);
FlatXmlDataSet.write(partialDataSet, new FileOutputStream(outputFile));
}
示例8: extract
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
/**
* Performs the extraction. If no tables or queries are specified, data from
* entire database will be extracted.
* Otherwise, a partial extraction will be performed.
*
* @throws Exception
*/
public void extract() throws Exception {
Connection conn = null;
try {
conn = dataSource.getConnection();
logger.info("Beginning extraction from '" + conn.toString() + "'.");
IDatabaseConnection connection = new DatabaseConnection(conn, schema);
configConnection((DatabaseConnection) connection);
if (tableList != null || queryList != null) {
// partial database export
QueryDataSet partialDataSet = new QueryDataSet(connection);
addTables(partialDataSet);
addQueries(partialDataSet);
FlatXmlDataSet.write(partialDataSet, new FileOutputStream(dataSetName));
} else {
// full database export
IDataSet fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream(dataSetName));
// dependent tables database export: export table X and all
// tables that
// have a PK which is a FK on X, in the right order for
// insertion
String[] depTableNames = TablesDependencyHelper.getAllDependentTables(connection, "research");
IDataSet depDataset = connection.createDataSet(depTableNames);
FlatXmlWriter datasetWriter = new FlatXmlWriter(new FileOutputStream("target/dependents.xml"));
datasetWriter.write(depDataset);
}
} finally {
if (conn != null) {
conn.close();
}
}
logger.info("Completed extraction to '" + dataSetName + "'.");
}
示例9: addTables
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
private void addTables(final QueryDataSet dataSet) throws AmbiguousTableNameException {
if (tableList == null) {
return;
}
for (Object element : tableList) {
String table = (String) element;
dataSet.addTable(table);
}
}
示例10: safelyCsvExportAndImportStandardColumnTables
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void safelyCsvExportAndImportStandardColumnTables()
throws IOException, DatabaseUnitException, SQLException {
IDatabaseConnection dbunit_conn = new DatabaseConnection(conn);
// cache(save) expected data snap-shot.
IDataSet expectedDataSet = new CachedDataSet(
dbunit_conn.createDataSet());
// export only t1, t2 table to CSV
QueryDataSet exportDataSet = new QueryDataSet(dbunit_conn);
exportDataSet.addTable("t1");
exportDataSet.addTable("t2");
CsvDataSetWriter.write(exportDataSet, tmpDir);
// after export, insert new record to t3 (not exported)
new T3("new label").insertMe(conn);
// clear & insert from exported CSV
IDataSet csvDataSet = new CsvDataSet(tmpDir);
DatabaseOperation.CLEAN_INSERT.execute(dbunit_conn, csvDataSet);
IDataSet actualDataSet = dbunit_conn.createDataSet();
Assertion.assertEquals(expectedDataSet.getTable("t1"),
actualDataSet.getTable("t1"));
Assertion.assertEquals(expectedDataSet.getTable("t2"),
actualDataSet.getTable("t2"));
// this produce assertion error : table record will be 3.
// Assertion.assertEquals(expectedDataSet.getTable("t3"),
// actualDataSet.getTable("t3"));
assertEquals(3, actualDataSet.getTable("t3").getRowCount());
}
示例11: customExportAndImportForControlCodeStrings
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void customExportAndImportForControlCodeStrings()
throws IOException, DatabaseUnitException, SQLException {
IDatabaseConnection dbunit_conn = new DatabaseConnection(conn);
// cache(save) expected data snap-shot.
IDataSet expectedDataSet = new CachedDataSet(
dbunit_conn.createDataSet());
// H2DB can store and load binary string to varchar column safely.
Set<T4> a = new T4().findAll(conn);
for (T4 a2 : a) {
assertEquals(a2.stringField, UnsignedByte.create0x00to0xFFString());
}
// export t4 using base64 binary safely csv dataset writer.
QueryDataSet exportDataSet = new QueryDataSet(dbunit_conn);
exportDataSet.addTable("t4");
CsvBase64BinarySafeDataSetWriter.write(exportDataSet, tmpDir);
// clear & insert from exported CSV using base64 binary safely csv data producer.
IDataSet csvDataSet = new CsvBase64BinarySafeDataSet(tmpDir);
DatabaseOperation.CLEAN_INSERT.execute(dbunit_conn, csvDataSet);
IDataSet actualDataSet = dbunit_conn.createDataSet();
Assertion.assertEquals(expectedDataSet.getTable("t4"),
actualDataSet.getTable("t4"));
}
示例12: testCompare
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void testCompare() throws Exception {
if (connection == null) {
return;
}
QueryDataSet actualDataSet = new QueryDataSet(getConnection());
liquiBase.update((String) null);
actualDataSet.addTable("USER_TRIGGERS", "SELECT STATUS from " + TABLE_NAME
+ " WHERE TRIGGER_NAME = 'RENAMEDZUIOLTRIGGER'");
loadedDataSet = getDataSet();
Assertion.assertEquals(loadedDataSet, actualDataSet);
}
示例13: updateTest
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void updateTest() throws Exception {
if (connection == null) {
return;
}
QueryDataSet actualDataSet = new QueryDataSet(getConnection());
actualDataSet.addTable("T" + TABLE_NAME);
actualDataSet.addTable(TABLE_NAME);
loadedDataSet = getDataSet();
Assertion.assertEquals(loadedDataSet, actualDataSet);
}
示例14: rollbackTest
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void rollbackTest() throws Exception {
if (connection == null) {
return;
}
liquiBase.rollback(1, (String) null);
QueryDataSet actualDataSet = new QueryDataSet(getConnection());
actualDataSet.addTable(TABLE_NAME);
loadedDataSet = getAfterRollbackDataSet();
Assertion.assertEquals(loadedDataSet, actualDataSet);
}
示例15: testCompare
import org.dbunit.database.QueryDataSet; //导入依赖的package包/类
@Test
public void testCompare() throws Exception {
if (connection == null) {
return;
}
QueryDataSet actualDataSet = new QueryDataSet(getConnection());
liquiBase.update((String) null);
actualDataSet.addTable("USER_TRIGGERS", "SELECT TRIGGER_NAME from " + TABLE_NAME
+ " WHERE table_name = 'TRIGGERTEST'");
loadedDataSet = getDataSet();
Assertion.assertEquals(loadedDataSet, actualDataSet);
}