当前位置: 首页>>代码示例>>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;未经允许,请勿转载。