db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cameron Hickey" <...@panoramatos.com>
Subject Dynamically Accessing Torque Objects
Date Tue, 29 Jul 2003 07:22:09 GMT
I realize that this may seem both strange, and naïve, but I want to be
able to choose which Torque Data object to access by passing in a String
value.  Has anyone else attempted something similar to this before?
What would be a logical syntax for it?

This obviously shows my lack of fluency with Java, but here is what I am

	String theObjStr = (String)request.getParameter("ObjType");
	String objectPeerStr = "RentalApp.torque.om." + theObjStr +
	Class c = Class.forName(objectPeerStr);
	BasePeer objectRef = (BasePeer)c.newInstance();
	Criteria crit = new Criteria();
	List v = objectRef.doSelect(crit);
This does not actually work properly, although it does manage to load
the proper class, because I don't know what class it is ahead of time, I
cast the class to to BasePeer, but the BasePeer object cannot manage the
connection to the database properly, because it does not know which
table it should be connected to. 

Is there some other way of doing this?  This is a java question, but: Is
there a way to cast my newly created object to the appropriate class
without knowing what it is ahead of time?

Sadly, because this seems a little futile, I may end up going back to
regurlar old SQL in my servlets, which really seems like too many steps
backward, unless I can get something like this working.

Thanks for any help


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

View raw message