本文整理匯總了Java中org.dbunit.database.IDatabaseConnection類的典型用法代碼示例。如果您正苦於以下問題:Java IDatabaseConnection類的具體用法?Java IDatabaseConnection怎麽用?Java IDatabaseConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IDatabaseConnection類屬於org.dbunit.database包,在下文中一共展示了IDatabaseConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public static void main(String[] args)
throws Exception
{
//Connect to the database
Class.forName( "com.mysql.jdbc.Driver" );
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/easyrec_test", "root", "root");
IDatabaseConnection connection = new DatabaseConnection( conn );
QueryDataSet partialDataSet = new QueryDataSet(connection);
//Specify the SQL to run to retrieve the data
partialDataSet.addTable("actionarchive1", " SELECT * FROM actionarchive1");
//Specify the location of the flat file(XML)
// file is stored in /target folder
FlatXmlWriter datasetWriter = new FlatXmlWriter(new FileOutputStream("easyrec-testutils/target/temp.xml"));
//Export the data
datasetWriter.write( partialDataSet );
}
示例2: execute
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public void execute(final IDatabaseConnection connection, final List<String> qualifiedTableNames) throws SQLException {
final IStatementFactory statementFactory = (IStatementFactory) connection.getConfig().getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
final IBatchStatement statement = statementFactory.createBatchStatement(connection);
try {
int count = 0;
for (final String tableName : qualifiedTableNames) {
statement.addBatch("DELETE FROM " + tableName);
count++;
}
if (count > 0) {
statement.executeBatch();
statement.clearBatch();
}
} finally {
statement.close();
}
}
示例3: execute
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public void execute(final IDatabaseConnection connection, final List<String> qualifiedTableNames) throws SQLException {
final IStatementFactory statementFactory = (IStatementFactory) connection.getConfig().getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
final IBatchStatement statement = statementFactory.createBatchStatement(connection);
try {
int count = 0;
for (final String tableName : qualifiedTableNames) {
if (!Arrays.asList(TABELLEN_ZONDER_SEQ).contains(tableName)) {
statement.addBatch(getAlterSequenceCommand(tableName));
count++;
}
}
if (count > 0) {
statement.executeBatch();
statement.clearBatch();
}
} finally {
statement.close();
}
}
示例4: setSpecificSequence
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
private void setSpecificSequence(final IDatabaseConnection connection, final String tableName) throws SQLException, DatabaseUnitException {
final List<String> databaseNames = new ArrayList<>();
databaseNames.add(tableName);
final PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT id from " + tableName + " order by id desc");
try (ResultSet rs = preparedStatement.executeQuery()) {
if (rs.next()) {
final long maxId = rs.getLong(1);
final long sequenceId = maxId + 1;
new RestartBrpSequenceOperation(sequenceId).execute(connection, databaseNames);
}
} finally {
try {
preparedStatement.close();
} catch (SQLException s) {
LOGGER.error("Kon preparedStatement niet sluiten");
}
}
}
示例5: main
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
/**
* @param args
* args
* @throws Exception
* Exception
*/
public static void main(String[] args) throws Exception {
String prop = "src/test/resources/jdbc.properties";
if (args.length > 0) {
prop = args[0];
}
Properties p = loadProperties(prop);
String input = "import.xls";
if (args.length > 1) {
input = args[1];
}
IDatabaseConnection con = createConnection(p);
DatabaseConfig config = con.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
factorySelector.getDataTypeFactory(con));
TableDataOperator op = new TableDataOperator();
// op.deleteInsert(con, input);
op.insertUpdate(con, input);
}
示例6: customSetup
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Before
public void customSetup() throws Exception {
super.getDatabaseTester().setSchema("linkbinder_test");
// マスタデータ
File resource = new File(getPjUserResourceName());
if (resource.exists()) {
IDataSet ds = new XlsDataSet(new FileInputStream(resource));
IDatabaseConnection connection = getConnection();
try {
DatabaseOperation.REFRESH.execute(connection, ds);
} finally {
closeConnection(connection);
}
}
super.setUp();
}
示例7: createVerifyDataAfterFeature
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Override
protected DbFeature<IDatabaseConnection> createVerifyDataAfterFeature(final ExpectedDataSets expectedDataSets) {
return (final IDatabaseConnection connection) -> {
try {
final IDataSet currentDataSet = connection.createDataSet();
final IDataSet expectedDataSet = mergeDataSets(loadDataSets(Arrays.asList(expectedDataSets.value())));
final DataSetComparator dataSetComparator = new DataSetComparator(expectedDataSets.orderBy(),
expectedDataSets.excludeColumns(), expectedDataSets.strict(), getColumnFilter(expectedDataSets));
final AssertionErrorCollector errorCollector = new AssertionErrorCollector();
dataSetComparator.compare(currentDataSet, expectedDataSet, errorCollector);
errorCollector.report();
} catch (final SQLException | DatabaseUnitException e) {
throw new DbFeatureException("Could not execute DB contents verification feature", e);
}
};
}
示例8: openConnection
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
public static IDatabaseConnection openConnection(final BasicDataSource ds) {
try {
final Connection connection = ds.getConnection();
for (final DbUnitConnectionFactory impl : SERVICE_LOADER) {
if (impl.supportsDriver(ds.getDriverClassName())) {
return impl.createConnection(connection);
}
}
// fall back if no specific implementation is available
return new DatabaseConnection(connection);
} catch (final DatabaseUnitException | SQLException e) {
throw new JpaUnitException(e);
}
}
示例9: createConnection
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Override
public IDatabaseConnection createConnection(final Connection connection) throws DatabaseUnitException {
final IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
dbUnitConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());
return dbUnitConnection;
}
示例10: testVerifyDataAfterFeatureExecution
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Test
public void testVerifyDataAfterFeatureExecution() throws DbFeatureException, SQLException, DataSetException {
// GIVEN
final IDataSet currentDs = mock(IDataSet.class);
when(currentDs.getTableNames()).thenReturn(new String[] {});
when(connection.createDataSet()).thenReturn(currentDs);
when(expectedDataSets.strict()).thenReturn(Boolean.FALSE);
when(expectedDataSets.value()).thenReturn(new String[] {});
when(expectedDataSets.orderBy()).thenReturn(new String[] {});
when(expectedDataSets.excludeColumns()).thenReturn(new String[] {});
// WHEN
final DbFeature<IDatabaseConnection> feature = featureExecutor.createVerifyDataAfterFeature(expectedDataSets);
assertThat(feature, notNullValue());
feature.execute(connection);
// THEN
verify(connection).createDataSet();
verifyNoMoreInteractions(connection);
}
示例11: beforeTestMethod
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
DataSetLocation dsLocation = testContext.getTestInstance().getClass().getAnnotation(DataSetLocation.class);
if (dsLocation != null) {
String dataSetResourcePath = dsLocation.value();
Resource dataSetResource = testContext.getApplicationContext().getResource(dataSetResourcePath);
if (dataSetResource.exists()) {
IDataSet dataSet = new FlatXmlDataSetBuilder().build(dataSetResource.getInputStream());
IDatabaseConnection dbConn = new DatabaseDataSourceConnection(
testContext.getApplicationContext().getBean(DataSource.class)
);
DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);
LOG.info("Annotated test, using data set: {}", dataSetResourcePath);
}
}
}
示例12: createPreparedBatchStatement
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
@Override
public IPreparedBatchStatement createPreparedBatchStatement(String sql,
IDatabaseConnection connection) throws SQLException {
if (logger.isDebugEnabled()) {
logger.debug("createPreparedBatchStatement(sql={}, connection={}) - start", sql, connection);
}
Integer batchSize =
(Integer) connection.getConfig().getProperty(DatabaseConfig.PROPERTY_BATCH_SIZE);
IPreparedBatchStatement statement = null;
if (supportBatchStatement(connection)) {
statement = new PreparedBatchDefaultValueStatement(sql, connection.getConnection());
} else {
statement = new SimplePreparedDefaultValueStatement(sql, connection.getConnection());
}
return new AutomaticPreparedBatchStatement(statement, batchSize.intValue());
}
示例13: cleanInsertIntoDatabase
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
/**
* 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 );
}
}
示例14: getConnection
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
protected IDatabaseConnection getConnection() throws Exception
{
Configuration 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;
}
示例15: getConnection
import org.dbunit.database.IDatabaseConnection; //導入依賴的package包/類
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;
}
開發者ID:testIT-LivingDoc,項目名稱:livingdoc-confluence,代碼行數:20,代碼來源:AbstractDBUnitHibernateMemoryTest.java