本文整理匯總了Java中org.dbunit.database.IDatabaseConnection.close方法的典型用法代碼示例。如果您正苦於以下問題:Java IDatabaseConnection.close方法的具體用法?Java IDatabaseConnection.close怎麽用?Java IDatabaseConnection.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dbunit.database.IDatabaseConnection
的用法示例。
在下文中一共展示了IDatabaseConnection.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testInvalidQuery
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Test
public void testInvalidQuery() throws Exception {
logger.info("-------------------- Test Invalid Query --------------------");
String queryFolder = getQueryFolderPrefix() + "src/test/resources/query/sql_invalid";
List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
for (File sqlFile : sqlFiles) {
String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
logger.info("Testing Query " + queryName);
String sql = getTextFromFile(sqlFile);
IDatabaseConnection cubeConn = new DatabaseConnection(cubeConnection);
try {
cubeConn.createQueryTable(queryName, sql);
} catch (Throwable t) {
continue;
} finally {
cubeConn.close();
}
throw new IllegalStateException(queryName + " should be error!");
}
}
示例2: testInvalidQuery
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Test
public void testInvalidQuery() throws Exception {
printInfo("-------------------- Test Invalid Query --------------------");
String queryFolder = "src/test/resources/query/sql_invalid";
List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
for (File sqlFile : sqlFiles) {
String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
printInfo("Testing Query " + queryName);
String sql = getTextFromFile(sqlFile);
IDatabaseConnection cubeConn = new DatabaseConnection(cubeConnection);
try {
cubeConn.createQueryTable(queryName, sql);
} catch (Throwable t) {
continue;
} finally {
cubeConn.close();
}
throw new IllegalStateException(queryName + " should be error!");
}
}
示例3: initializeGlobalDataFile
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* Initialize.
*
* @param context
* the context
* @param dataSource
* the data source
* @throws DatabaseUnitException
* the database unit exception
* @throws SQLException
* the SQL exception
* @throws MalformedURLException
* the malformed url exception
*/
public void initializeGlobalDataFile(ApplicationContext context)
throws DatabaseUnitException, SQLException, MalformedURLException {
DataSource datas = GlobalUtils.findDataSourceBean(context);
IDatabaseConnection con = new DatabaseConnection(datas.getConnection()); // Create
// DBUnit
// Database
// connection
FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
builder.setColumnSensing(true);
datasets = new IDataSet[] { builder.build(singleInitXmlFile) };
DatabaseOperation.REFRESH.execute(con, new CompositeDataSet(datasets)); // Import
// your
// data
// TODO handle the empty data file case.
con.close();
}
示例4: tearDownDB
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@AfterClass
public static void tearDownDB() {
System.out.println("Tearing down DB");
try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("context.xml")) {
IDatabaseConnection connection = new DatabaseDataSourceConnection(
(DataSource) applicationContext.getBean("dataSource"));
try {
DatabaseOperation.DELETE_ALL.execute(connection,
new FlatXmlDataSetBuilder().build(
applicationContext.getResource("/database_tear_down.xml").getInputStream()));
} finally {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: setupDb
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public static void setupDb() {
try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("context.xml")) {
IDatabaseConnection connection = new DatabaseDataSourceConnection(
(DataSource) applicationContext.getBean("dataSource"));
try {
DatabaseOperation.CLEAN_INSERT.execute(connection,
new FlatXmlDataSetBuilder().build(
applicationContext.getResource("/database_seed_minimal.xml").getInputStream()));
} finally {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: execute
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* 對XML文件中的數據在H2數據庫中執行Operation.
*
* @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();
}
}
}
示例7: main
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* Edit this main to do an export with desired parms
*/
public static void main(String[] args) throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection jdbcConnection = null;
try {
jdbcConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/nciadev",
"nciaAdmin",
"nciA#112");
}
catch (SQLException se) {
se.printStackTrace();
System.exit(1);
}
IDatabaseConnection conn = new DatabaseConnection(jdbcConnection);
FlatDtdDataSet.write(conn.createDataSet(), new FileOutputStream("test.dtd"));
//DbUnitUtil.exportPatient(conn, 112918531, new File("test.xml"));
//DbUnitUtil.exportCsmUser(conn, "kascice", new File("csm.xml"));
//DbUnitUtil.exportAll(conn, new File("c://temp//PublicTestData.xml"));
//DbUnitUtil.exportCollectionDescription(conn, "lethai", new File("collection_desc.xml"));
//DbUnitUtil.exportCustomSeriesList(conn, "lethai", new File("custom_series_list.xml"));
conn.close();
}
示例8: migrate
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* Run the migration using the given context.
*
* @param context the context to run under
* @throws MigrationException if an unexpected error occurs
*/
public void migrate(MigrationContext context) throws MigrationException
{
log.debug("Executing patch " + getLevel());
// down casting, technically not safe, but everyone else is doing it.
JdbcMigrationContext jdbcContext = (JdbcMigrationContext) context;
// used to close connection in finally block
Connection contextConnection = null;
try
{
FlatXmlDataSet xmlDataSet = new FlatXmlDataSet(getXmlAsStream());
// Set contextConnection so it can be accessed in the finally block.
contextConnection = jdbcContext.getConnection();
// run the data load
IDatabaseConnection connection = new DatabaseConnection(contextConnection);
DatabaseOperation.INSERT.execute(connection, xmlDataSet);
context.commit();
// Closing here instead of in finally block to keep the signature of this from throwing
// a SqlException. Exceptional condition handled in finally block to make sure
// we don't leak a connection.
connection.close();
}
catch (Exception e)
{
log.debug("Unable to patch due to " + e.getMessage());
context.rollback();
throw new MigrationException("Unable to patch", e);
}
finally
{
// Might already be closed if everything worked fine and connection.close was called
// above, in that case, calling close again shouldn't do any harm. However, if an
// exception occurred the DBUnit based connection wrapper didn't get closed, so we
// catch that case here.
SqlUtil.close(contextConnection, null, null);
}
}
示例9: resetDB
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* Leegt de database en indien gewenst wordt de stamgegevens ook gereset.
* @param testClass testclass waaruit deze methode wordt aangeroepen
* @param log logger waarin gelogd kan worden
* @param resetStamgegevens true als de stamgegevens gereset moet worden
*/
public void resetDB(final Class<?> testClass, final Logger log, final boolean resetStamgegevens) {
log.info("Preparing database");
try {
final IDatabaseConnection connection = createConnection();
try {
log.info("Resetting sequences");
resetSequences(connection);
if (resetStamgegevens) {
log.info("Truncating all tables");
truncateTables(connection);
log.info("Inserting stamgegevens kern");
insert(connection, testClass, "/sql/data/brpStamgegevens-kern.xml");
log.info("Inserting stamgegevens autaut");
insert(connection, testClass, "/sql/data/brpStamgegevens-autaut.xml");
// log.info("Inserting stamgegevens lev");
// insert(testClass, "/sql/data/brpStamgegevens-lev.xml");
log.info("Inserting stamgegevens conv");
insert(connection, testClass, "/sql/data/brpStamgegevens-conv.xml");
log.info("Inserting stamgegevens verconv");
insert(connection, testClass, "/sql/data/brpStamgegevens-verconv.xml");
log.info("Resetting specific sequences");
setStamgegevensSequences(connection);
} else {
log.info("Truncating tables no stamtabellen");
truncateTablesNoStamtabellen(connection);
}
} finally {
connection.close();
}
} catch (
DatabaseUnitException
| SQLException e) {
throw new IllegalStateException("Kan database niet intialiseren.", e);
}
}
示例10: compareNotExpectedWithActual
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* Vergelijkt een actuele dataset met een niet-verwachte dataset. Alle records in de niet-verwachte dataset dienen
* niet voor te komen in de actuele dataset. Tabellen/records die niet in de not-expected set voorkomen worden
* genegeerd.
* <p>
* @param notExpected De not-expected dataset.
* @throws DatabaseUnitException on error
* @throws SQLException on error
*/
protected void compareNotExpectedWithActual(final IDataSet notExpected) throws DatabaseUnitException, SQLException {
if (notExpected == null) {
throw new IllegalArgumentException("Argument 'notExpected' is null");
}
final IDatabaseConnection connection = createConnection();
try {
final IDataSet actual = createActualSet(connection);
final String[] notExpTableNames = notExpected.getTableNames();
for (final String currentTableName : notExpTableNames) {
final ITable expTable = notExpected.getTable(currentTableName);
final ITable actTable = actual.getTable(currentTableName);
final ITable filteredActTable = new RowFilterTable(actTable, new PrimaryKeyRowFilter(expTable));
final int actualRowCount = filteredActTable.getRowCount();
if (0 != actualRowCount) {
final String foutmelding =
"Er zijn "
+ actualRowCount
+ " records gevonden in de tabel "
+ currentTableName.toUpperCase()
+ " die voorkomen in de NOT EXPECTED dataset";
LOG.error(foutmelding);
LOG.error("****** De volgende 'NotExpected' records zijn aangetroffen in de database:");
LOG.error(FORMATTER.format(filteredActTable));
Assert.fail(foutmelding + " (zie ERROR-log voor details)");
}
}
} finally {
connection.close();
}
}
示例11: afterAll
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@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();
}
示例12: closeConnection
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
private void closeConnection( IDatabaseConnection connection )
throws SQLException
{
if ( null != connection )
{
connection.close();
}
}
示例13: testUpgrade
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Test
public void testUpgrade() throws Exception {
ProarcDatabaseV1 v1 = new ProarcDatabaseV1();
ProarcDatabaseV2 v2 = new ProarcDatabaseV2();
ProarcDatabaseV3 v3 = new ProarcDatabaseV3();
ProarcDatabaseV4 v4 = new ProarcDatabaseV4();
final IDatabaseConnection con = support.getConnection();
try {
// clear DB
dropSchema(schema);
dropSchema(v4);
dropSchema(v3);
dropSchema(v2);
dropSchema(v1);
v1.init(emireCfg);
assertEquals(1, ProarcDatabase.schemaExists(schema, con.getConnection()));
IDataSet db = support.loadFlatXmlDataStream(getClass(), "proarc_v1.xml", true);
try {
DatabaseOperation.INSERT.execute(con, db);
con.getConnection().commit();
} finally {
support.clearDtdSchema();
}
schema.init(emireCfg);
assertEquals(ProarcDatabase.VERSION, ProarcDatabase.schemaExists(schema, con.getConnection()));
} finally {
con.close();
dropSchema(schema);
dropSchema(v1);
}
}
示例14: setUp
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
protected void setUp() throws Exception {
IDatabaseConnection connection = getConnection();
IDataSet dataSet = getDataSet();
String op = getSetUpOperation().getClass().getSimpleName();
// reset the database
try {
long t1 = System.currentTimeMillis();
getSetUpOperation().execute(connection, dataSet);
long t2 = System.currentTimeMillis();
System.out.println("database reset (" + op + ") successful in " + (t2 - t1) + "ms");
} finally {
connection.close();
}
}
示例15: execute
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Override
public void execute()
throws MojoExecutionException, MojoFailureException {
if (skip) {
this.getLog().info("Skip DbUnit comparison");
return;
}
super.execute();
try {
IDatabaseConnection connection = createConnection();
try {
Compare dbUnitCompare = new Compare();
dbUnitCompare.setSrc(src);
dbUnitCompare.setFormat(format);
dbUnitCompare.setSort(sort);
for (int i = 0; queries != null && i < queries.length; ++i) {
dbUnitCompare.addQuery((Query) queries[i]);
}
for (int i = 0; tables != null && i < tables.length; ++i) {
dbUnitCompare.addTable((Table) tables[i]);
}
dbUnitCompare.execute(connection);
}
finally {
connection.close();
}
}
catch (Exception e) {
throw new MojoExecutionException("Error executing DbUnit comparison.", e);
}
}