cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Engelhart <mengelh...@earthtrip.com>
Subject Re: Storing XML in databases w/o lots of string parsing....
Date Fri, 21 Apr 2000 16:23:33 GMT
Williams, Murray Todd wrote:

> Let me see if I understand correctly.  Your ObjectReader and ObjectWriter
> are basically classes that serialize any java Object and store it via binary
> stream into a "blob" in a database.  Does this use Java's serialization?  If
> so, does this require DOM objects implement Serializable (I didn't think
> they did) ?
Yes, it's using serialization.  The DOM objects in Xerces appear to
implement Serializable (at least a cursory look at org.w3c.NodeImpl does)

> I'm also wondering if this is the best approach, considering that Cocoon2 is
> moving away from DOM and into SAX.  I must confess I haven't completely
> grasped the SAX event paradigm in my mind.  Does anyone know how Cocoon's
> cache works right now?  Are objects deserialized into DOM objects and then
> parsed into SAX events?  Or is there some sort of raw event stream that can
> be stored up into a binary representation?
Can't answer that as I haven't had time to even look at C2. :-(
I've been busy getting a site finished and have to stick with 1.7.x until I
get this done.
Cocoon's 1.x cache is just a very simple object cache that uses a HashTable
to stick key/value pairs into it.  Nothing gets serialized.

>> anyway, let me know if you interested and I'll forward the source.  You
>> may
>> need to tweak it a little bit to work with mySQL as I only tested it with
>> PostgreSQL.
>> 
> Thanks for the offer.  Let me make sure I know what I need before I trouble
> you for the source.  (Actually, it would probably be a good education to see
> how you were doing the serialization.)

It's totally simple.  The gist of the serialization happens in the following
2 methods.

**** from ObjectReader.java ******
private Object bytesToObject(byte[] bytes) throws IOException,
ClassNotFoundException
{
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream is = new ObjectInputStream(bais);
    return is.readObject();
}


**** from ObjectWriter.java ******
private byte[] objectToBytes(Object object) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream os = new ObjectOutputStream(baos);
    os.writeObject(object);
    return baos.toByteArray();
}

if you want the other JDBC related source I can send those too...

Mike


Mime
View raw message