commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick.Grim...@xtl.com
Subject Re: Scripting Suggestion?
Date Wed, 10 Sep 2008 14:16:51 GMT
I figured out an alternative.  Primarily, all source data needs to get truncated
to fit the target columns.  The only source data I might need to do something
tricky with appears to be java.sql.Timestamp values.  One particular column in
my target table that is a String data type that holds a date value wants to see
the dates as YYYY-MM-DD-HH-MM-SS.  So when I'm getting values from my source
data ResultSet, rather than just using the getString() method, I'm using the
getObject() method instead.

Doing it that way, I'm able to test the returned Object to see what class it's
an instance of.  This allows me to convert the data to a string and do any other
conversions that are specific to the source data type.  In the case of my date
above, I'm replacing the " " (space) character between the data and time with a
"-" (dash) and dropping the nanos.  That gives me the converted value I need.
So no fancy scripting needed in my XML.
(Embedded image moved to file: pic04107.jpg)



                                                                                
             Patrick.Grimard@xtl                                                
             .com                                                               
                                                                             To 
             09/10/2008 07:41 AM         "Commons Users List"                   
                                         <user@commons.apache.org>              
                                                                             cc 
              Please respond to                                                 
               "Commons Users                                           Subject 
                    List"                Re: Scripting Suggestion?              
             <user@commons.apach                                                
                   e.org>                                                       
                                                                                
                                                                                
                                                                                
                                                                                




To add to this, some source fields I may not want to substring from index=0.  I
may want to substring from the middle of the source value.
(Embedded image moved to file: pic22704.jpg)




             Patrick.Grimard@xtl
             .com
                                                                             To
             09/10/2008 07:38 AM         user@commons.apache.org
                                                                             cc

              Please respond to                                         Subject
               "Commons Users            Scripting Suggestion?
                    List"
             <user@commons.apach
                   e.org>








Yesterday I successfully implemented my first digester class and it works great,
just like I would want it to.  Now I need to take my XML file a step further by
including some form of scripting.  My XML file is basically used to map tables
and fields between 2 datasources so that my java process can pull from one and
dump to the other.  The issue however is that the columns in the target
datasource are all string columns and my source data columns aren't always
string columns and are sometimes also longer in length than the target columns.
My process will have logic to determine the source datatype and convert it to a
proper string, I just don't want to create methods for each field that might
need to be substringed before inserting into the target datasource because I
want the java process to be independent of the actual data it's processing,
hence the XML file.  It's not enough to say I can just check the length of the
target column and substring the source accordingly, because the result might not
be what I want, ie: a boolean won't automatically convert to Y or N which my
target datasource wants.  Does anybody have any suggestions?  Thanks in advance.

Here's a sample of what my XML file might look like:

<harvester>
      <datasources>
            <datasource>
                  <name>source</name>
                  <driver>some.driver</driver>
                  <url>the.url</url>
                  <username></username>
                  <password></password>
            </datasource>
            <datasource>
                  <name>destination</name>
                  <driver>some.driver</driver>
                  <url>the.url</url>
                  <username></username>
                  <password></password>
            </datasource>
      </datasources>

      <tables>
            <table>
                  <sourceTable>tableName</sourceTable>
                  <destTable>tableName</destTable>
                  <fields>
                        <field>
                              <sourceField>fieldName</sourceField>
                              <destField>fieldName</destField>
                              <transformSource>
                                    <!-- would like some kind of script here
to
say how to convert/trim the source value
-->
                              </transformSource>
                        </field>
                        <field>
                              <sourceField>fieldName</sourceField>
                              <destField>fieldName</destField>
                        </field>
                        <field>
                              <sourceField>fieldName</sourceField>
                              <destField>fieldName</destField>
                        </field>
                  </fields>
            </table>
      </tables>
</harvester>
(Embedded image moved to file: pic15141.jpg)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org

Mime
View raw message