Loading ...
Sorry, an error occurred while loading the content.

Re: [xml-dbms] How to handle BLOB column types in Map file

Expand Messages
  • Ronald Bourret
    I don t have time to answer this tonight. In the mean time, search the archives [1] for binary data . This will return a number of messages that deal with
    Message 1 of 5 , Feb 20, 2005
    • 0 Attachment
      I don't have time to answer this tonight. In the mean time, search the
      archives [1] for "binary data". This will return a number of messages
      that deal with this topic. If I have time tomorrow night, I will try to
      write a FAQ for this question.

      (In your map file, you can declare the data type of the BLOB column as
      LONGVARBINARY. You will also need to write some code implementing the
      org.xmlmiddleware.conversions.formatters.StringFormatter interface to
      convert the binary data to/from Base64.)

      -- Ron

      [1] http://groups.yahoo.com/group/xml-dbms/

      Ranjan K. Baisak wrote:
      > I was wondering how to handle BLOB data types in map
      > file. One of column of my table is of type BLOB so I
      > need to define the same in map file. I would
      > appreciate of anyone can help me ?
    • Ronald Bourret
      FAQ: How do I handle binary data in XML-DBMS v2.0? ... Binary data is generally represented in XML documents in one of three ways: Base64, hexBinary, and as an
      Message 2 of 5 , Feb 24, 2005
      • 0 Attachment
        FAQ: How do I handle binary data in XML-DBMS v2.0?

        Intro:
        ------
        Binary data is generally represented in XML documents in one of three
        ways: Base64, hexBinary, and as an unparsed entity. XML-DBMS can handle
        the first two (Base64 and hexBinary) with a bit of work, but cannot
        handle the third (unparsed entities) without significant work.

        Base64 and hexBinary data are character representations of binary data.
        Base64 seems to be the most commonly used in XML. For more information
        about these, see XML Schema Part 2: Data Types:

        http://www.w3.org/TR/xmlschema-2/#base64Binary
        http://www.w3.org/TR/xmlschema-2/#hexBinary


        What you need to do:
        --------------------
        This procedure describes how to map a binary column to an XML document
        using Base64. If you want to use hexBinary, modify steps (1) and (3)
        accordingly.

        Please note that I have not actually tested this procedure, so let me
        know if there are any problems.

        1) In your map document, specify that the formatter for the binary data
        types is Base64Formatter:

        <Options>
        ...
        <FormatClass
        Class="org.xmlmiddleware.conversions.formatters.external.Base64Formatter"
        DefaultForTypes="BINARY VARBINARY LONGVARBINARY" />
        ...
        </Options>

        2) In your map document, map the binary column using the BINARY,
        VARBINARY, or LONGVARBINARY data type. For BLOB columns, use
        LONGVARBINARY. For example:

        <Table Name="MyTable">
        ...
        <Column Name="MyBLOBColumn" DataType="LONGVARBINARY" />
        ...
        </Table>

        3) Implement the parse and format methods in
        org.xmlmiddleware.conversions.formatters.external.Base64Formatter. The
        easiest way to do this is to use an existing Base64 encoder/decoder. For
        example, you might use one of the products available on SourceForge, as
        returned by this Google search:


        http://www.google.com/search?hl=en&lr=&q=base64+java+site%3Asourceforge.net&btnG=Search

        Note that you will have to use the ByteArray class defined by XML-DBMS
        for representing binary data. This simply wraps an object around a byte[].

        4) Modify the code in org.xmlmiddleware.xmldbms.Row to use ByteArray, as
        explained in:

        http://groups.yahoo.com/group/xml-dbms/message/3418

        Note that this code will cache the entire BLOB value in memory, which
        may cause problems for very large values. Unfortunately, there does not
        seem to be an easy way to fix this. You could modify this code and the
        code in Base64Formatter to use a file instead of memory, but the data
        value would still need to be cached in memory at some point anyway, as
        XML-DBMS uses DOM trees to represent XML documents.

        -- Ron
      Your message has been successfully submitted and would be delivered to recipients shortly.