Package org.dbunit.database

Examples of org.dbunit.database.IDatabaseConnection


  }

  @Override
  public IDatabaseConnection create() {
    try {
      IDatabaseConnection dbUnitConn = new DatabaseConnection(getConnection());
      dbUnitConn.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());
      return dbUnitConn;
    } catch (DatabaseUnitException e) {
      throw new IllegalStateException(
          "It's not possible to create a PostgreSql DbUnit connection: "
              + e.getMessage(), e);
View Full Code Here


      executeOperations(afterTestOperations);
   }

   private void executeOperations(List<DataSetOperation> list)
   {
      IDatabaseConnection con = null;
      try
      {
         con = getConnection();
         disableReferentialIntegrity(con);
         for (DataSetOperation op : list)
         {
            op.execute(con);
         }
         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(datasourceJndiName));

         // 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

    JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
    jdbcTemplate.execute("create table records (id smallint, " +
        "name varchar(100), address varchar(100), city varchar(100), country varchar(100), " +
        "age smallint)");
    Connection con = DataSourceUtils.getConnection(ds);
    IDatabaseConnection dbUnitCon = null;
    try {
      dbUnitCon = new DatabaseConnection(con);
    } catch (DatabaseUnitException e) {
      System.out.println(e);
    }
    dbUnitCon.getConfig().setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, Boolean.TRUE);
    dbUnitCon.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
    IDataSet dataSet = null;
    try {
      dataSet = new XmlDataSet(new FileInputStream("data/load.xml"));
    } catch (IOException e) {
      System.out.println(e);
View Full Code Here

    jdbcTemplate.execute("create table records (id smallint, " +
        "name varchar(100), address varchar(100), city varchar(100), country varchar(100), " +
        "age smallint)");
    // Test data
    Connection con = DataSourceUtils.getConnection(ds);
    IDatabaseConnection dbUnitCon = null;
    try {
      dbUnitCon = new DatabaseConnection(con);
    } catch (DatabaseUnitException e) {
      System.out.println(e);
    }
    dbUnitCon.getConfig().setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, Boolean.TRUE);
    dbUnitCon.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());
    IDataSet dataSet = null;
    try {
      dataSet = new XmlDataSet(new FileInputStream("data/load.xml"));
    } catch (IOException e) {
      System.out.println(e);
View Full Code Here

        super.beforeTestMethod(testContext);

        DataSource dataSource = getDataSource(testContext);
        Connection conn = DataSourceUtils.getConnection(dataSource);
        IDatabaseConnection dbUnitConn = getDBUnitConnection(conn);
        try {
            IDataSet dataSets[] = getDataSets(testContext);
            for (IDataSet dataSet : dataSets) {
                DatabaseOperation.CLEAN_INSERT.execute(dbUnitConn, dataSet);
                logger.debug("Performed CLEAN_INSERT of IDataSet.");
View Full Code Here

    }

    private IDatabaseConnection getDBUnitConnection(Connection c)
            throws DatabaseUnitException
            {
        IDatabaseConnection conn = new DatabaseConnection(c);
        DatabaseConfig config = conn.getConfig();
        config.setFeature("http://www.dbunit.org/features/qualifiedTableNames",
                true);
        config.setProperty("http://www.dbunit.org/properties/tableType",
                TABLE_TYPES);
        return conn;
View Full Code Here

            FileNotFoundException, IOException {
        File datasetFile = new File(dataSetXML);
        if (datasetFile.exists()) {
            DataSource ds = jdbcTemplate.getDataSource();
            Connection con = DataSourceUtils.getConnection(ds);
            IDatabaseConnection dbUnitCon = new DatabaseConnection(con);
            DatabaseConfig config = dbUnitCon.getConfig();
            config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
            IDataSet dataSet = new FlatXmlDataSetBuilder().build(datasetFile);
            databaseOperation.execute(dbUnitCon, dataSet);
            DataSourceUtils.releaseConnection(con, ds);
        } else {
View Full Code Here

        this.datasource = datasource;
       

        // prepare the database
        IDatabaseConnection connection = new DatabaseConnection(datasource.getConnection());
        IDataSet dataSet = new XmlDataSet(new FileInputStream("conf/dataset.xml"));

        try
        {
            DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
        }
        finally
        {
            connection.close();
        }
    }
View Full Code Here

      Properties props = new Properties();
      props.load(in);
      System.out.print("properties loaded...");

      Connection jdbcConnection = DriverManager.getConnection(props.getProperty("db.url"), props.getProperty("db.username"), props.getProperty("db.password"));
      IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
      DatabaseConfig config = connection.getConfig();
      config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
      System.out.print("mysql connection set...");

      dataSet = new QueryDataSet(connection);
      for (String table : tables) {
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.