Since I got no answer on this, I have coded a serializer/deserializer for the Criteria
class. And I
must say that it wokrs quite fine. If anyone thinks that this could be a good addition
to the Torque code base, please let me know and I'll be happy to share it. I don't
claim it is perfect but
it does quite a good job so far.
Thx!
MG
--
Martin Goulet, B.Sc.
Senior Software Architect
SunGard Front Office Solutions
Email: [EMAIL PROTECTED]
Web: www.online.sungard.com
> -----Original Message-----
> From: Goulet, Martin
> Sent: Monday, April 19, 2004 12:12 PM
> To: '[EMAIL PROTECTED]'
> Subject: Criteria object serialization/deserialization
>
> Hello,
>
> Anyone has ever tried to serialize a Criteria object into a byte array?
> I've implemented a Criteria serializer/deserializer and I get weird results out of
> it. For example, if I print the Criteria (through the toString() method) before
> and after it looks like the same criteria but the where clause is malformed:
>
> BEFORE: Criteria:: CSLogin.LOGINNAME<=>CSLogin.LOGINNAME='MONICA.BELLUCI':
> Current Query SQL (may not be complete or applicable): SELECT FROM CSLogin WHERE
> CSLogin.LOGINNAME='MONICA.BELLUCI'
>
> AFTER : Criteria::
> CSLogin.LOGINNAME<=>CSLogin.LOGINNAME=CSLogin.LOGINNAME='MONICA.BELLUCI':
> Current Query SQL (may not be complete or applicable): SELECT FROM CSLogin WHERE
> CSLogin.LOGINNAME=CSLogin.LOGINNAME='MONICA.BELLUCI'
>
> Notice that the where clause has twice the "CSLogin.LOGINNAME"... Obviously
> when I try to put that through a doSelect, it doesn't work at all! So has anyone
> succeeded into serializing a Criteria into a byte array? Any feedback would
> be very much appreciated!! Thx!!
>
> My code to serialize and deserialize is:
>
> public void testSerialize() throws Exception
> {
> Criteria crit, crit2;
>
> crit = new Criteria();
> crit.add( CSLoginPeer.LOGINNAME, "MONICA.BELLUCI" );
> crit2 = deserialize( serialize( crit ) );
> System.out.println( "BEFORE: " + crit.toString() );
> System.out.println( "" );
> System.out.println( "AFTER : " + crit2.toString() );
> }
>
> /**
> * Serializes the given object into a String.
> *
> * @param foo the object to serialize
> * @returns the serialization of the given object
> * @throws IOException when doublewords attack
> **/
> public byte[] serialize(Criteria foo) throws IOException {
>
>
> // The object is written to a ByteArrayOutputStream, so we can make a
> String from the byte array.
> ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
> ObjectOutputStream objStream;
>
> // Writes the object out to byteStream's internal byte array.
> objStream = new ObjectOutputStream(byteStream);
> objStream.writeObject(foo); // IOException
> objStream.close();
>
> // Convert byteStream's byte array to a String.
>
> return byteStream.toByteArray();
>
> }
>
>
> /**
> * Deserializes the given String into an Object.
> *
> * @param bar the String to deserialize
> * @returns the object represented by the given serialization
> * @throws IOException when doublewords attack
> **/
> public Criteria deserialize( byte[] foo ) throws IOException,
> OptionalDataException, ClassNotFoundException, StreamCorruptedException {
>
> ByteArrayInputStream byteStream;
> ObjectInputStream objStream;
>
> byteStream = new ByteArrayInputStream( foo );
>
> objStream = new ObjectInputStream( byteStream ); // IOException,
> StreamCorruptedException
>
> return (Criteria) objStream.readObject(); // OptionalDataException,
> ClassNotFoundException
> }
>
>
>
> MG
> --
> Martin Goulet, B.Sc.
> Senior Software Architect
> SunGard Front Office Solutions
> Email: [EMAIL PROTECTED]
> Web: www.online.sungard.com
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]