[ruby-oci8-devel] About XML DB support in Ruby-OCI8

Liming Lian liming.lian at oracle.com
Mon May 5 23:10:56 EDT 2008


Hi all,

So far, for XML DB support, we already have two approaches to implement it.

1) Without XDK

http://rubyforge.org/pipermail/ruby-oci8-devel/2008-April/000061.html

2) With XDK

http://rubyforge.org/pipermail/ruby-oci8-devel/2008-March/000057.html

I haven't fully tested those two approaches, but basic functionalities 
does work. And approach 1) supports both XML data retrieve and insert 
while approach 2)  only supports xml data retrieve.

 From the design perspective, we notice that both approaches go the same 
mechanism:  retrieve  the entire xml data from database and use it to 
construct an client side REXML document object. This is what I concern 
for the performance if the xml data is very large. Actually in Oracle 
XMLDB, there is a conception "Lazy XML Loading" defined as: Oracle XML 
DB provides a virtual DOM; it only loads rows of data as they are 
requested, throwing away previously referenced sections of the document 
if memory usage grows too large.

Maybe we can use the same approach as the Lazy XML loading. We don't 
retrieve the entire XML data when issue the cursor fetch operation, but 
instead maintain a client side object with an initialized XML context 
and retrieved xmlnode which is a pointer to XML data requested. Whenever 
users process the data of this xml doc such as retrieving child nodes, 
xpath querying and so on, we use corresponding XDK api to process data 
requested in database and retrieve the result to the client side. Or we 
can say, we add a ruby-oci8 class to wrap XDK api for processing xml 
data in database in Lazy XML loading mode. IMO, this may somehow 
increase the performance of XMLDB support in Ruby-OCI8.
 
This is only a idea, I am now making experiments on how to implement it. 
I will keep reporting  my progress and any comments are welcome.

Regards,
Liming

> Hi Liming,
>
> I have found an other way to support XML.
> It just add the following code at the end of lib/oci8/oci8.rb
>
> --------------------------------------------------------
> autoload(:REXML, 'rexml/document')
> class OCI8
>   module BindType
>     class REXML < OCI8::BindType::Long
>       def set(val)
>         super(val && val.to_s)
>       end
>       def get
>         (val = super) && ::REXML::Document.new(val)
>       end
>     end
>   end
> end
> OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::REXML
> --------------------------------------------------------
>
> We can add support for other XML libraries easily. For example:
> --------------------------------------------------------
> # Hpricot: http://code.whytheluckystiff.net/hpricot/
> require 'rubygems'
> require 'hpricot'
> class OCI8
>   module BindType
>     class HpricotXML < OCI8::BindType::Long
>       def set(val)
>         super(val && val.to_s)
>       end
>       def get
>         (val = super) && ::Hpricot.XML(val)
>       end
>     end
>   end
> end
> OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::HpricotXML
> --------------------------------------------------------
>
> libxml ruby <http://libxml.rubyforge.org/> binding will be made by similar way.
> _______________________________________________
> ruby-oci8-devel mailing list
> ruby-oci8-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ruby-oci8-devel
>   



More information about the ruby-oci8-devel mailing list