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


Java IDatabaseConnection類代碼示例

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


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

示例1: main

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

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public void execute(final IDatabaseConnection connection, final List<String> qualifiedTableNames) throws SQLException {
    final IStatementFactory statementFactory = (IStatementFactory) connection.getConfig().getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
    final IBatchStatement statement = statementFactory.createBatchStatement(connection);
    try {
        int count = 0;

        for (final String tableName : qualifiedTableNames) {
            statement.addBatch("DELETE FROM " + tableName);
            count++;
        }
        if (count > 0) {
            statement.executeBatch();
            statement.clearBatch();
        }
    } finally {
        statement.close();
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:19,代碼來源:TruncateBrpTableOperation.java

示例3: execute

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public void execute(final IDatabaseConnection connection, final List<String> qualifiedTableNames) throws SQLException {
    final IStatementFactory statementFactory = (IStatementFactory) connection.getConfig().getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
    final IBatchStatement statement = statementFactory.createBatchStatement(connection);
    try {
        int count = 0;

        for (final String tableName : qualifiedTableNames) {
            if (!Arrays.asList(TABELLEN_ZONDER_SEQ).contains(tableName)) {
            statement.addBatch(getAlterSequenceCommand(tableName));
            count++;
            }
        }
        if (count > 0) {
            statement.executeBatch();
            statement.clearBatch();
        }
    } finally {
        statement.close();
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:21,代碼來源:RestartBrpSequenceOperation.java

示例4: setSpecificSequence

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
private void setSpecificSequence(final IDatabaseConnection connection, final String tableName) throws SQLException, DatabaseUnitException {
    final List<String> databaseNames = new ArrayList<>();
    databaseNames.add(tableName);
    final PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT id from " + tableName + " order by id desc");
    try (ResultSet rs = preparedStatement.executeQuery()) {
        if (rs.next()) {
            final long maxId = rs.getLong(1);
            final long sequenceId = maxId + 1;
            new RestartBrpSequenceOperation(sequenceId).execute(connection, databaseNames);
        }
    } finally {
        try {
            preparedStatement.close();
        } catch (SQLException s) {
            LOGGER.error("Kon preparedStatement niet sluiten");
        }
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:19,代碼來源:DBUnitBrpUtil.java

示例5: main

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
/**
 * @param args
 *            args
 * @throws Exception
 *             Exception
 */
public static void main(String[] args) throws Exception {

    String prop = "src/test/resources/jdbc.properties";
    if (args.length > 0) {
        prop = args[0];
    }
    Properties p = loadProperties(prop);

    String input = "import.xls";
    if (args.length > 1) {
        input = args[1];
    }

    IDatabaseConnection con = createConnection(p);
    DatabaseConfig config = con.getConfig();
        config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
                           factorySelector.getDataTypeFactory(con));
    TableDataOperator op = new TableDataOperator();
    // op.deleteInsert(con, input);
    op.insertUpdate(con, input);
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:28,代碼來源:DataImporter.java

示例6: customSetup

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

示例7: 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

示例8: openConnection

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public static IDatabaseConnection openConnection(final BasicDataSource ds) {
    try {
        final Connection connection = ds.getConnection();

        for (final DbUnitConnectionFactory impl : SERVICE_LOADER) {
            if (impl.supportsDriver(ds.getDriverClassName())) {
                return impl.createConnection(connection);
            }
        }

        // fall back if no specific implementation is available
        return new DatabaseConnection(connection);
    } catch (final DatabaseUnitException | SQLException e) {
        throw new JpaUnitException(e);
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:DatabaseConnectionFactory.java

示例9: createConnection

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Override
public IDatabaseConnection createConnection(final Connection connection) throws DatabaseUnitException {
    final IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
    dbUnitConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());

    return dbUnitConnection;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:8,代碼來源:PostgresqlConnectionFactory.java

示例10: testVerifyDataAfterFeatureExecution

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Test
public void testVerifyDataAfterFeatureExecution() throws DbFeatureException, SQLException, DataSetException {
    // GIVEN
    final IDataSet currentDs = mock(IDataSet.class);
    when(currentDs.getTableNames()).thenReturn(new String[] {});
    when(connection.createDataSet()).thenReturn(currentDs);
    when(expectedDataSets.strict()).thenReturn(Boolean.FALSE);
    when(expectedDataSets.value()).thenReturn(new String[] {});
    when(expectedDataSets.orderBy()).thenReturn(new String[] {});
    when(expectedDataSets.excludeColumns()).thenReturn(new String[] {});

    // WHEN
    final DbFeature<IDatabaseConnection> feature = featureExecutor.createVerifyDataAfterFeature(expectedDataSets);
    assertThat(feature, notNullValue());
    feature.execute(connection);

    // THEN
    verify(connection).createDataSet();
    verifyNoMoreInteractions(connection);
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:21,代碼來源:SqlDbFeatureExecutorTest.java

示例11: beforeTestMethod

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

示例12: createPreparedBatchStatement

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Override
public IPreparedBatchStatement createPreparedBatchStatement(String sql,
    IDatabaseConnection connection) throws SQLException {
  if (logger.isDebugEnabled()) {
    logger.debug("createPreparedBatchStatement(sql={}, connection={}) - start", sql, connection);
  }

  Integer batchSize =
      (Integer) connection.getConfig().getProperty(DatabaseConfig.PROPERTY_BATCH_SIZE);

  IPreparedBatchStatement statement = null;
  if (supportBatchStatement(connection)) {
    statement = new PreparedBatchDefaultValueStatement(sql, connection.getConnection());
  } else {
    statement = new SimplePreparedDefaultValueStatement(sql, connection.getConnection());
  }
  return new AutomaticPreparedBatchStatement(statement, batchSize.intValue());
}
 
開發者ID:frank780117,項目名稱:dbunit-ext,代碼行數:19,代碼來源:PreparedStatementFactory.java

示例13: cleanInsertIntoDatabase

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

示例14: getConnection

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
protected IDatabaseConnection getConnection() throws Exception
    {
        Configuration cfg = getHibernateConfiguration();
        String username = cfg.getProperty( "hibernate.connection.username" );
        String password = cfg.getProperty( "hibernate.connection.password" );
        String driver = cfg.getProperty( "hibernate.connection.driver_class" );
        String url = cfg.getProperty( "hibernate.connection.url" );

        Class.forName( driver );

        Connection jdbcConnection = DriverManager.getConnection( url, username, password );
        
        IDatabaseConnection connection =  new DatabaseConnection(jdbcConnection);
        DatabaseConfig config = connection.getConfig();
//        config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
        config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
      
        return connection;
    }
 
開發者ID:strator-dev,項目名稱:greenpepper,代碼行數:20,代碼來源:AbstractDBUnitHibernateMemoryTest.java

示例15: getConnection

import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
protected IDatabaseConnection getConnection() throws Exception {
    Properties cfg = getHibernateConfiguration();
    String username = cfg.getProperty("hibernate.connection.username");
    String password = cfg.getProperty("hibernate.connection.password");
    String driver = cfg.getProperty("hibernate.connection.driver_class");
    String url = cfg.getProperty("hibernate.connection.url");

    Class.forName(driver);

    Connection jdbcConnection = DriverManager.getConnection(url, username, password);

    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
    DatabaseConfig config = connection.getConfig();
    // config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new
    // H2DataTypeFactory());
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    return connection;
}
 
開發者ID:testIT-LivingDoc,項目名稱:livingdoc-confluence,代碼行數:20,代碼來源:AbstractDBUnitHibernateMemoryTest.java


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