db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: Get type of fields in auto generated classse
Date Fri, 18 Jan 2008 19:50:10 GMT
Not really a bug, they just use different types of
names as keys.  In the OM code (record/peer objects), 
they use the Java Name for the field.  In the Map code,
they use the SQL column names.  Mainly because these
sections on code focus on different areas. E.g.the Map 
code handles mapping the SQL schema and the OM code 
handles making it easy for Java programmers.

The ColumnMap objects also contains the JavaName for
the column. So, if you want to use this instead of 
the SQL name, you can use the getColumns() method in
TableMap and search this for the column with the 
matching JavaName.


> -----Original Message-----
> From: Martin Tilsted [mailto:tiller@daimi.au.dk] 
> Sent: Friday, January 18, 2008 9:33 AM
> To: Apache Torque Users List
> Subject: Re: Get type of fields in auto generated classse
> 
> Greg Monroe wrote:
> > All record objects and table Peer objects will have a
> > getTableMap() function.  You can use this to access all
> > the schema information.  E.g.:
> >
> > rec.getTableMap().getColumn(fieldName).getType();
> >   
> Think you, this work, but there is one small catch.
> In the database I have a field called
> name varchar(255) not nul,
> And to get the class I use
> BaseObject p;
> Class myClass=p.getTableMap().getColumn("name").getType().getClass();
> 
> And this works fine. I get the class back. But if I want to use 
> p.getByName() to get the value of the field
> I have to call with
> p.getByName("Name");
> That is: Give name with big N.
> 
> I don't know if this is a bug(I use torque 3.3 RC3) or a feature, but 
> it's rather confusing that the name of the column depend on 
> where I call 
> from.
> 
> Martin Tilsted
> > Will
> >  return a "sample object" of the same type as the
> > field.  Note that the XML can defined the objects being
> > returned via the getFieldName() methods as primitives.  
> > Since you can't return a primitive, the getType() 
> > returns the Object version of the primitive.  You may
> > need to check the usePrimitive property to verify the
> > actual type.
> >
> >   
> >> -----Original Message-----
> >> From: Martin Tilsted [mailto:tiller@daimi.au.dk] 
> >> Sent: Thursday, January 17, 2008 5:27 PM
> >> To: torque-user@db.apache.org
> >> Subject: Get type of fields in auto generated classse
> >>
> >> Is there a way to make a method, that given a field name, and 
> >> any auto generated object, can return the type of that field?
> >>
> >> Something like
> >> boolean isFieldAnInteger(BaseObject obj,String fieldName)  {
> >>     // What here. (And is BaseObject the correct class to 
> >> use, if you want to accept something that can be any torque 
> >> auto generated class?) }
> >>
> >> At first I thought I could do
> >> Class c=obj. getByName(field).getClass(); But that don't work 
> >> if obj is a newly created object, becasue getByName will 
> return null.
> >>
> >> Martin
> >>
> >>
> >>
> >>
> >>
> >> 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail: torque-user-help@db.apache.org
> >>
> >>
> >>     
> > DukeCE Privacy Statement:
> > Please be advised that this e-mail and any files transmitted with
> > it are confidential communication or may otherwise be privileged or
> > confidential and are intended solely for the individual or entity
> > to whom they are addressed. If you are not the intended recipient
> > you may not rely on the contents of this email or any attachments,
> > and we ask that you please not read, copy or retransmit this
> > communication, but reply to the sender and destroy the email, its
> > contents, and all copies thereof immediately. Any unauthorized
> > dissemination, distribution or copying of this communication is
> > strictly prohibited.
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> >
> >   
> 
> 

---------------------------------------------------------------------
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