db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cameron Hickey" <...@panoramatos.com>
Subject RE: Generic Admin Tool for Torque Objects
Date Fri, 12 Sep 2003 07:42:52 GMT
I too tried to accomplish this a while back, without considerable
success.  I wish there was a means for dynamically casting an object in
java based on a string value, but this does not appear possible (I am
pretty new to java, so correct me if I am wrong).  Your suggestion to
create a superclass, and have all the OM objects extend that class seems
to be the only sane way to accomplish your goal, and will also allow you
to implement any other convenience methods you need in this superclass
only once, as opposed to adding them to the velocity templates, and have
them generated individually for each Base and Peer object created.

Without this path, here is some code someone else on this list
originally gave to me, which seemed to accomplish the same goal you
have.

Perhaps the problem is where you are using the "getMethod()" method...
in this code, it is applied directly to the Class.forName(classname)
method, which should properly return any methods of this class.


String s = httpservletrequest.getParameter("ObjType");
String myclass = "RentalApp.torque.om.";
BasePeer basepeer =
(BasePeer)Class.forName(myclass+s+"Peer").newInstance();
String s1 =
(String)Class.forName(myclass+s+"Peer").getField("DATABASE_NAME").get(ba
sepeer);
String s2 = (String)Class.forName(myclass + s +
"Peer").getField("TABLE_NAME").get(basepeer);
Criteria criteria = new Criteria();
criteria.setDbName(s1);
Class aclass[] = new Class[1];
aclass[0] = criteria.getClass();
Method method = Class.forName(myclass + s +
"Peer").getMethod("doSelect", aclass);
Object aobj[] = new Object[1];
aobj[0] = criteria;
List list = (List)method.invoke(basepeer, aobj);
List list1 = BaseProperty.getFieldNames();

Good luck, and HTH.

Cameron

-----Original Message-----
From: Josh Holtzman [mailto:josh@joshholtzman.com] 
Sent: Friday, September 12, 2003 1:13 AM
To: torque-user@db.apache.org
Subject: Generic Admin Tool for Torque Objects

I am interested in developing a generic "admin" tool to display all of
the fields for any given torque object.  I thought I could use
reflection to get the call to the getFields() method, but I can't.
Here's what happens:

1) Class c = Class.forName(request.getParameter("type"));
2) Object o = c.newInstance();
3) Method m = c.getMethod("getFields", null);

Line 3 throws an error, because Object doesn't have a getFields()
method.  If I specify "wait" or "notify", it works fine because these
methods are defined in Object.

So, I suppose the answer is to cast to a BaseObject type... Wrong! The
problem is that BaseObject doesn't have getFields() either.  So, I'm
still stuck.  There is o comon superclass that I can cast to in order to
get a list of fields in the unknown torque object.

Is there any way to get the field names (and hence, values) for an
unknown torque object type?  Do I need to create an empty torque object
in my schema and have al of my other objects extend this one, just so I
can get a common superclass with the getFields() method?

I hope this makes sense.  Thanks for any ideas!

Josh

=============================
JOSH HOLTZMAN Web Development
http://joshholtzman.com
============================= 


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


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message