db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: SetByName, SetByPeerName, SetByPostion support / Generic String to Column Object utility class.
Date Mon, 05 Jun 2006 21:48:05 GMT

> -----Original Message-----
> From: Thomas Fischer [mailto:tfischer@apache.org] 
> Greg, I like the first improvement and think it will improve Torque.

Kewl.. It's about ready to go except for packaging and testing against
the SVN repository head code.

> I have read the second improvement thrice now but still do 
> not understand what it does and what it is for. Can you 
> please enlighten us earth-bound spirits by giving some example ?
Don't you mean straighten out my confusing.. in a hurry to finish this 
... end of note verbage?  LOL

First, I think I need to revise the potential class / method 
signatures: ( FWIW: I'm still trying to find good name...)

public class ColumnValueConverter {

  public static parseColumnObject( ColumnMap cMap, String Value);

  public static toString( ColumnMap cMap, Object value );


Here's an example using my specific need for this.  (You guessed it)...
doing XML imports using the Torque generated DTD.  So, for example, I 
might have have records represented in XML like the ones below that 
need to be parsed and converted to a list of OM classes that my 
application can process.

<dataset name="default">
  <UserTable UserId="bob" Password="thePenguin" ClientId="101" 
     Expires="1 Jan 2007 00:00:00 EST" Rate="99.99" 
  <RolesTable UserId="bob" RoleId="student" CourseId="666"/>

Parsing the XML will get string representations of the Torque DB name,
e.g. default; Table Name(s), e.g. UserTable; Column names, e.g. UserId; 
and values, e.g. bob.  Converting these String values into an OM class
needs some XML Parser code (sans a lot of error checking) like:

public void startElement(....

    if ( rawname.equals("dataset") {
        String dbName = attributes.getValue("name"); 
        dbMap = Torque.getDatabase(dbName);
    } else {
       String table = rawName;
       TableMap tMap = dbMap.getTable(table);
       BaseObject record = tMap.getOMClass().newInstance();
       for ( int i=0; I < attributes.getLength(); i++)
         String columnName = attributes.getQName(i);
         String value = attributes.getValue(i);
// getColumnByJavaName searchs thru Columns[] to find match...
        ColumnMap cMap = getColumnByJavaName(columnName)

// *** Need to convert String to Column Appropriate object.
        Object oValue = 
            ColumnValueConverter.parseColumnObject(cMap, value);

        record.setByName(columnName, oValue);

Having a ColumnValueConverter class will centralize all the 
logic needed to convert between String data representations and 
column specific object types (e.g. Date, Boolean, Float, and the 

I have used an XML import example, but I can see it being used in
many different application needs.. e.g. Import/Export using Comma
Separated Values format or processing a web form request that needs
to return more than String values.  

Another possible use for it is to improve the way that default values
get set from the default XML schema attribute.  E.g., have you ever 
tried to define a default value for a Date field?  You have to use 
long integer milliseconds format to get it to work.  Not nice.

On the output side, having a central object that generates consistant
string representation of data is also useful.  E.g., always generating
true / false for booleans, or Numeric field strings with the right 
precision and scale, and the like.

In addition, I can see the need for dealing export and import of 
binary data (e.g., picture Blob of user).  This might be a good place
to have "safe string" encode/decode methods, e.g. Hex and/or base64
encoding support.

Well hopefully this is clearer and better stated.


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-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org

View raw message