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


Java FlatXmlDataSet类代码示例

本文整理汇总了Java中org.dbunit.dataset.xml.FlatXmlDataSet的典型用法代码示例。如果您正苦于以下问题:Java FlatXmlDataSet类的具体用法?Java FlatXmlDataSet怎么用?Java FlatXmlDataSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FlatXmlDataSet类属于org.dbunit.dataset.xml包,在下文中一共展示了FlatXmlDataSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertDbUnitTestdata

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
 * Inserts test data in DbUnit XML format.
 *
 * @param entityManager
 *           the EntityManager
 * @param dbUnitTestdata
 *           test file stream
 */
public static void insertDbUnitTestdata(EntityManager entityManager, final InputStream dbUnitTestdata) {

   entityManager.unwrap(Session.class).doWork(new Work() {

      @Override
      public void execute(Connection connection) throws SQLException {
         // Insert Testdata
         try {
            LOGGER.debug("INSERTing testdata");
            DatabaseConnection databaseConnection = new DatabaseConnection(connection);
            databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
               new MySqlDataTypeFactory());

            FlatXmlDataSet dataSet = new FlatXmlDataSet(
               new FlatXmlProducer(new InputSource(dbUnitTestdata), false, true));
            DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
            LOGGER.debug("INSERTing testdata ... done");
         } catch (DatabaseUnitException e) {
            throw new SQLException(e);
         }
      }

   });
}
 
开发者ID:kaiwinter,项目名称:testcontainers-examples,代码行数:33,代码来源:DockerDatabaseTestUtil.java

示例2: testDeletion

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
 * Tests export.
 */
public void testDeletion() throws Exception {
	File resultDir = new File(testDir, "result");
	if (!resultDir.exists()) {
		resultDir.mkdir();
	}
	File result = null;
	result = new File(resultDir, "delete.sql");
	File insertResult = new File(resultDir, "insert.sql");
	
	if (doDeletion(datamodelDir, new File(testDir, "extractionmodel.csv"), result, insertResult, scope)) {
		Session statementExecutor = new Session(connectionArguments.get(0), connectionArguments.get(1), connectionArguments.get(2), connectionArguments.get(3));
		SqlScriptExecutor.executeScript(result.getCanonicalPath(), statementExecutor);
		statementExecutor.shutDown();
		
		File actualState = new File(resultDir, "remaining-state.xml");
		IDataSet depDataset = getConnection().createDataSet(getDataSet().getTableNames());
		Writer out = new FileWriter(actualState);
	    FlatXmlDataSet.write(depDataset, out, Charset.defaultCharset().name());
	    out.close();

		assertEqualDatasets(expectedResult, actualState);
	}
}
 
开发者ID:P15,项目名称:jailer,代码行数:27,代码来源:DeletionTestCase.java

示例3: writeToFileFromDataSet

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
 * 把数据集写入到文件中
 * @param dataSet
 * @param destFilePath
 */
public static void writeToFileFromDataSet(IDataSet dataSet,String destFilePath) {
	File destFile = new File(destFilePath);
	try {
			String destFileName = destFile.getName();
			//转换为excel格式
			if(destFileName.endsWith(".xls")){
				XlsDataSet.write(dataSet, new FileOutputStream(destFile));
			}else if(destFileName.endsWith(".xml")){
				FlatXmlDataSet.write(dataSet, new FileOutputStream(destFile));
			}else{
				log.error("文件格式不是xls或者xml,不支持");
				return;
			}
			log.info("写入数据到文件 : "+destFile.getAbsolutePath());
	} catch (Exception e) {
			log.error("写入数据到文件失败");
			log.error(e.getMessage());
	}
}
 
开发者ID:sapientTest,项目名称:Sapient,代码行数:25,代码来源:DbUnitUtil.java

示例4: run

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
@Scheduled(cron = "0 0 3 * * *")
public void run() throws SQLException, DatabaseUnitException, IOException {
    if (enable) {
        log.info("begin backup database");

        String bak = root + "/" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());

        ITableFilter filter = new DatabaseSequenceFilter(conn);
        IDataSet dataSet = new FilteredDataSet(filter, conn.createDataSet());

        //IDataSet dataSet = conn.createDataSet();
        FlatXmlDataSet.write(dataSet, new FileOutputStream(bak + ".xml"));
        FlatDtdDataSet.write(dataSet, new FileOutputStream(bak + ".dtd"));
        log.info("end backup database");
    }


}
 
开发者ID:chonglou,项目名称:itpkg,代码行数:19,代码来源:BackupJob.java

示例5: test

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
@Test
public void test() throws Exception
{
	// DB is initially empty
	new DbUnitAssert().assertEquals(new FlatXmlDataSetBuilder().build(new StringReader("<dataset><SimpleEntity/><GroupEntity/><simple_entity_join_table/></dataset>")),
	                                dataset.get());

	// Add some db contents
	try (HibernateTransaction tx = txutils.start().withAutoCommit())
	{
		dao.save(new SimpleEntity(1, "alice", new GroupEntity(1), new GroupEntity(2)));
		dao.save(new SimpleEntity(2, "bob"));
		dao.save(new SimpleEntity(3, "carol"));
		dao.save(new SimpleEntity(4, "dave"));
	}

	// DB should now have 4 rows
	FlatXmlDataSet expected = new FlatXmlDataSetBuilder().build(this.getClass()
	                                                                .getResourceAsStream("/com/peterphi/std/guice/hibernatetest/alice-bob-carol-dave-dataset.xml"));
	new DbUnitAssert().assertEquals(expected, dataset.get());
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:22,代码来源:DbunitModuleTest.java

示例6: main

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的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

示例7: getBuilder

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
 * Permet de créer un dataSet pouvant parser un fichier xml.
 * @return {@link IDataSet}
 * @throws SaladiumException
 */
private IDataSet getBuilder(File file) throws SaladiumException {
    FlatXmlDataSetBuilder dataSetBuilder = new FlatXmlDataSetBuilder();
    dataSetBuilder.setColumnSensing(true);
    dataSetBuilder.setCaseSensitiveTableNames(true);
    dataSetBuilder.setDtdMetadata(false);
    try {
        // FileInputStream xmlInputFile = new FileInputStream(file);
        FlatXmlDataSet dataSet = dataSetBuilder.build(file);
        // xmlInputFile.close();
        return dataSet;
    } catch (Exception e) {
        throw new SaladiumException(e);
    }
}
 
开发者ID:Nonorc,项目名称:saladium,代码行数:20,代码来源:AbstractWorker.java

示例8: migrate

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
 * Run the migration using the given context.
 *
 * @param context the context to run under
 * @throws MigrationException if an unexpected error occurs
 */
public void migrate(MigrationContext context) throws MigrationException
{
    log.debug("Executing patch " + getLevel());
    // down casting, technically not safe, but everyone else is doing it.
    JdbcMigrationContext jdbcContext = (JdbcMigrationContext) context;
    // used to close connection in finally block
    Connection contextConnection = null;
    try
    {
        FlatXmlDataSet xmlDataSet = new FlatXmlDataSet(getXmlAsStream());
        // Set contextConnection so it can be accessed in the finally block.
        contextConnection = jdbcContext.getConnection();

        // run the data load
        IDatabaseConnection connection = new DatabaseConnection(contextConnection);
        DatabaseOperation.INSERT.execute(connection, xmlDataSet);
        context.commit();

        // Closing here instead of in finally block to keep the signature of this from throwing
        // a SqlException.  Exceptional condition handled in finally block to make sure
        // we don't leak a connection.
        connection.close();
    }
    catch (Exception e)
    {
        log.debug("Unable to patch due to " + e.getMessage());
        context.rollback();
        throw new MigrationException("Unable to patch", e);
    }
    finally
    {
        // Might already be closed if everything worked fine and connection.close was called 
        // above, in that case, calling close again shouldn't do any harm.  However, if an 
        // exception occurred the DBUnit based connection wrapper didn't get closed, so we 
        // catch that case here.
        SqlUtil.close(contextConnection, null, null);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:45,代码来源:FlatXmlDataSetMigrationTask.java

示例9: generateString

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
@Override
public String generateString() throws IOException, SQLException, DatabaseUnitException {
  StringWriter writer = new StringWriter();
  try {
    IDataSet modifiedDataSet = modify(dataSet);
    FlatXmlDataSet.write(modifiedDataSet, writer);
    return writer.toString();
  } finally {
    writer.close();
  }
}
 
开发者ID:frank780117,项目名称:dbunit-ext,代码行数:12,代码来源:FlatXmlDataSetGenerator.java

示例10: writeDataSetString

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
@Override
public void writeDataSetString(File file) throws IOException, SQLException, DatabaseUnitException {
  OutputStream outputStream = new FileOutputStream(file);
  try {
    IDataSet modifiedDataSet = modify(dataSet);
    FlatXmlDataSet.write(modifiedDataSet, outputStream);
  } finally {
    outputStream.close();
  }
}
 
开发者ID:frank780117,项目名称:dbunit-ext,代码行数:11,代码来源:FlatXmlDataSetGenerator.java

示例11: assertDatabaseState

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
    * Asserts that the database is in a given state.
    * 
    * @param expectedState file name of dataset holding the expected state
    */
   @SuppressWarnings("deprecation")
protected void assertDatabaseState(String expectedState) throws Exception {
	// Fetch database data after executing your code
       IDataSet databaseDataSet = getConnection().createDataSet();
       IDataSet initialDataSet = new FlatXmlDataSet(new File(expectedState), false, true);
       
       // compare tables
       for (ITable table: initialDataSet.getTables()) {
       	ITable actualTable = databaseDataSet.getTable(table.getTableMetaData().getTableName());
       	ITable filteredTable = DefaultColumnFilter.includedColumnsTable(actualTable, 
                   table.getTableMetaData().getColumns());
       	Assertion.assertEquals(new SortedTable(table), new SortedTable(filteredTable));
       }
}
 
开发者ID:P15,项目名称:jailer,代码行数:20,代码来源:DbmsAwareTestCase.java

示例12: assertEqualDatasets

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
/**
    * Asserts that the two database states are equal.
    * 
    * @param expectedState file name of dataset holding the expected state
    * @param actualState file name of dataset holding the actual state
    */
   @SuppressWarnings("deprecation")
protected void assertEqualDatasets(File expectedState, File actualState) throws Exception {
       IDataSet expected = new FlatXmlDataSet(expectedState, false, true);
       IDataSet actual = new FlatXmlDataSet(actualState, false, true);
       
       // compare tables
       for (ITable table: expected.getTables()) {
       	ITable actualTable = actual.getTable(table.getTableMetaData().getTableName());
       	Assertion.assertEquals(new SortedTable(table), new SortedTable(actualTable));
       }
}
 
开发者ID:P15,项目名称:jailer,代码行数:18,代码来源:DbmsAwareTestCase.java

示例13: dumpDatabase

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的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

示例14: dumpDatabase

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的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

示例15: loadFlatXmlDataStream

import org.dbunit.dataset.xml.FlatXmlDataSet; //导入依赖的package包/类
public IDataSet loadFlatXmlDataStream(Class<?> c, String resource, boolean resetDtdSchema) throws Exception {
        FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
        builder.setMetaDataSetFromDtd(getDtdSchema(resetDtdSchema));
//        builder.setMetaDataSet(getConnection().createDataSet());
        FlatXmlDataSet fds = builder.build(getResourceStream(c, resource));
        return fds;
    }
 
开发者ID:proarc,项目名称:proarc,代码行数:8,代码来源:DbUnitSupport.java


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