导出/导入DBUnit中的数据类型



我正试图使用DBUnit从我们的AS400导出数据,并将其导入HSQLDB数据库进行JUnit测试,然而,数据类型信息似乎无法导出/导入。所有内容似乎都被导出(因此将被导入)为CDATA。有人能告诉我在哪里找到答案吗?

我已经成功地构建并运行了其中一个示例:

public static void main(String[] args) throws Exception
{
    // database connection
    Class driverClass = Class.forName("com.ibm.as400.access.AS400JDBCDriver");
    Connection jdbcConnection = DriverManager.getConnection("jdbc:as400://myserver;libraries=MYLIB", "user", "password");
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
    // partial database export
    QueryDataSet partialDataSet = new QueryDataSet(connection);
    partialDataSet.addTable("TABLE1");
    partialDataSet.addTable("TABLE2");
    FlatXmlDataSet.write(partialDataSet, new FileOutputStream("flatpartial_as400.xml"));
    FlatDtdDataSet.write(connection.createDataSet(), new FileOutputStream("flatdtd_as400.dtd"));
    XmlDataSet.write(partialDataSet, new FileOutputStream("partial_as400.xml"));

例如,这给了我以下输出:

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
  <TABLE1/>
  <TABLE2 ADDRESS_ID="1" ADDRESS_TYPE="1" ADDRESS_DESCRIPTION="Billing Address          "/>
  <TABLE2 ADDRESS_ID="2" ADDRESS_TYPE="2" ADDRESS_DESCRIPTION="Delivery Address         "/>
  <TABLE2 ADDRESS_ID="3" ADDRESS_TYPE="3" ADDRESS_DESCRIPTION="Owner Address            "/>
  <TABLE2 ADDRESS_ID="4" ADDRESS_TYPE="4" ADDRESS_DESCRIPTION="Owner Previous Address   "/>
  <TABLE2 ADDRESS_ID="5" ADDRESS_TYPE="5" ADDRESS_DESCRIPTION="Store Address            "/>
</dataset>

以下是生成的DTD片段:

<!ELEMENT TABLE2 EMPTY>
<!ATTLIST TABLE2
    ADDRESS_ID CDATA #REQUIRED
    ADDRESS_TYPE CDATA #REQUIRED
    ADDRES_DESCRIPTION CDATA #REQUIRED
>

第一个字段应该是DECIMAL(10,0),但它是CDATA。显然,从数据完整性的角度来看,这将是一个问题。在调试器中,我可以看到类型信息正在进入DBUnit包(代码中的ADDRESS_ID字段是DECIMAL。)但这些信息并没有进入文件的XML DTD。

任何帮助都将不胜感激。。。

也许它会有所帮助:为要导入的表生成dtd文件

private static void generateDTD(String fileName,IDatabaseConnection connection,
        String[] tablesToExport) throws IOException, DataSetException,
        SQLException, FileNotFoundException {
    FlatDtdDataSet.write(connection.createDataSet(tablesToExport), new FileOutputStream(fileName));
}

然后在生成器中设置

FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
        builder.setMetaDataSetFromDtd(new FileInputStream(schemaFile));

相关内容

  • 没有找到相关文章

最新更新