Examples of IDatabaseConnection


Examples of org.dbunit.database.IDatabaseConnection

        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

Examples of org.dbunit.database.IDatabaseConnection

        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

Examples of org.dbunit.database.IDatabaseConnection

   * @param xmlFilePaths 符合Spring Resource路径格式的文件列表.
   */
  private static void execute(DatabaseOperation operation, DataSource dataSource, String... xmlFilePaths)
      throws DatabaseUnitException, SQLException {
    //注意这里HardCode了使用H2的Connetion
    IDatabaseConnection connection = new H2Connection(dataSource.getConnection(), null);

    for (String xmlPath : xmlFilePaths) {
      try {
        InputStream input = resourceLoader.getResource(xmlPath).getInputStream();
        IDataSet dataSet = new FlatXmlDataSetBuilder().setColumnSensing(true).build(input);
        operation.execute(connection, dataSet);
      } catch (IOException e) {
        logger.warn(xmlPath + " file not found", e);
      }finally{
        connection.close();
      }
    }
  }
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

        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(
                ConfigurationAssert.getTestFile("dataset.xml")));

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

        return ds;
    }
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

    public void initDB() throws Exception {
        Connection connection = null;

        try {
            connection = getConnection();
            IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
            setDbType(dbUnitConnection);
            DatabaseOperation.REFRESH.execute(dbUnitConnection, getDataSet());
        } finally {
            if (connection != null) {
                connection.close();
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

        }

        try {
            connection = getConnection();

            IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
            setDbType(dbUnitConnection);
            DatabaseOperation.DELETE.execute(dbUnitConnection, getDataSet());
        } finally {
            if (connection != null) {
                connection.close();
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

    public void initDB() throws Exception {
        Connection connection = null;

        try {
            connection = getConnection();
            IDatabaseConnection conn = new DatabaseConnection(connection);
            setDbType(conn);
            DatabaseOperation.REFRESH.execute(conn, getDataSet());
        } finally {
            if (connection != null) {
                connection.close();
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

    public void cleanDB() throws Exception {
        Connection connection = null;

        try {
            connection = getConnection();
            IDatabaseConnection conn = new DatabaseConnection(connection);
            setDbType(conn);
            DatabaseOperation.DELETE.execute(conn, getDataSet());
        } finally {
            if (connection != null) {
                connection.close();
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

     * @param config
     * @param consumer
     * @throws Exception
     */
    public static void run(ExportConfiguration config, IDataSetConsumer consumer) throws Exception {
        IDatabaseConnection connection = DbUnitUtil.getConnection(config.getSettings());
        try {
            Map<Entity, String> entityQueries = getEntityQueries(config);

            Map<Class<?>, Set<ColumnValues>> pksToLoad = new HashMap<Class<?>, Set<ColumnValues>>();
            for (Map.Entry<Entity, String> entry : entityQueries.entrySet()) {
                Entity entity = entry.getKey();
                String query = entry.getValue();

                String tableName = MappingTranslator.getTableName(config.getClassForEntity(entity));

                Set<ColumnValues> pks = getPksFromQuery(connection, tableName, query);
                pksToLoad.put(config.getClassForEntity(entity), pks);
            }

            IDataSet data = null;

            if (pksToLoad.isEmpty()) {
                data = connection.createDataSet();
            } else {
                EntityRelationshipFilter filter = new EntityRelationshipFilter(connection, pksToLoad, new ConfigurableDependencyInclusionResolver(config));
                data = new FilteredDataSet(filter, connection.createDataSet());
            }

            ReplacementDataSet nullReplacingData = new ReplacementDataSet(data);
            nullReplacingData.addReplacementObject(null, Settings.NULL_REPLACEMENT);

            DataSetProducerAdapter producer = new DataSetProducerAdapter(nullReplacingData);
            producer.setConsumer(consumer);
            producer.produce();
        } finally {
            connection.close();
        }
    }
View Full Code Here

Examples of org.dbunit.database.IDatabaseConnection

        String dbUrl="-unknown-" ;
        Connection jdbcConnection = null;
        Statement statement = null;
        try {
            InputStreamProvider streamProvider = getInputStreamProvider(state.url(), state.storage(), method);
            IDatabaseConnection connection = new DatabaseDataSourceConnection(new InitialContext(),
                "java:jboss/datasources/RHQDS");
            jdbcConnection = connection.getConnection();
            dbUrl = jdbcConnection.getMetaData().getURL();
            System.out.println("Using database at " + dbUrl);
            System.out.flush();

            setDatabaseType(connection);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.