You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Ma...@sungard.com on 2004/04/19 18:11:47 UTC
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: Martin.Goulet@sungard.com
Web: www.online.sungard.com
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org