Package org.dbunit.database

Examples of org.dbunit.database.IDatabaseConnection


  private BasicDataSource dataSource;
 
  @Override
  protected IDatabaseConnection getConnection() throws Exception {
    IDatabaseConnection dc = new DatabaseConnection(dataSource.getConnection());
    DatabaseConfig config = dc.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
        new MySqlDataTypeFactory());
    return dc;
  }
View Full Code Here


    dataSource.setUsername("gnizr");
    dataSource.setPassword("gnizr");
    dataSource.setUrl("jdbc:mysql://localhost/gnizr_db");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
   
    IDatabaseConnection dc = new DatabaseConnection(dataSource.getConnection());
    DatabaseConfig config = dc.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
        new MySqlDataTypeFactory());

        // full database export
        IDataSet fullDataSet = dc.createDataSet();
        FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));            
    }
View Full Code Here

        for (String dataset : datasets) {
            dataSetOperations.add(new DataSetOperation(dataset));
        }

        IDatabaseConnection con = null;
        try {
            con = getConnection();
            disableReferentialIntegrity(con);
            for (DataSetOperation op : dataSetOperations) {
                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

        try {
            DataSource datasource = ((DataSource)new InitialContext().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

        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

                }
                if (System.getProperty("mysql.password") != null) {
                    password = System.getProperty("mysql.password");
                }
            }
            IDatabaseConnection connection = new DatabaseConnection(DriverManager.getConnection(provider.getUrl(), username, password));
            DatabaseConfig config = connection.getConfig();
            if (provider.getUrl().startsWith("jdbc:h2")) {
                config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
            } else if (provider.getUrl().startsWith("jdbc:hsql")) {
                config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
            } else if (provider.getUrl().startsWith("jdbc:mysql")) {
View Full Code Here

        ds.setPassword(DATABASE_PASSWORD);
        ds.setDefaultAutoCommit(isAutoCommit());

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

        try
        {
            DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
        }
        finally
        {
            if (!isAutoCommit())
            {
                conn.commit();
            }
            connection.close();
        }

        return ds;
    }
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

          .getProperty("hibernate.connection.url");
    }
    Connection jdbcConnection = DriverManager.getConnection(
        databaseURL, "sysdba",
        "masterkey");
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

    // EKSPORT
//     XmlDataSetWriter exportBase = new XmlDataSetWriter(new FileOutputStream(
//     "c:/dataset.xml"), "UTF-8");
//     exportBase.write(connection.createDataSet());
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.