Java Code Examples for org.dbunit.database.IDatabaseConnection

The following examples show how to use org.dbunit.database.IDatabaseConnection. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected IDatabaseConnection getConnection() throws Exception {
    Properties cfg = getHibernateConfiguration();
    String username = cfg.getProperty("hibernate.connection.username");
    String password = cfg.getProperty("hibernate.connection.password");
    String driver = cfg.getProperty("hibernate.connection.driver_class");
    String url = cfg.getProperty("hibernate.connection.url");

    Class.forName(driver);

    Connection jdbcConnection = DriverManager.getConnection(url, username, password);

    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
    DatabaseConfig config = connection.getConfig();
    // config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new
    // H2DataTypeFactory());
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    return connection;
}
 
Example 2
Source Project: kylin-on-parquet-v2   Source File: ITKylinQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionQuery() throws Exception {
    String expectVersion = KylinVersion.getCurrentVersion().toString();
    logger.info("---------- verify expect version: " + expectVersion);

    String queryName = "QueryKylinVersion";
    String sql = "SELECT VERSION() AS version";

    // execute Kylin
    logger.info("Query Result from Kylin - " + queryName);
    IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
    ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);
    String queriedVersion = String.valueOf(kylinTable.getValue(0, "version"));

    // compare the result
    Assert.assertEquals(expectVersion, queriedVersion);
}
 
Example 3
Source Project: proarc   Source File: DbUnitSupport.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Reader getDtdSchema(boolean resetDtdSchema) throws Exception {
        if (resetDtdSchema || dtdSchema == null) {
            Connection c = getEmireCfg().getConnection();
            try {

                IDatabaseConnection dc = createProgresConnection(c);
                StringWriter sw = new StringWriter();
                FlatDtdDataSet.write(dc.createDataSet(), sw);
                dtdSchema = sw.toString();
//                System.out.println(dtdSchema);
            } finally {
                c.close();
            }
        }
        return new StringReader(dtdSchema);
    }
 
Example 4
Source Project: kylin-on-parquet-v2   Source File: KylinTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void verifyResultContent(String queryFolder) throws Exception {
    logger.info("---------- verify result content in folder: " + queryFolder);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        String sql = getTextFromFile(sqlFile);

        File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected.xml");
        IDataSet expect = new FlatXmlDataSetBuilder().build(expectResultFile);
        // Get expected table named "expect". FIXME Only support default table name
        ITable expectTable = expect.getTable("expect");

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);

        // compare the result
        assertTableEquals(expectTable, kylinTable);
    }
}
 
Example 5
Source Project: kylin-on-parquet-v2   Source File: KylinTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected void execAndCompColumnCount(String input, int expectedColumnCount) throws Exception {
    logger.info("---------- test column count: " + input);
    Set<String> sqlSet = ImmutableSet.of(input);

    for (String sql : sqlSet) {
        // execute Kylin
        logger.info("Query Result from Kylin - " + sql);
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, sql, sql, false);

        try {
            // compare the result
            Assert.assertEquals(expectedColumnCount, kylinTable.getTableMetaData().getColumns().length);
        } catch (Throwable t) {
            logger.info("execAndCompColumnCount failed on: " + sql);
            throw t;
        }
    }
}
 
Example 6
Source Project: kylin   Source File: ITMassInQueryTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void run(String queryFolder, String[] exclusiveQuerys, boolean needSort) throws Exception {
    logger.info("---------- test folder: " + queryFolder);
    Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        if (exclusiveSet.contains(queryName)) {
            continue;
        }
        String sql = getTextFromFile(sqlFile);

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, needSort);
        printResult(kylinTable);

    }
}
 
Example 7
Source Project: jpa-unit   Source File: CleanupStrategyProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedTablesOnlyStrategy() {
    return (final IDatabaseConnection connection, final List<IDataSet> initialDataSets, final String... tablesToExclude) -> {
        if (initialDataSets.isEmpty()) {
            return;
        }

        try {
            IDataSet dataSet = excludeTables(mergeDataSets(initialDataSets), tablesToExclude);
            dataSet = new FilteredDataSet(new DatabaseSequenceFilter(connection), dataSet);
            DatabaseOperation.DELETE_ALL.execute(connection, dataSet);
        } catch (final SQLException | DatabaseUnitException e) {
            throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e);
        }
    };
}
 
Example 8
Source Project: jpa-unit   Source File: PostgresqlConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), not(equalTo(DefaultDataTypeFactory.class)));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 9
Source Project: jpa-unit   Source File: H2ConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(H2DataTypeFactory.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 10
Source Project: jpa-unit   Source File: Db2ConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws Exception {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(Db2DataTypeFactory.class));

    final Object metadataHandler = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER);
    assertThat(metadataHandler, notNullValue());
    assertThat(metadataHandler.getClass(), equalTo(Db2MetadataHandler.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 11
Source Project: jpa-unit   Source File: McKoiConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(MckoiDataTypeFactory.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 12
Source Project: jpa-unit   Source File: MsSqlConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(MsSqlDataTypeFactory.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 13
/**
 * Return a data set for export. A sort filter is used for the foreign key.
 *
 * @param tables
 *            which table should be exported.
 * @param con
 *            is used for the export
 *
 * @return the export data set
 *
 * @throws DataSetException
 * @throws SQLException
 * @throws AmbiguousTableNameException
 */
private IDataSet getDataSetToExport(final String[] tables,
		final IDatabaseConnection con) throws DataSetException,
		SQLException, AmbiguousTableNameException {
	final ITableFilter filter = new DatabaseSequenceFilter(con);
	IDataSet dataSetToExport = null;
	if (tables == null || tables.length == 0) {
		// want a complete database export
		dataSetToExport = con.createDataSet();
		dataSetToExport = new FilteredDataSet(filter, dataSetToExport);
	} else {
		final QueryDataSet qDataSet = new QueryDataSet(con);
		// generate the data set
		if (tables.length % 2 != 0) {
			throw new IllegalArgumentException(
					"Contract {<Table Name>,<SELECT_QUERY>} is brocken.");
		}
		for (int i = 0; i < tables.length; i += 2) {
			final String table = tables[i].toUpperCase();
			String query = tables[i + 1];
			if (query == null || query.trim().length() == 0) {
				query = "SELECT * FROM " + table;
			}

			qDataSet.addTable(table, query);
		}

		dataSetToExport = qDataSet;
	}
	return dataSetToExport;
}
 
Example 14
/**
 * This composite operation performs a deleteAllFromDatabase operation
 * followed by an insertIntoDatabase operation. This is the safest approach
 * to ensure that the database is in a known state. This is appropriate for
 * tests that require the database to only contain a specific set of data.
 *
 * @param dataSet
 * @throws Exception
 */
protected void cleanInsertIntoDatabase(IDataSet dataSet) throws Exception {
    IDatabaseConnection connection = null;

    try {
        connection = getConnection();
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
    } finally {
        closeConnection(connection);
    }
}
 
Example 15
Source Project: kylin-on-parquet-v2   Source File: ITMassInQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void compare(String queryFolder, String[] exclusiveQuerys, boolean needSort) throws Exception {
    logger.info("---------- test folder: " + queryFolder);
    Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        if (exclusiveSet.contains(queryName)) {
            continue;
        }
        String sql = getTextFromFile(sqlFile);

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, needSort);

        // execute H2
        sql = sql.replace("massin(test_kylin_fact.SELLER_ID,'vip_customers')", "test_kylin_fact.SELLER_ID in ( " + org.apache.commons.lang.StringUtils.join(vipSellers, ",") + ")");
        logger.info("Query Result from H2 - " + queryName);
        logger.info("Query for H2 - " + sql);
        ITable h2Table = executeQuery(newH2Connection(), queryName, sql, needSort);

        try {
            // compare the result
            assertTableEquals(h2Table, kylinTable);
        } catch (Throwable t) {
            logger.info("execAndCompQuery failed on: " + sqlFile.getAbsolutePath());
            throw t;
        }
    }
}
 
Example 16
Source Project: kylin-on-parquet-v2   Source File: KylinTestBase.java    License: Apache License 2.0 5 votes vote down vote up
protected void verifyResultRowColCount(String queryFolder) throws Exception {
    logger.info("---------- verify result count in folder: " + queryFolder);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        String sql = getTextFromFile(sqlFile);

        File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected");
        Pair<Integer, Integer> pair = getExpectedRowAndCol(expectResultFile);
        int expectRowCount = pair.getFirst();
        int expectColCount = pair.getSecond();

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);

        // compare the result
        if (BackdoorToggles.getPrepareOnly())
            Assert.assertEquals(queryName, 0, kylinTable.getRowCount());
        else if (expectRowCount >= 0)
            Assert.assertEquals(queryName, expectRowCount, kylinTable.getRowCount());

        if (expectColCount >= 0)
            Assert.assertEquals(queryName, expectColCount, kylinTable.getTableMetaData().getColumns().length);
    }
}
 
Example 17
Source Project: kylin-on-parquet-v2   Source File: KylinTestBase.java    License: Apache License 2.0 5 votes vote down vote up
protected void execAndCompResultSize(String queryFolder, String[] exclusiveQuerys, boolean needSort)
        throws Exception {
    logger.info("---------- test folder: " + queryFolder);
    Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        if (exclusiveSet.contains(queryName)) {
            continue;
        }
        String sql = getTextFromFile(sqlFile);

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, needSort);

        // execute H2
        logger.info("Query Result from H2 - " + queryName);
        ITable h2Table = executeQuery(newH2Connection(), queryName, sql, needSort);

        try {
            // compare the result
            Assert.assertEquals(h2Table.getRowCount(), kylinTable.getRowCount());
        } catch (Throwable t) {
            logger.info("execAndCompResultSize failed on: " + sqlFile.getAbsolutePath());
            throw t;
        }

        compQueryCount++;
        if (kylinTable.getRowCount() == 0) {
            zeroResultQueries.add(sql);
        }
    }
}
 
Example 18
Source Project: kylin-on-parquet-v2   Source File: KylinTestBase.java    License: Apache License 2.0 5 votes vote down vote up
protected void execLimitAndValidate(String queryFolder) throws Exception {
    logger.info("---------- test folder: " + new File(queryFolder).getAbsolutePath());

    int appendLimitQueries = 0;
    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        String sql = getTextFromFile(sqlFile);

        String sqlWithLimit;
        if (sql.toLowerCase(Locale.ROOT).contains("limit ")) {
            sqlWithLimit = sql;
        } else {
            sqlWithLimit = sql + " limit 5";
            appendLimitQueries++;
        }

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sqlWithLimit, false);

        // execute H2
        logger.info("Query Result from H2 - " + queryName);
        ITable h2Table = executeQuery(newH2Connection(), queryName, sql, false);

        try {
            assertTableContains(h2Table, kylinTable);
        } catch (Throwable t) {
            logger.info("execAndCompQuery failed on: " + sqlFile.getAbsolutePath());
            throw t;
        }

        compQueryCount++;
        if (kylinTable.getRowCount() == 0) {
            zeroResultQueries.add(sql);
        }
    }
    logger.info("Queries appended with limit: " + appendLimitQueries);
}
 
Example 19
Source Project: kylin-on-parquet-v2   Source File: KylinTestBase.java    License: Apache License 2.0 5 votes vote down vote up
protected void execAndCompDynamicQuery(String queryFolder, String[] exclusiveQuerys, boolean needSort)
        throws Exception {
    logger.info("---------- test folder: " + queryFolder);
    Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        if (exclusiveSet.contains(queryName)) {
            continue;
        }
        String sql = getTextFromFile(sqlFile);
        List<String> parameters = getParameterFromFile(sqlFile);

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeDynamicQuery(kylinConn, queryName, sql, parameters, needSort);

        // execute H2
        logger.info("Query Result from H2 - " + queryName);
        ITable h2Table = executeDynamicQuery(newH2Connection(), queryName, sql, parameters, needSort);

        // compare the result
        assertTableEquals(h2Table, kylinTable);
    }
}
 
Example 20
Source Project: JavaSpringMvcBlog   Source File: HsqldbSequenceResetter.java    License: MIT License 5 votes vote down vote up
@Override
public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException {
    String[] tables = dataSet.getTableNames();
    Statement statement = connection.getConnection().createStatement();
    for (String table : tables) {
        statement.execute("TRUNCATE TABLE " + table + " RESTART IDENTITY AND COMMIT NO CHECK");

    }
}
 
Example 21
Source Project: jpa-unit   Source File: SqlDbFeatureExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected DbFeature<IDatabaseConnection> createCleanupFeature(final CleanupStrategy cleanupStrategy,
        final List<IDataSet> initialDataSets) {
    return (final IDatabaseConnection connection) -> {
        final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> executor = cleanupStrategy
                .provide(providerFactory.createCleanupStrategyProvider());
        executor.execute(connection, initialDataSets);
    };
}
 
Example 22
Source Project: jpa-unit   Source File: SqlDbFeatureExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected DbFeature<IDatabaseConnection> createSeedDataFeature(final DataSeedStrategy dataSeedStrategy,
        final List<IDataSet> initialDataSets) {
    return (final IDatabaseConnection connection) -> {
        try {
            final DatabaseOperation operation = dataSeedStrategy.provide(providerFactory.createDataSeedStrategyProvider());
            operation.execute(connection, mergeDataSets(initialDataSets));
        } catch (DatabaseUnitException | SQLException e) {
            throw new DbFeatureException("Could not execute DB seed feature", e);
        }
    };
}
 
Example 23
public IDatabaseConnection getConnection() throws Exception {
            IDatabaseConnection connection = super.getConnection();
            DatabaseConfig config = connection.getConfig();
            config.setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, false);
//            config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
            return connection;
        }
 
Example 24
Source Project: jpa-unit   Source File: DbUnitTestMethodDecorator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void beforeTest(final TestInvocation invocation) throws Exception {
    final ExecutionContext context = invocation.getContext();

    final SqlDbFeatureExecutor dbFeatureExecutor = new SqlDbFeatureExecutor(invocation.getFeatureResolver());
    final IDatabaseConnection connection = (IDatabaseConnection) context.getData(Constants.KEY_CONNECTION);

    dbFeatureExecutor.executeBeforeTest(connection);
    context.storeData(Constants.KEY_FEATURE_EXECUTOR, dbFeatureExecutor);
}
 
Example 25
Source Project: jpa-unit   Source File: DbUnitTestMethodDecorator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void afterTest(final TestInvocation invocation) throws Exception {
    final ExecutionContext context = invocation.getContext();

    final SqlDbFeatureExecutor dbFeatureExecutor = (SqlDbFeatureExecutor) context.getData(Constants.KEY_FEATURE_EXECUTOR);
    context.storeData(Constants.KEY_FEATURE_EXECUTOR, null);

    final IDatabaseConnection connection = (IDatabaseConnection) context.getData(Constants.KEY_CONNECTION);

    dbFeatureExecutor.executeAfterTest(connection, invocation.getException().isPresent());
}
 
Example 26
@Override
public void beforeAll(final TestInvocation invocation) throws Exception {
    final ExecutionContext context = invocation.getContext();
    final BasicDataSource ds = (BasicDataSource) context.getData(Constants.KEY_DATA_SOURCE);

    final IDatabaseConnection connection = DatabaseConnectionFactory.openConnection(ds);
    connection.getConfig().setPropertiesByString(
            DbUnitConfigurationLoader.loadConfiguration(ResourceLocator.getResource("dbunit.properties")));
    context.storeData(Constants.KEY_CONNECTION, connection);
}
 
Example 27
@Override
public void afterAll(final TestInvocation invocation) throws Exception {
    final ExecutionContext context = invocation.getContext();
    final IDatabaseConnection connection = (IDatabaseConnection) context.getData(Constants.KEY_CONNECTION);
    context.storeData(Constants.KEY_CONNECTION, null);

    connection.close();
}
 
Example 28
Source Project: Kylin   Source File: KylinQueryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleExecuteQuery() throws Exception {

    String queryFileName = "src/test/resources/query/sql/query39.sql";

    File sqlFile = new File(queryFileName);
    String sql = getTextFromFile(sqlFile);
    IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);

    executeQuery(kylinConn, queryFileName, sql, true);
}
 
Example 29
Source Project: jpa-unit   Source File: CleanupStrategyProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strictStrategy() {
    return (final IDatabaseConnection connection, final List<IDataSet> initialDataSets, final String... tablesToExclude) -> {
        try {
            IDataSet dataSet = excludeTables(connection.createDataSet(), tablesToExclude);
            dataSet = new FilteredDataSet(new DatabaseSequenceFilter(connection), dataSet);
            DatabaseOperation.DELETE_ALL.execute(connection, dataSet);
        } catch (final SQLException | DatabaseUnitException e) {
            throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e);
        }
    };
}
 
Example 30
Source Project: jpa-unit   Source File: CleanupStrategyProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedRowsOnlyStrategy() {
    return (final IDatabaseConnection connection, final List<IDataSet> initialDataSets, final String... tablesToExclude) -> {
        if (initialDataSets.isEmpty()) {
            return;
        }

        try {
            final IDataSet dataSet = excludeTables(mergeDataSets(initialDataSets), tablesToExclude);
            DatabaseOperation.DELETE.execute(connection, dataSet);
        } catch (final SQLException | DatabaseUnitException e) {
            throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e);
        }
    };
}