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


Java DatabaseOperation类代码示例

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


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

示例1: insertData

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
/**
 * Inserts the file of the dbUnit compliant flat xml file into the database
 * used by the system.
 * 
 * @param dbSrcFileName
 *            The name of the file to be imported.
 * @throws IOException
 * @throws DataSetException
 * @throws DatabaseUnitException
 * @throws SQLException
 */
public static void insertData(String dbSourceFileLocation)
        throws IOException, DataSetException, DatabaseUnitException,
        SQLException {
    if (dbSourceFileLocation == null) {
        return;
    }
    ReplacementDataSet dataSet = new ReplacementDataSet(
            new FlatXmlDataSetBuilder()
                    .build(new File(dbSourceFileLocation)));
    dataSet.addReplacementObject("[NULL]", null);
    Date now = new Date();
    dataSet.addReplacementObject("[SYSDATE]", Long.valueOf(now.getTime()));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    dataSet.addReplacementObject("[SYSTIMESTAMP]", sdf.format(now));

    DatabaseOperation.INSERT.execute(dbConn, dataSet);
}
 
开发者ID:servicecatalog,项目名称:development,代码行数:29,代码来源:DatabaseTaskHandler.java

示例2: recursive

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
/**
 * Méthode recursive.
 * @param file
 * @param hasParameters
 * @param operation
 * @throws SaladiumException
 */
private void recursive(File file, DatabaseOperation operation) throws SaladiumException {
    if (file.isDirectory()) {
        if (!".svn".equals(file.getName())) {
            for (File childFile : file.listFiles()) {
                recursive(childFile, operation);
            }
        }
    } else {
        if ("xml".equals(FilenameUtils.getExtension(file.getAbsolutePath()))) {
            dataOperation(file, operation);
        } else {
            LOGGER.info(file.getAbsolutePath() + " n'est pas un fichier valide et ne devrait pas se trouver à cet emplacement");
        }
    }
}
 
开发者ID:Nonorc,项目名称:saladium,代码行数:23,代码来源:AbstractWorker.java

示例3: initEntityManager

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
/**
 * Set up memory database and insert data from test-dataset.xml
 * 
 * @throws DatabaseUnitException
 * @throws HibernateException
 * @throws SQLException
 */
@BeforeClass
public static void initEntityManager() throws HibernateException, DatabaseUnitException, SQLException {
    entityManagerFactory = Persistence.createEntityManagerFactory("listing-test-db");
    entityManager = entityManagerFactory.createEntityManager();
    connection = new DatabaseConnection(((SessionImpl) (entityManager.getDelegate())).connection());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetXml);
    if (inputStream != null) {
        FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
        flatXmlDataSetBuilder.setColumnSensing(true);
        dataset = flatXmlDataSetBuilder.build(inputStream);
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
    }
}
 
开发者ID:coodoo-io,项目名称:coodoo-listing,代码行数:23,代码来源:AbstractDbUnitTest.java

示例4: customSetup

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@Before
public void customSetup() throws Exception {
    super.getDatabaseTester().setSchema("linkbinder_test");

    // マスタデータ
    File resource = new File(getPjUserResourceName());
    if (resource.exists()) {
        IDataSet ds = new XlsDataSet(new FileInputStream(resource));
        IDatabaseConnection connection = getConnection();
        try {
            DatabaseOperation.REFRESH.execute(connection, ds);
        } finally {
            closeConnection(connection);
        }
    }

    super.setUp();

}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:20,代码来源:AbstractDaoTestCase.java

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

示例6: beforeTestMethod

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    DataSetLocation dsLocation = testContext.getTestInstance().getClass().getAnnotation(DataSetLocation.class);
    if (dsLocation != null) {
        String dataSetResourcePath = dsLocation.value();
        Resource dataSetResource = testContext.getApplicationContext().getResource(dataSetResourcePath);

        if (dataSetResource.exists()) {
            IDataSet dataSet = new FlatXmlDataSetBuilder().build(dataSetResource.getInputStream());
            IDatabaseConnection dbConn = new DatabaseDataSourceConnection(
                    testContext.getApplicationContext().getBean(DataSource.class)
            );
            DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);

            LOG.info("Annotated test, using data set: {}", dataSetResourcePath);
        }
    }
}
 
开发者ID:DmitriyLy,项目名称:travel_portal,代码行数:19,代码来源:CleanInsertTestExecutionListener.java

示例7: insertDbUnitTestdata

import org.dbunit.operation.DatabaseOperation; //导入依赖的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

示例8: cleanDB

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
/**
 * Will clean the dataBase before each test
 * 
 * @throws SQLException
 * @throws DatabaseUnitException
 */
@Before
public void cleanDB() throws DatabaseUnitException, SQLException {
	// DatabaseOperation.TRUNCATE_TABLE.execute(connection, dataset);
	DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
	// try {
	// EntityManagerHelper.beginTransaction();
	// } catch (RuntimeException e) {
	// e.printStackTrace();
	// if (EntityManagerHelper.getEntityManager() != null &&
	// EntityManagerHelper.getEntityManager().isOpen()) {
	// EntityManagerHelper.rollback();
	// }
	// EntityManagerHelper.closeEntityManager();
	// throw e;
	// }
}
 
开发者ID:infinitiessoft,项目名称:keystone4j,代码行数:23,代码来源:AbstractIntegratedTest.java

示例9: cleanDB

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
/**
 * Will clean the dataBase before each test
 * 
 * @throws SQLException
 * @throws DatabaseUnitException
 */
@Before
public void cleanDB() throws DatabaseUnitException, SQLException {
	// DatabaseOperation.TRUNCATE_TABLE.execute(connection, dataset);
	DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
	try {
		EntityManagerHelper.beginTransaction();
	} catch (RuntimeException e) {
		e.printStackTrace();
		if (EntityManagerHelper.getEntityManager() != null && EntityManagerHelper.getEntityManager().isOpen()) {
			EntityManagerHelper.rollback();
		}
		EntityManagerHelper.closeEntityManager();
		throw e;
	}
}
 
开发者ID:infinitiessoft,项目名称:keystone4j,代码行数:22,代码来源:AbstractDbUnitJpaTest.java

示例10: cleanInsertIntoDatabase

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
/**
 * This composite operation performs a  deleteAllFromDatabase operation
 * followed by an insertIntoDatabase operation. This is the safest approach
 * to ensure that the database is in a known state. This is appropriate for
 * tests that require the database to only contain a specific set of data.
 *
 * @param dataSet
 * @throws Exception
 */
protected void cleanInsertIntoDatabase( IDataSet dataSet )
        throws Exception
{
    IDatabaseConnection connection = null;

    try
    {
        connection = getConnection();
        DatabaseOperation.CLEAN_INSERT.execute( connection, dataSet );
    }
    finally
    {
        closeConnection( connection );
    }
}
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:25,代码来源:AbstractDBUnitHibernateMemoryTest.java

示例11: testFindByArgs

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@Test
public void testFindByArgs() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.setOrder("desc");
    SystemContext.setSort("id");
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Pager<User> expected = userDao.find("from User where id>=? and id<=?", new Object[] { 1, 10 });
    List<User> actuals = Arrays.asList(new User(10, "admin10"), new User(9, "admin9"), new User(8, "admin8"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 10);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
开发者ID:SoftwareKing,项目名称:SpringCloud,代码行数:17,代码来源:TestUserDao.java

示例12: testFindByArgsAndAlias

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@Test
public void testFindByArgsAndAlias() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.removeOrder();
    SystemContext.removeSort();
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Map<String, Object> alias = new HashMap<String, Object>();
    alias.put("ids", Arrays.asList(1, 2, 4, 5, 6, 7, 8, 10));
    Pager<User> expected = userDao.find("from User where id>=? and id<=? and id in (:ids)", new Object[] { 1, 10 },
            alias);
    List<User> actuals = Arrays.asList(new User(1, "admin1"), new User(2, "admin2"), new User(4, "admin4"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 8);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
开发者ID:SoftwareKing,项目名称:SpringCloud,代码行数:20,代码来源:TestUserDao.java

示例13: testFindSQLByArgs

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@Test
public void testFindSQLByArgs() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.setOrder("desc");
    SystemContext.setSort("id");
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Pager<User> expected = userDao.findUserBySql("select * from t_user where id>=? and id<=?",
            new Object[] { 1, 10 }, User.class, true);
    List<User> actuals = Arrays.asList(new User(10, "admin10"), new User(9, "admin9"), new User(8, "admin8"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 10);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
开发者ID:SoftwareKing,项目名称:SpringCloud,代码行数:18,代码来源:TestUserDao.java

示例14: testFindSQLByArgsAndAlias

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@Test
public void testFindSQLByArgsAndAlias() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.removeOrder();
    SystemContext.removeSort();
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Map<String, Object> alias = new HashMap<String, Object>();
    alias.put("ids", Arrays.asList(1, 2, 4, 5, 6, 7, 8, 10));
    Pager<User> expected = userDao.findUserBySql("select * from t_user where id>=? and id<=? and id in (:ids)",
            new Object[] { 1, 10 }, alias, User.class, true);
    List<User> actuals = Arrays.asList(new User(1, "admin1"), new User(2, "admin2"), new User(4, "admin4"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 8);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
开发者ID:SoftwareKing,项目名称:SpringCloud,代码行数:20,代码来源:TestUserDao.java

示例15: setupDB

import org.dbunit.operation.DatabaseOperation; //导入依赖的package包/类
@BeforeClass
public static void setupDB() throws Exception {
  ds = UnitTestDSProvider.getDataSource();
  //clean any existing records and load some records into the database.
  FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
  builder.setColumnSensing(true);
  Connection setup = ds.getConnection();
  IDatabaseConnection con = new DatabaseConnection(setup);
  {
    InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/app-data-1.xml");
    IDataSet dataSet = builder.build(xmlInput);
    DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
  }
  // load test encryptor class
  Class.forName(EncryptorForTest.class.getName());
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:17,代码来源:AppTest.java


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