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: BaseMyTable.getFieldNames() replacement?
Date Wed, 12 Apr 2006 17:35:48 GMT
FWIW, I thought this rang a bell... you might look
at the following Scarab issue.

http://issues.apache.org/scarab/issues/id/TRQS344

It's a enhancement I submitted for adding an XML 
export feature to Torque's runtime. Include in it
is an updated version of TableMap that preserves 
the XML order. (Uses Map instead of Hashtable).

> -----Original Message-----
> From: Greg Monroe [mailto:Greg.Monroe@DukeCE.com] 
> Sent: Wednesday, April 12, 2006 1:20 PM
> To: Apache Torque Users List
> Subject: RE: BaseMyTable.getFieldNames() replacement?
> 
> 
> Hmm, I looked at my Torque 3.2 generated classes and I
> see a getFieldNames() method being generated.
> 
> I think the problem may be in your build.properties
> file.  There have been a lot of major changes in the
> way this is set up and if you use an older version
> odd things may happen.
> 
> In particular, you need to make sure the default.properties
> is the same version and that in your build.properties you
> have addGetByNameMethod set to true.
> 
> 
> > -----Original Message-----
> > From: Helge Weissig [mailto:helgew@grajagan.org]
> > Sent: Wednesday, April 12, 2006 12:53 PM
> > To: torque-user@db.apache.org
> > Subject: BaseMyTable.getFieldNames() replacement?
> > 
> > 
> > Hi,
> > 
> > 	the version of Torque I am upgrading from (too
> > embarrassed to tell)  
> > used to put a method getFieldNames() into the generated Base 
> > classes.  
> > I have re-written this as below to be generic, but to my chagrin,  
> > have come to find out a substantial difference in 
> behaviour: the old  
> > method would return a list of field names in the order that 
> > they were  
> > present in the schema.xml file. Unfortunately, we have relied 
> > on this  
> > order for our presentation layer, where we want the fields to 
> > be in a  
> > given order.
> > 
> > So here are my questions/comments:
> > 1) is there a better way to do this? For example, do I really
> > need to  
> > go through the BasePeer class (my table maps came up empty without  
> > that and try as I might, I only found other posts of people 
> likewise  
> > frustrated by this problem, but no solution that worked for me).
> > 2) more philosophically, in an MVC approach, should one avoid the  
> > assumption that was made here? In other words, should the  
> > presentation layer, in our case the Velocity template, 
> decide on the  
> > column sort order, rather than the data model layer (the 
> schema file)?
> > 
> > thanks for any input! I hope the code below may be useful to others!
> > 
> > cheers,
> > h.
> > 
> > 	// we are passed a table name and are supposed to return
> > 	// a sorted list of columns. This gets it done, except for the
> > 	// sorting part :(
> > 	public static List getFieldNames(String tableName) {
> > 		List l = new Vector();
> > 		String peerName = toPeerClassName(tableName);
> > 		tableName = camelCaseToUnderBars(tableName);
> > 		log.debug("returning field names for " + tableName);
> > 
> > 		DatabaseMap dbMap = null;
> > 
> > 		/*
> > 		 * We are using reflection to get the peer for
> > this table. From it, we
> > 		 * use the getMapBuilder method since 
> > Torque.getMapBuilder() does not
> > 		 * work in all cases (peers need to have been 
> > accessed at least  
> > once for
> > 		 * it to work)
> > 		 */
> > 		try {
> > 			Class peer = Class.forName(peerName);
> > 			Method m = 
> > peer.getMethod("getMapBuilder", (Class[]) null);
> > 			MapBuilder mBuilder = (MapBuilder) 
> > m.invoke(peer, (Object[]) null);
> > 			dbMap = mBuilder.getDatabaseMap();
> > 		} catch (ClassNotFoundException e1) {
> > 			log.error("cannot get peer class for " 
> > + peerName, e1);
> > 		} catch (SecurityException e) {
> > 			log.error("not allowed to get the
> > method getMapBuilder!", e);
> > 		} catch (NoSuchMethodException e) {
> > 			log.error(peerName + " does not define 
> > getMapBuilder", e);
> > 
> > 			// none of the next three should ever happen
> > 		} catch (IllegalArgumentException ignored) {
> > 		} catch (IllegalAccessException ignored) {
> > 		} catch (InvocationTargetException ignored) {
> > 
> > 			// this is really a TorqueException
> > thrown by getMapBuilder
> > 		} catch (Exception e) {
> > 			log.error("Cannot get a databse map for 
> > " + tableName, e);
> > 		}
> > 
> > 		log.debug("got db map " + dbMap.getName());
> > 
> > 		TableMap tableMap = null;
> > 		if (dbMap.containsTable(tableName)) {
> > 			tableMap = dbMap.getTable(tableName);
> > 		} else {
> > 			log.error("Table map for " + tableName
> > + " does not exist!");
> > 		}
> > 
> > 		ColumnMap[] cmap = tableMap.getColumns();
> > 
> > 		// field names look like java classes:
> > CapitalizedCamelWords
> > 		for (int i = 0; i < cmap.length; i++) {
> > 			String fname = 
> > cmap[i].getColumnName().toLowerCase();
> > 			fname = toJavaFieldName(fname);
> > 			fname = StringUtils.capitalize(fname);
> > 			l.add(fname);
> > 		}
> > 		return l;
> > 	}
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> > 
> > 
> 
> Duke CE 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