0

dbunit の公式チュートリアルでは、単一のデータベース スキーマからデータセットをエクスポートするため の良い例が既に示されています。
異なるスキーマの異なるテーブルを 1 つのデータセットにエクスポートする方法はありますか (スキーマ A のテーブル A、スキーマ B のテーブル B など)。
エクスポートされたデータセットを xml ファイルに書き込むと、次のようになります。

<?xml version='1.0' encoding='UTF-8'?>
<dataset schema:schemaA schema:schemaB>
    <schemaA:tableA ..... />
    <schemaA:tableA ..... />
    <schemaB:tableB ..... />
</dataset>
4

1 に答える 1

2

同じ問題が発生しました。修正するには、FEATURE_QUALIFIED_TABLE_NAMES プロパティを設定する必要があります。

変更を加えた同じサンプル コードを以下に示します (完全なデータベース エクスポートは必要ないため、コードの一部を削除しました)。

    public static void main(String[] args) throws Exception
    {
        // database connection
        Class driverClass = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:sqlserver://<server>:1433;DatabaseName=<dbName>", "<usr>", "<passwd>");
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

        Properties props = new Properties();
        props.put(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, "true");
        connection.getConfig().setPropertiesByString(props);        


        // dependent tables database export: export table X and all tables that
        // have a PK which is a FK on X, in the right order for insertion
        String[] depTableNames = TablesDependencyHelper.getAllDependentTables( connection, "vehicle.Vehicle_Series_Model_SMA" );
        IDataSet depDataset = connection.createDataSet( depTableNames );
        FlatXmlDataSet.write(depDataset, new FileOutputStream("vehicle.Vehicle_Series_Model_SMA.xml"));          

    }
于 2015-12-08T20:28:43.170 に答える