Package org.dbunit.database

Examples of org.dbunit.database.IDatabaseConnection


        if(operationListener == null){
            logger.debug("OperationListener is null and will be defaulted.");
            operationListener = new DefaultOperationListener();
        }
       
      IDatabaseConnection connection = getConnection();
        operationListener.connectionRetrieved(connection);

      try{
        operation.execute( connection, getDataSet() );
      }
View Full Code Here


        if (databaseTester == null) {
            throw new IllegalStateException(
            "databaseTester is null; must configure or set it first");
        }

        IDatabaseConnection connection = databaseTester.getConnection();

        try {
            int count = tableDefs.length;
            LOG.info("verifyData: about to verify {} tables={}", new Integer(
                    count), tableDefs);
            if (count == 0) {
                LOG.warn("No tables to verify;"
                        + " no VerifyTableDefinitions specified");
            }

            for (int i = 0; i < count; i++) {
                VerifyTableDefinition td = tableDefs[i];
                String[] excludeColumns = td.getColumnExclusionFilters();
                String[] includeColumns = td.getColumnInclusionFilters();
                String tableName = td.getTableName();

                LOG.info("Verifying table '{}'", tableName);

                LOG.debug("  Loading its rows from expected dataset");
                ITable expectedTable = null;
                try {
                    expectedTable = expectedDs.getTable(tableName);
                } catch (DataSetException e) {
                    final String msg =
                        "Problem obtaining table '" + tableName
                        + "' from expected dataset";
                    LOG.error(msg, e);
                    throw new DataSetException(msg, e);
                }

                LOG.debug("  Loading its rows from actual table");
                ITable actualTable = null;
                try {
                    actualTable = connection.createTable(tableName);
                } catch (DataSetException e) {
                    final String msg =
                        "Problem obtaining table '" + tableName
                        + "' from actual dataset";
                    LOG.error(msg, e);
                    throw new DataSetException(msg, e);
                }

                verifyData(expectedTable, actualTable, excludeColumns,
                        includeColumns);
            }
        } finally {
            LOG.debug("verifyData: Verification done, closing connection");
            connection.close();
        }
    }
View Full Code Here

     * @throws Exception
     */
    protected IDatabaseTester newDatabaseTester() throws Exception{
        logger.debug("newDatabaseTester() - start");

      final IDatabaseConnection connection = getConnection();
      getOperationListener().connectionRetrieved(connection);
      final IDatabaseTester tester = new DefaultDatabaseTester(connection);
      return tester;
    }
View Full Code Here

  protected final IDatabaseConnection getConnection() throws Exception {
        logger.debug("getConnection() - start");

    final IDatabaseTester databaseTester = getDatabaseTester();
    assertNotNull( "DatabaseTester is not set", databaseTester );
    IDatabaseConnection connection = databaseTester.getConnection();
    // Ensure that users have the possibility to configure the connection's configuration
    setUpDatabaseConfig(connection.getConfig());
    return connection;
}
View Full Code Here

   *
   * @param xmlFilePaths 符合Spring Resource路径格式的文件列表.
   */
  private static void execute(DatabaseOperation operation, DataSource h2DataSource, String... xmlFilePaths)
      throws DatabaseUnitException, SQLException {
    IDatabaseConnection connection = new H2Connection(h2DataSource.getConnection(), "");
    for (String xmlPath : xmlFilePaths) {
      try {
        InputStream input = resourceLoader.getResource(xmlPath).getInputStream();
        IDataSet dataSet = new FlatXmlDataSetBuilder().setColumnSensing(true).build(input);
        operation.execute(connection, dataSet);
View Full Code Here

    public void execute(IDatabaseConnection connection, IDataSet dataSet)
            throws DatabaseUnitException, SQLException
    {
        logger.debug("execute(connection={}, dataSet={}) - start", connection, dataSet);

        IDatabaseConnection databaseConnection = connection;
        Connection jdbcConnection = databaseConnection.getConnection();

        if (jdbcConnection.getAutoCommit() == false)
        {
            throw new ExclusiveTransactionException();
        }
View Full Code Here

    {
        logger.trace("execute() - start");

        try
        {
            IDatabaseConnection connection = createConnection();

            Iterator stepIter = steps.listIterator();
            while (stepIter.hasNext())
            {
                DbUnitTaskStep step = (DbUnitTaskStep)stepIter.next();
View Full Code Here

            // Driver doesn't understand the URL
            throw new SQLException("No suitable Driver for " + url);
        }
        conn.setAutoCommit(true);

        IDatabaseConnection connection = createDatabaseConnection(conn, schema);
        return connection;
    }
View Full Code Here

    protected IDatabaseConnection createDatabaseConnection(Connection jdbcConnection,
            String dbSchema)
    {
        logger.trace("createDatabaseConnection(jdbcConnection={}, dbSchema={}) - start", jdbcConnection, dbSchema);

        IDatabaseConnection connection = null;
        try
        {
            connection = new DatabaseConnection(jdbcConnection, dbSchema);
        }
        catch(DatabaseUnitException e)
        {
            throw new BuildException("Could not create dbunit connection object", e);
        }
        DatabaseConfig config = connection.getConfig();
       
        // Override the default resultset table factory
        config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory());

        if(this.dbConfig != null){
View Full Code Here

        Connection conn = DataSourceUtils.getConnection(dataSource);
        // CHECKSTYLE:OFF
        System.out.println("Writing DTD...");
        // CHECKSTYLE:ON
        try {
            IDatabaseConnection connection = new DatabaseConnection(conn);
            FlatDtdDataSet.write(connection.createDataSet(), new FileOutputStream(DTD_FILENAME));
        } catch (DataSetException e) {
            throw new RuntimeException(e);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.dbunit.database.IDatabaseConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.