當前位置: 首頁>>代碼示例>>Java>>正文


Java IDatabaseConnection.createDataSet方法代碼示例

本文整理匯總了Java中org.dbunit.database.IDatabaseConnection.createDataSet方法的典型用法代碼示例。如果您正苦於以下問題:Java IDatabaseConnection.createDataSet方法的具體用法?Java IDatabaseConnection.createDataSet怎麽用?Java IDatabaseConnection.createDataSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dbunit.database.IDatabaseConnection的用法示例。


在下文中一共展示了IDatabaseConnection.createDataSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createVerifyDataAfterFeature

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Override
protected DbFeature<IDatabaseConnection> createVerifyDataAfterFeature(final ExpectedDataSets expectedDataSets) {
    return (final IDatabaseConnection connection) -> {
        try {
            final IDataSet currentDataSet = connection.createDataSet();
            final IDataSet expectedDataSet = mergeDataSets(loadDataSets(Arrays.asList(expectedDataSets.value())));

            final DataSetComparator dataSetComparator = new DataSetComparator(expectedDataSets.orderBy(),
                    expectedDataSets.excludeColumns(), expectedDataSets.strict(), getColumnFilter(expectedDataSets));

            final AssertionErrorCollector errorCollector = new AssertionErrorCollector();
            dataSetComparator.compare(currentDataSet, expectedDataSet, errorCollector);

            errorCollector.report();
        } catch (final SQLException | DatabaseUnitException e) {
            throw new DbFeatureException("Could not execute DB contents verification feature", e);
        }
    };
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:20,代碼來源:SqlDbFeatureExecutor.java

示例2: compareTables

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public void compareTables(String expectedDatasetFileName, String... tableNames) throws Exception {
	JdbcDatabaseTester jdbc = new JdbcDatabaseTester("org.hsqldb.jdbcDriver", "jdbc:hsqldb:file:./db/example-db;ifexists=true;shutdown=true;", "sa", "");
	IDatabaseConnection connection = jdbc.getConnection();
	
	DatabaseConfig config = connection.getConfig();
	config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
	
	IDataSet databaseDataSet = connection.createDataSet();
	IDataSet expectedDataSet = new FlatXmlDataFileLoader().load(expectedDatasetFileName);
	
	for (String tableName : tableNames) {
		ITable actualTable = databaseDataSet.getTable(tableName);
		ITable expectedTable = expectedDataSet.getTable(tableName);
		Assertion.assertEquals(expectedTable, actualTable);
	}
}
 
開發者ID:EsfingeFramework,項目名稱:querybuilder,代碼行數:17,代碼來源:DataBaseCommunicator.java

示例3: doRecreate

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Test
public void doRecreate() throws DatabaseUnitException, SQLException, FileNotFoundException {
	IDatabaseConnection dconnection = new DatabaseConnection(dataSource.getConnection());
	IDataSet dataSet = dconnection.createDataSet();
	File file = new File("formbuilder-dataset.dtd");
	
	Assert.assertTrue("DTD file can not be deleted.", !file.exists() || file.delete());
	
	Writer out = new OutputStreamWriter(new FileOutputStream(file));
	FlatDtdWriter datasetWriter = new FlatDtdWriter(out);
	datasetWriter.setContentModel(FlatDtdWriter.CHOICE);
	// You could also use the sequence model which is the default
	// datasetWriter.setContentModel(FlatDtdWriter.SEQUENCE);
	datasetWriter.write(dataSet);
	
	Assert.assertTrue("DTD file did not created.", file.exists());
}
 
開發者ID:NCIP,項目名稱:edct-formbuilder,代碼行數:18,代碼來源:RecreateDBUnitDTDTestCase.java

示例4: main

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception
{
    Class driverClass = Class.forName("org.postgresql.Driver");
    Connection jdbcConnection = DriverManager.getConnection(
            "jdbc:postgresql://localhost:5432/FormBuilder?autoReconnect=true", "fbdev", "fbdev");
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

    // partial database export
    /*QueryDataSet partialDataSet = new QueryDataSet(connection);
    partialDataSet.addTable("FOO", "SELECT * FROM TABLE WHERE COL='VALUE'");
    partialDataSet.addTable("BAR");
    FlatXmlDataSet.write(partialDataSet, new FileOutputStream("partial.xml"));*/

    // full database export
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream("skips_on_table.xml"));
    
    // 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, "X" );
    IDataSet depDataset = connection.createDataSet( depTableNames );
    FlatXmlDataSet.write(depDataSet, new FileOutputStream("dependents.xml"));*/          
    
}
 
開發者ID:NCIP,項目名稱:edct-formbuilder,代碼行數:26,代碼來源:DatabaseExport.java

示例5: generateDtdContent

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
 * Generates the actual content of the DTD file as an in-memory string.
 *
 * @return the DTD content, not null
 */
protected String generateDtdContent() {
    Connection conn = null;
    try {
        conn = sqlHandler.getDataSource().getConnection();
        IDatabaseConnection dbUnitDatabaseConnection = new DatabaseConnection(conn, defaultDbSupport.getSchemaName());

        StringWriter stringWriter = new StringWriter();

        FlatDtdWriter datasetWriter = new FlatDtdWriter(stringWriter);
        datasetWriter.setContentModel(FlatDtdWriter.CHOICE);

        // create a dataset for the database content
        // filter out all system table names
        Set<String> tableNames = defaultDbSupport.getTableNames();
        IDataSet actualDataSet = dbUnitDatabaseConnection.createDataSet();
        IDataSet filteredActualDataSet = new FilteredDataSet(new IncludeTableFilter(tableNames.toArray(new String[0])), actualDataSet);

        datasetWriter.write(filteredActualDataSet);
        return stringWriter.toString();

    } catch (Exception e) {
        throw new UnitilsException("Error generating content for DTD file.", e);
    } finally {
        DbUtils.closeQuietly(conn);
    }
}
 
開發者ID:linux-china,項目名稱:unitils,代碼行數:32,代碼來源:DtdDataSetStructureGenerator.java

示例6: dumpDatabase

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@After
@Transactional
public void dumpDatabase() throws SQLException, DatabaseUnitException, FileNotFoundException, IOException {
    // full database export
    Connection jdbcConnection = dataSource.getConnection();
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream("./target/QueryKeyRepositoryTest-dbunit.xml"));
}
 
開發者ID:jhaood,項目名稱:github-job-keywords,代碼行數:10,代碼來源:QueryKeyRepositoryTest.java

示例7: dumpDatabase

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@After
@Transactional
public void dumpDatabase() throws SQLException, DatabaseUnitException, FileNotFoundException, IOException {
    // full database export
    Connection jdbcConnection = dataSource.getConnection();
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream(
        "./target/TermFrequencyResultsDataManagerTest-dbunit.xml"));
}
 
開發者ID:jhaood,項目名稱:github-job-keywords,代碼行數:11,代碼來源:TermFrequencyResultsDataManagerTest.java

示例8: writeToFileFromDataBase

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
 * 從數據庫中讀取數據寫入到文件中,支持excel和xml格式,以文件後綴名區分
 * @param databaseConnection  使用的IDatabaseConnection數據連接
 * @param destFilePath 寫入文件的路徑
 */
public static void writeToFileFromDataBase(IDatabaseConnection databaseConnection,String destFilePath){
	IDataSet dataSet=null;
	
	try {
		dataSet=databaseConnection.createDataSet();
	} catch (Exception e) {
		log.error("未獲取到測試集");
		log.error(e.getMessage());
		return;
	}
	writeToFileFromDataSet(dataSet,destFilePath);
}
 
開發者ID:sapientTest,項目名稱:Sapient,代碼行數:18,代碼來源:DbUnitUtil.java

示例9: compareTables

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
protected void compareTables(String expectedDatasetFileName, String... tableNames) throws Exception {
	IDatabaseConnection connection = jdt.getConnection();
	
	DatabaseConfig config = connection.getConfig();
	config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
	
	IDataSet databaseDataSet = connection.createDataSet();
	IDataSet expectedDataSet = new FlatXmlDataFileLoader().load(expectedDatasetFileName);
	for (String tableName : tableNames) {
		ITable actualTable = databaseDataSet.getTable(tableName);
		ITable expectedTable = expectedDataSet.getTable(tableName);
		Assertion.assertEquals(expectedTable, actualTable);
	}
}
 
開發者ID:EsfingeFramework,項目名稱:querybuilder,代碼行數:15,代碼來源:QueryBuilderDatabaseTest.java

示例10: main

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Config config = new Config();
    Class.forName(config.getDbDriver());
    Connection jdbcConnection = DriverManager.getConnection(config.getDbUrl(), config.getDbUser(), config.getDbPass());
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection, "public");

    // dtd
    FlatDtdDataSet.write(connection.createDataSet(), new FileOutputStream("src/test/java/it/pronetics/acl/conf/dbunit/database-schema.dtd"));

    // export
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream("src/test/java/opennms/opennms/acl/conf/dbunit/full.xml"));
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:14,代碼來源:DbUnit.java

示例11: extract

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的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

示例12: createDataSet

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public IDataSet createDataSet() throws GoalExecutionException {
	IDatabaseConnection connection = richDriverConfig.createConnection();
	try {
		String[] dependentTables = exportDataSet.getDependentTables();
		IDataSet dataSet = null;
		if (dependentTables == null) {
			dataSet = connection.createDataSet();
		} else {
			String[] depTableNames = TablesDependencyHelper
					.getAllDependentTables(connection, dependentTables);
			dataSet = connection.createDataSet(depTableNames);
		}

		String[] tableNames = dataSet.getTableNames();
		List<String> filteredTableNameList = new ArrayList<String>(
				Arrays.asList(tableNames));

		String[] excludeTables = exportDataSet.getExcludeTables();
		filteredTableNameList.removeAll(Arrays.asList(excludeTables));

		String[] filteredTableNames = (String[]) filteredTableNameList
				.toArray(new String[filteredTableNameList.size()]);

		FilteredDataSet filteredDataSet = new FilteredDataSet(
				filteredTableNames, dataSet);
		return filteredDataSet;
	} catch (Exception e) {
		try {
			connection.close();
		} catch (SQLException e1) {
		}
		throw new GoalExecutionException("Unable to create data set", e);
	}
}
 
開發者ID:link-intersystems,項目名稱:maven,代碼行數:35,代碼來源:RichExportDataSet.java

示例13: safelyCsvExportAndImportStandardColumnTables

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的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

示例14: customExportAndImportForControlCodeStrings

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的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

示例15: main

import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    String driver = System.getProperty("CliDbUnitCsvExportDemo.driver",
            "org.h2.Driver");
    Class.forName(driver);
    String url = System.getProperty("CliDbUnitCsvExportDemo.url",
            "jdbc:h2:mem:CliDbUnitCsvExportDemo");
    String dbUser = System.getProperty("CliDbUnitCsvExportDemo.dbUser",
            "sa");
    String dbPassword = System.getProperty(
            "CliDbUnitCsvExportDemo.dbPassword", "");
    Connection conn = DriverManager.getConnection(url, dbUser, dbPassword);

    CliDbUnitCsvExportDemo demo = new CliDbUnitCsvExportDemo();
    demo.setup(conn);

    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
    Calendar c = Calendar.getInstance();
    File outDir = new File(sdf1.format(c.getTime()));
    outDir.mkdir();

    IDatabaseConnection dbunit_conn = new DatabaseConnection(conn);
    IDataSet dataSet = dbunit_conn.createDataSet();

    CsvBase64BinarySafeDataSetWriter.write(dataSet, outDir);

    conn.close();
}
 
開發者ID:msakamoto-sf,項目名稱:javasnack,代碼行數:28,代碼來源:CliDbUnitCsvExportDemo.java


注:本文中的org.dbunit.database.IDatabaseConnection.createDataSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。