当前位置: 首页>>代码示例>>Java>>正文


Java QueryDataSet类代码示例

本文整理汇总了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 );
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:22,代码来源:DbUnitSqlToXmlExporter.java

示例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);
            }
        }
    }
}
 
开发者ID:antoniomaria,项目名称:gazpachoquest,代码行数:21,代码来源:DBUnitDataExtractor.java

示例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);
}
 
开发者ID:SoftwareKing,项目名称:SpringCloud,代码行数:8,代码来源:AbstractDbUnitTestCase.java

示例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);
    }
}
 
开发者ID:0xC70FF3,项目名称:java-gems,代码行数:14,代码来源:DBMock.java

示例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);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:13,代码来源:DatabaseExport.java

示例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 );
}
 
开发者ID:mrswadge,项目名称:liquibase-flexibleview,代码行数:11,代码来源:CreateFlexibleViewDBTest.java

示例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));
}
 
开发者ID:JadiraOrg,项目名称:jadira,代码行数:10,代码来源:DatabaseCapable.java

示例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 + "'.");
}
 
开发者ID:antoniomaria,项目名称:gazpachoquest,代码行数:44,代码来源:DBUnitDataExtractor.java

示例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);
    }
}
 
开发者ID:antoniomaria,项目名称:gazpachoquest,代码行数:10,代码来源:DBUnitDataExtractor.java

示例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());
}
 
开发者ID:msakamoto-sf,项目名称:javasnack,代码行数:33,代码来源:DbUnitCsvUsageTest.java

示例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"));
}
 
开发者ID:msakamoto-sf,项目名称:javasnack,代码行数:29,代码来源:DbUnitCsvUsageTest.java

示例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);
}
 
开发者ID:liquibase,项目名称:liquibase-oracle,代码行数:15,代码来源:DisableTriggerDBTest.java

示例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);
}
 
开发者ID:liquibase,项目名称:liquibase-oracle,代码行数:14,代码来源:EncapsulateTableWithViewDBTest.java

示例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);
}
 
开发者ID:liquibase,项目名称:liquibase-oracle,代码行数:15,代码来源:EncapsulateTableWithViewDBTest.java

示例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);
}
 
开发者ID:liquibase,项目名称:liquibase-oracle,代码行数:15,代码来源:RenameTriggerDBTest.java


注:本文中的org.dbunit.database.QueryDataSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。