當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseConnection類代碼示例

本文整理匯總了Java中org.dbunit.database.DatabaseConnection的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseConnection類的具體用法?Java DatabaseConnection怎麽用?Java DatabaseConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DatabaseConnection類屬於org.dbunit.database包,在下文中一共展示了DatabaseConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.dbunit.database.DatabaseConnection; //導入依賴的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 );
}
 
開發者ID:major2015,項目名稱:easyrec_major,代碼行數:22,代碼來源:DbUnitSqlToXmlExporter.java

示例2: initEntityManager

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
/**
 * Set up memory database and insert data from test-dataset.xml
 * 
 * @throws DatabaseUnitException
 * @throws HibernateException
 * @throws SQLException
 */
@BeforeClass
public static void initEntityManager() throws HibernateException, DatabaseUnitException, SQLException {
    entityManagerFactory = Persistence.createEntityManagerFactory("listing-test-db");
    entityManager = entityManagerFactory.createEntityManager();
    connection = new DatabaseConnection(((SessionImpl) (entityManager.getDelegate())).connection());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetXml);
    if (inputStream != null) {
        FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
        flatXmlDataSetBuilder.setColumnSensing(true);
        dataset = flatXmlDataSetBuilder.build(inputStream);
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
    }
}
 
開發者ID:coodoo-io,項目名稱:coodoo-listing,代碼行數:23,代碼來源:AbstractDbUnitTest.java

示例3: shouldExportDataSetUsingSubSelectToFilterRows

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@Test
@DataSet("datasets/yml/users.yml")
public void shouldExportDataSetUsingSubSelectToFilterRows() throws SQLException, DatabaseUnitException {
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()),
            new DataSetExportConfig().
                    outputFileName("target/querySubselect.yml").
                    //export only users that have tweets
                    queryList(new String[]{"select * from user u where u.id in" +
                            " (select t.user_id from tweet t)"})
    );
    File ymlDataSet = new File("target/querySubselect.yml");
    assertThat(ymlDataSet).exists();
    assertThat(contentOf(ymlDataSet)).
        isEqualTo("user:"+NEW_LINE +
                "  - ID: 1"+NEW_LINE +
                "    NAME: \"@realpestano\""+NEW_LINE+NEW_LINE);
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:18,代碼來源:ExportDataSetIt.java

示例4: shouldNotExportNullColumnsInYMLDataSet

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@Test
public void shouldNotExportNullColumnsInYMLDataSet() throws SQLException, DatabaseUnitException {
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()), new DataSetExportConfig().outputFileName("target/userWithNullProperty.yml"));
    File ymlDataSet = new File("target/userWithNullProperty.yml");
    assertThat(ymlDataSet).exists();
    assertThat(contentOf(ymlDataSet)).
            contains("FOLLOWER:" + NEW_LINE +
                            "" + NEW_LINE +
                            "SEQUENCE:" + NEW_LINE +
                            "  - SEQ_NAME: \"SEQ_GEN\"" + NEW_LINE +
                            "    SEQ_COUNT: 50" + NEW_LINE +
                            "" + NEW_LINE +
                            "TWEET:" + NEW_LINE +
                            "" + NEW_LINE +
                            "USER:" + NEW_LINE +
                            "  - ID: 1" + NEW_LINE + NEW_LINE
            );
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:19,代碼來源:ExportNullPropertiesIt.java

示例5: shouldNotExportNullColumnsInJSONDataSet

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@Test
public void shouldNotExportNullColumnsInJSONDataSet() throws SQLException, DatabaseUnitException{
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()), new DataSetExportConfig().
            dataSetFormat(DataSetFormat.JSON).outputFileName("target/userWithNullProperty.json"));
    File xmlDataSet = new File("target/userWithNullProperty.json");
    assertThat(xmlDataSet).exists();
    assertThat(contentOf(xmlDataSet).replaceAll("\r","")).isEqualTo(("{"+NEW_LINE +
            "  \"FOLLOWER\": ["+NEW_LINE +
            "  ],"+NEW_LINE +
            "  \"SEQUENCE\": ["+NEW_LINE +
            "    {"+NEW_LINE +
            "      \"SEQ_NAME\": \"SEQ_GEN\","+NEW_LINE +
            "      \"SEQ_COUNT\": 50"+NEW_LINE +
            "    }"+NEW_LINE +
            "  ],"+NEW_LINE +
            "  \"TWEET\": ["+NEW_LINE +
            "  ],"+NEW_LINE +
            "  \"USER\": ["+NEW_LINE +
            "    {"+NEW_LINE +
            "      \"ID\": 1,"+NEW_LINE +
            "    }"+NEW_LINE +
            "  ]"+NEW_LINE +
            "}").replaceAll("\r",""));

}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:26,代碼來源:ExportNullPropertiesIt.java

示例6: openConnection

import org.dbunit.database.DatabaseConnection; //導入依賴的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);
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:DatabaseConnectionFactory.java

示例7: createConnection

import org.dbunit.database.DatabaseConnection; //導入依賴的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;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:8,代碼來源:PostgresqlConnectionFactory.java

示例8: testOpenConnectionToSqliteDbHavingAllSupportedPersistenceProperties

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@Test
public void testOpenConnectionToSqliteDbHavingAllSupportedPersistenceProperties() throws Exception {
    // This test is about a fall back functionality
    // GIVEN
    final File dbFile = folder.newFile("test.db");

    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(SQLITE_DRIVER_CLASS_PROP_VALUE);
    ds.setUsername(USERNAME_PROP_VALUE);
    ds.setPassword(PASSWORD_PROP_VALUE);
    ds.setUrl(SQLITE_CONNECTION_URL_PROP_PREFIX + dbFile.getAbsolutePath());

    // WHEN
    connection = DatabaseConnectionFactory.openConnection(ds);

    // THEN
    assertThat(connection, notNullValue());
    assertThat(connection.getClass(), equalTo(DatabaseConnection.class));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:20,代碼來源:DatabaseConnectionFactoryTest.java

示例9: testOpenConnectionToSqliteDbWithoutHavingUsernameAndPasswordProperties

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@Test
public void testOpenConnectionToSqliteDbWithoutHavingUsernameAndPasswordProperties() throws Exception {
    // GIVEN
    final File dbFile = folder.newFile("test.db");

    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(SQLITE_DRIVER_CLASS_PROP_VALUE);
    ds.setUrl(SQLITE_CONNECTION_URL_PROP_PREFIX + dbFile.getAbsolutePath());

    // WHEN
    connection = DatabaseConnectionFactory.openConnection(ds);

    // THEN
    assertThat(connection, notNullValue());
    assertThat(connection.getClass(), equalTo(DatabaseConnection.class));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:DatabaseConnectionFactoryTest.java

示例10: setUp

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    initialDataSet = new FlatXmlDataSetBuilder().build(new File("src/test/resources/test-data.xml"));
    connection = new DatabaseConnection(DriverManager.getConnection(CONNECTION_URL, USER_NAME, PASSWORD));

    final DatabaseOperation operation = DatabaseOperation.CLEAN_INSERT;
    operation.execute(connection, initialDataSet);

    connection.getConnection().createStatement().execute(
            "insert into XML_TABLE_1(id, version, value_1, value_2, value_3, value_4, value_5) values(10, 'Record 10 version', 'Record 10 Value 1', 'Record 10 Value 2', 'Record 10 Value 3', 'Record 10 Value 4', 'Record 10 Value 5');");
    connection.getConnection().commit();

    connection.getConnection().createStatement().execute(
            "merge into XML_TABLE_3(id, version, value_8, value_9) values(11, 'Record 11 version', 'Record 11 Value 8', 'Record 11 Value 9');");
    connection.getConnection().commit();

    assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(4));
    assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1));
    assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:21,代碼來源:CleanupStrategyProviderTest.java

示例11: insertDbUnitTestdata

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
/**
 * Inserts test data in DbUnit XML format.
 *
 * @param entityManager
 *           the EntityManager
 * @param dbUnitTestdata
 *           test file stream
 */
public static void insertDbUnitTestdata(EntityManager entityManager, final InputStream dbUnitTestdata) {

   entityManager.unwrap(Session.class).doWork(new Work() {

      @Override
      public void execute(Connection connection) throws SQLException {
         // Insert Testdata
         try {
            LOGGER.debug("INSERTing testdata");
            DatabaseConnection databaseConnection = new DatabaseConnection(connection);
            databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
               new MySqlDataTypeFactory());

            FlatXmlDataSet dataSet = new FlatXmlDataSet(
               new FlatXmlProducer(new InputSource(dbUnitTestdata), false, true));
            DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
            LOGGER.debug("INSERTing testdata ... done");
         } catch (DatabaseUnitException e) {
            throw new SQLException(e);
         }
      }

   });
}
 
開發者ID:kaiwinter,項目名稱:testcontainers-examples,代碼行數:33,代碼來源:DockerDatabaseTestUtil.java

示例12: getConnection

import org.dbunit.database.DatabaseConnection; //導入依賴的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;
    }
 
開發者ID:strator-dev,項目名稱:greenpepper,代碼行數:20,代碼來源:AbstractDBUnitHibernateMemoryTest.java

示例13: getConnection

import org.dbunit.database.DatabaseConnection; //導入依賴的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

示例14: testInvalidQuery

import org.dbunit.database.DatabaseConnection; //導入依賴的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!");
    }
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:22,代碼來源:ITKylinQueryTest.java

示例15: testVersionQuery

import org.dbunit.database.DatabaseConnection; //導入依賴的package包/類
@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);
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:18,代碼來源:ITKylinQueryTest.java


注:本文中的org.dbunit.database.DatabaseConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。