本文整理匯總了Java中org.dbunit.database.IDatabaseConnection.getConfig方法的典型用法代碼示例。如果您正苦於以下問題:Java IDatabaseConnection.getConfig方法的具體用法?Java IDatabaseConnection.getConfig怎麽用?Java IDatabaseConnection.getConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dbunit.database.IDatabaseConnection
的用法示例。
在下文中一共展示了IDatabaseConnection.getConfig方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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
示例4: compareTables
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public void compareTables(String expectedDatasetFileName, String... tableNames) throws Exception {
JdbcDatabaseTester jdbc = new JdbcDatabaseTester("org.hsqldb.jdbcDriver", "jdbc:hsqldb:file:./db/example-db;ifexists=true;shutdown=true;", "sa", "");
IDatabaseConnection connection = jdbc.getConnection();
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
IDataSet databaseDataSet = connection.createDataSet();
IDataSet expectedDataSet = new FlatXmlDataFileLoader().load(expectedDatasetFileName);
for (String tableName : tableNames) {
ITable actualTable = databaseDataSet.getTable(tableName);
ITable expectedTable = expectedDataSet.getTable(tableName);
Assertion.assertEquals(expectedTable, actualTable);
}
}
示例5: create
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Override
public IDatabaseConnection create() {
Connection jdbcConnection = this.getConnection();
JdbcMetaDataExtractor extractor = new JdbcMetaDataExtractor(jdbcConnection);
String userName = extractor.getUserName();
try {
IDatabaseConnection dbUnitConn = new OracleConnection(jdbcConnection, userName);
DatabaseConfig config = dbUnitConn.getConfig();
// oracle 10g
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory());
// receycle bin (skip oracle 10g recycle bin system tables if enabled)
config.setProperty(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, Boolean.TRUE);
return dbUnitConn;
} catch (DatabaseUnitException e) {
throw new IllegalStateException(
"It's not possible to create a Oracle DbUnit connection: "
+ e.getMessage(), e);
}
}
示例6: connectionRetrieved
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Override
public void connectionRetrieved(final IDatabaseConnection connection) {
final DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());
config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);
config.setProperty(DatabaseConfig.PROPERTY_BATCH_SIZE, 300);
config.setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, true);
}
示例7: createConnection
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
/**
* Geeft een door DBUnit gewrapte connectie terug naar de testdatabase.
* @return Een DBUnit {@link IDatabaseConnection} naar de testdatabase.
* @throws SQLException on error
* @throws DatabaseUnitException on error
*/
public IDatabaseConnection createConnection() throws DatabaseUnitException, SQLException {
final IDatabaseConnection connection = new DatabaseConnection(createSqlConnection());
final DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, Boolean.TRUE);
config.setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, Boolean.TRUE);
config.setProperty(DatabaseConfig.PROPERTY_BATCH_SIZE, INT_5000);
if (inMemory) {
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
} else {
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());
}
return connection;
}
示例8: getSetUpOperation
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
protected DatabaseOperation getSetUpOperation() throws Exception {
parseCreateTableScriptFile();
initSpringContext();
return new CompositeOperation(new DatabaseOperation[] { new DatabaseOperation() {
@Override
public void execute(IDatabaseConnection connection, IDataSet dataSet)
throws DatabaseUnitException, SQLException {
DatabaseConfig databaseConfig = connection.getConfig();
IStatementFactory statementFactory = (IStatementFactory) databaseConfig
.getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
IBatchStatement statement = statementFactory.createBatchStatement(connection);
try {
int count = 0;
for (SingleCreateTableScriptEntry entry : createdTableList) {
statement.addBatch(entry.getCreateTableScript());
count++;
}
if (count > 0) {
statement.executeBatch();
statement.clearBatch();
}
} finally {
statement.close();
}
}
}, DatabaseOperation.CLEAN_INSERT });
}
示例9: getTearDownOperation
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
protected DatabaseOperation getTearDownOperation() throws Exception {
return new DatabaseOperation() {
@Override
public void execute(IDatabaseConnection connection, IDataSet dataSet)
throws DatabaseUnitException, SQLException {
DatabaseConfig databaseConfig = connection.getConfig();
IStatementFactory statementFactory = (IStatementFactory) databaseConfig
.getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
IBatchStatement statement = statementFactory.createBatchStatement(connection);
try {
int count = 0;
for (SingleCreateTableScriptEntry entry : createdTableList) {
statement.addBatch("drop table " + entry.getTableName());
count++;
}
if (count > 0) {
statement.executeBatch();
statement.clearBatch();
}
} finally {
statement.close();
}
}
};
}
示例10: execute
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
@Override
public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException {
DatabaseConfig databaseConfig = connection.getConfig();
IStatementFactory statementFactory = (IStatementFactory) databaseConfig.getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
IBatchStatement statement = statementFactory.createBatchStatement(connection);
try {
int count = 0;
ITableIterator iterator = dataSet.iterator();
while (iterator.next()) {
String tableName = iterator.getTableMetaData().getTableName();
StringBuilder sql = new StringBuilder();
sql.append("delete from ");
sql.append(this.getQualifiedName(this.schema, tableName, connection));
statement.addBatch(sql.toString());
count++;
}
if (count > 0) {
statement.executeBatch();
statement.clearBatch();
}
} finally {
statement.close();
}
}
示例11: getConnection
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
public IDatabaseConnection getConnection() throws Exception {
IDatabaseConnection connection = super.getConnection();
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, true);
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
return connection;
}
示例12: compareTables
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
protected void compareTables(String expectedDatasetFileName, String... tableNames) throws Exception {
IDatabaseConnection connection = jdt.getConnection();
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
IDataSet databaseDataSet = connection.createDataSet();
IDataSet expectedDataSet = new FlatXmlDataFileLoader().load(expectedDatasetFileName);
for (String tableName : tableNames) {
ITable actualTable = databaseDataSet.getTable(tableName);
ITable expectedTable = expectedDataSet.getTable(tableName);
Assertion.assertEquals(expectedTable, actualTable);
}
}
示例13: createConnection
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
IDatabaseConnection createConnection()
throws Exception
{
// Instantiate JDBC driver
Class dc = Class.forName( driver );
Driver driverInstance = (Driver) dc.newInstance();
Properties info = new Properties();
info.put( "user", username );
if ( password != null )
{
info.put( "password", password );
}
Connection conn = driverInstance.connect( url, info );
if ( conn == null )
{
// Driver doesn't understand the URL
throw new SQLException( "No suitable Driver for " + url );
}
conn.setAutoCommit( true );
IDatabaseConnection connection = new DatabaseConnection( conn, schema );
DatabaseConfig config = connection.getConfig();
config.setFeature( DatabaseConfig.FEATURE_BATCHED_STATEMENTS, supportBatchStatement );
config.setFeature( DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, useQualifiedTableNames );
config.setFeature( DatabaseConfig.FEATURE_DATATYPE_WARNING, datatypeWarning );
config.setFeature( DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, this.skipOracleRecycleBinTables );
config.setFeature( DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, caseSensitiveTableNames );
config.setProperty( DatabaseConfig.PROPERTY_ESCAPE_PATTERN, escapePattern );
config.setProperty( DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory() );
// Setup data type factory
IDataTypeFactory dataTypeFactory = (IDataTypeFactory) Class.forName( dataTypeFactoryName ).newInstance();
config.setProperty( DatabaseConfig.PROPERTY_DATATYPE_FACTORY, dataTypeFactory );
// Setup metadata handler
IMetadataHandler metadataHandler = (IMetadataHandler) Class.forName( metadataHandlerName ).newInstance();
config.setProperty( DatabaseConfig.PROPERTY_METADATA_HANDLER, metadataHandler );
return connection;
}
示例14: createConnection
import org.dbunit.database.IDatabaseConnection; //導入方法依賴的package包/類
IDatabaseConnection createConnection()
throws Exception {
// Instantiate JDBC driver
Class dc = Class.forName(driver);
Driver driverInstance = (Driver) dc.newInstance();
Properties info = new Properties();
info.put("user", username);
if (password != null) {
info.put("password", password);
}
Connection conn = driverInstance.connect(url, info);
if (conn == null) {
// Driver doesn't understand the URL
throw new SQLException("No suitable Driver for " + url);
}
conn.setAutoCommit(true);
IDatabaseConnection connection = new DatabaseConnection(conn, schema);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, supportBatchStatement);
config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, useQualifiedTableNames);
config.setProperty(DatabaseConfig.FEATURE_DATATYPE_WARNING, datatypeWarning);
config.setProperty(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, this.skipOracleRecycleBinTables);
config.setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, caseSensitiveTableNames);
config.setProperty(DatabaseConfig.PROPERTY_ESCAPE_PATTERN, escapePattern);
config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory());
// Setup data type factory
IDataTypeFactory dataTypeFactory = (IDataTypeFactory) Class.forName(dataTypeFactoryName).newInstance();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, dataTypeFactory);
// Setup metadata handler
IMetadataHandler metadataHandler = (IMetadataHandler) Class.forName(metadataHandlerName).newInstance();
config.setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, metadataHandler);
return connection;
}