當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。