db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Morrogh" <jmorr...@hotmail.com>
Subject Problem with Criteria After Deserializing
Date Mon, 28 Mar 2005 01:54:11 GMT
Hi,

I've got a Torque 3.0 application (part of a Turbine 2.2 webapp) and I want 
to add persistent query
funtionality to it.  Since the Torque Criteria class already represents a 
set of query criteria, and is serializable, it seems logical to persist 
instances of this class for my purposes.  The problem I'm
having is that the deserialized Criteria object doesn't behave exactly the 
same as the object that
existed prior to serialization.  Specifically, my Criterion objects in the 
hash seem to contain an
addtional layer of Criterion objects after deserialization.  For example, if 
my search criteria is    "MY_TABLE.MYCOLUMN = 'AAA'", before serialization, 
I've got one Criterion in the hash whose value is "AAA".  After 
serialization, I've still got one Criterion in the hash, but the value is 
not the String
"AAA", but another Criterion object, whose value is then "AAA".  The end 
result of all this is that when the query is generated, I end up with an 
invalid query like:

    select * from MY_TABLE where MYCOLUMN=MYCOLUMN='AAA'

I'm rying to avoid coding my own classes to represent the "where clause".  
Any ideas?

TIA,
Joe

Below is a simple program that demonstrates the problem.


import java.io.*;
import org.apache.torque.util.Criteria;

public class SerializeCriteriaTest {

public static void main(String args[]) throws Exception {

	System.out.println("Entering SerializeCriteriaTest::main");
	Criteria criteria = new Criteria();
	criteria.add("MY_TABLE.MYCOLUMN", (Object) "AAA",
	Criteria.EQUAL);
	System.out.println(criteria.toString());

	ByteArrayOutputStream bas = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(bas);
	oos.writeObject(criteria);
	byte [] bytes = bas.toByteArray();
	System.out.println("the length of bytes is " + 	bytes.length);

	Criteria criteriaReborn =
	   (Criteria) new ObjectInputStream(new 
ByteArrayInputStream(bytes)).readObject();
	System.out.println(criteriaReborn.toString());

}} // end class


Here's the stdout

Entering SerializeCriteriaTest::main
Criteria:: MY_TABLE.MYCOLUMN<=>MY_TABLE.MYCOLUMN='AAA':
Current Query SQL (may not be complete or applicable):
the length of bytes is 1544
Criteria:: MY_TABLE.MYCOLUMN<=>MY_TABLE.MYCOLUMN=MY_TABLE.MYCOLUMN='AAA':
Current Query SQL (may not be complete or applicable):



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message