Package org.dbunit.database

Examples of org.dbunit.database.IDatabaseConnection


        }
    }

    private IDatabaseConnection getConnection() throws Exception {
        Connection con = dataSource.getConnection();
        IDatabaseConnection connection = new DatabaseConnection(con);
        return connection;
    }
View Full Code Here


    final Connection realConn = unwrappedConn != null
        ? unwrappedConn
        : connection;
   
    try {
      IDatabaseConnection conn = new DatabaseConnection(realConn, this.schemaName);
      for (String key : this.configProperties.keySet()) {
        conn.getConfig().setProperty(key, this.configProperties.get(key));
      }
      work.execute(conn);
    } catch (DatabaseUnitException ex) {
      throw new JuDbException("Couldn't execute DbUnitWork", ex);
    }
View Full Code Here

  }

  @Override
  public IDatabaseConnection get() {
    try {
      IDatabaseConnection connection = databaseTester.getConnection();

      vendorConfig.configure(connection);

      return connection;
    } catch (Exception e) {
View Full Code Here

    final Connection realConn = unwrappedConn != null
        ? unwrappedConn
        : connection;
   
    try {
      IDatabaseConnection conn = new DatabaseConnection(realConn, this.schemaName);
      for (String key : this.configProperties.keySet()) {
        conn.getConfig().setProperty(key, this.configProperties.get(key));
      }
      work.execute(conn);
    } catch (DatabaseUnitException ex) {
      throw new JuDbException("Couldn't execute DbUnitWork", ex);
    }
View Full Code Here

    tryToExecute(datasets);
  }

  private void tryToExecute(List<DataSupplier> datasets) {

    IDatabaseConnection conn = connections.get(); // don't get conned

    try {
      disableReferentialIntegrity(conn);

      for (DataSupplier op : datasets) {

        try {

          IDataSet dataSet = op.get();

          DatabaseOperation operacao = op.getOperation();
          DatabaseOperation trx = DatabaseOperation.TRANSACTION(operacao);
          trx.execute(conn, dataSet);

        } catch (Exception e) {

          Throwables.propagateIfInstanceOf(e, DBUnitSetupException.class);
          String msg = String.format("Could not load DBUnit file: %s", op.getFilename());
          throw new DBUnitSetupException(msg, e);

        }
      }

      enableReferentialIntegrity(conn);
    } finally {
      try {
        conn.close();
      } catch (SQLException e) {
        // move along, nothing to see here
      }
    }
View Full Code Here

  }

  @Override
  public IDatabaseConnection get() {
    try {
      IDatabaseConnection connection = databaseTester.getConnection();

      vendorConfig.configure(connection);

      return connection;
    } catch (Exception e) {
View Full Code Here

   }

   private void executeOperations(List<DataSetOperation> list)
   {
      log.debug("Executing DataSetOperations: " + list.size());
      IDatabaseConnection con = null;
      try
      {
         con = getConnection();
         disableReferentialIntegrity(con);
         for (DataSetOperation op : list)
         {
            prepareExecution(con, op);
            op.execute(con);
            afterExecution(con, op);
         }
         enableReferentialIntegrity(con);
      }
      finally
      {
         if (con != null)
         {
            try
            {
               con.close();
            }
            catch (Exception ex)
            {
               ex.printStackTrace(System.err);
            }
View Full Code Here

         DataSource datasource = ((DataSource) getInitialContext().lookup(getDatasourceJndiName()));

         // Get a JDBC connection from JNDI datasource
         Connection con = datasource.getConnection();
         IDatabaseConnection dbUnitCon = new DatabaseConnection(con);
         editConfig(dbUnitCon.getConfig());
         return dbUnitCon;
      }
      catch (Exception ex)
      {
         throw new RuntimeException(ex);
View Full Code Here

    tryToExecute(datasets);
  }

  private void tryToExecute(List<DataSupplier> datasets) {

    IDatabaseConnection conn = connections.get(); // don't get conned

    try {
      disableReferentialIntegrity(conn);

      for (DataSupplier op : datasets) {

        try {

          IDataSet dataSet = op.get();

          DatabaseOperation operacao = op.getOperation();
          DatabaseOperation trx = DatabaseOperation.TRANSACTION(operacao);
          trx.execute(conn, dataSet);

        } catch (Exception e) {

          Throwables.propagateIfInstanceOf(e, DBUnitSetupException.class);
          String msg = String.format("Could not load DBUnit file: %s", op.getFilename());
          throw new DBUnitSetupException(msg, e);

        }
      }

      enableReferentialIntegrity(conn);
    } finally {
      try {
        conn.close();
      } catch (SQLException e) {
        // move along, nothing to see here
      }
    }
View Full Code Here

      return;
    }
    // Load test data using DBUnit
    DataSource ds = jdbcTemplate.getDataSource();
    Connection con = DataSourceUtils.getConnection(ds);
    IDatabaseConnection dbUnitCon = new DatabaseConnection(con);
    IDataSet dataSet = new FlatXmlDataSet(new FileInputStream(fixtureFile));
    try {
      DatabaseOperation.CLEAN_INSERT.execute(dbUnitCon, dataSet);
    }
    finally {
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.