>although I haven't got a scoobie what language they're written in?

The templates are written in Velocity.  It seems like it should be hard to understand, 
but if you
sit a velocity template next to the generated output from the file, you'll see that 
Velocity
templates really only have like 5 rules.  Check out the user guide here
http://jakarta.apache.org/velocity/user-guide.html.

>I think it's such a time saver getting table objects ready generated.

I agree, completely. Of course the main reason that I started using it is so I can 
switch databases
easier.  Not having your code locked into a single vendors code was worth every minute 
of trying to
figure the system out.  It's nice being able to bring in code that can run on 
(usually) whatever
they got.

>Can you elaborate a wee bit more? What kind of code?

Sure thing!  The velocity templates are used by Torque to generate the java files like 
the Base and
Peer classes.  They do this by parsing the project-schema.xml file and pushing the 
data into a
Velocity context for retrieval.  (If you didn't follow that don't worry, I didn't 
either.)  The
important part is that this data (table names, field variables and the like) are all 
available to
you if you wanted to make your own template that used that information.

I am working on a Struts based webapp.  I noticed that I was writing about 12 
different files total
(Actions, Controllers and jsp's) per table in my database.  While it wasn't too bad, 
as my table
list got bigger and bigger I noticed I was writing code in way too many places.  It 
was much easier
to write a Velocity template for each of the 12 different cases and have Torque 
generate the (now)
80 or so files that I use.  I still have to write custom things like reports and 
helper classes, but
the majority of the data entry is generated now, including struts-config.xml.

For instance, here is my tiles-defs template (lines beginning with # are the Velocity 
commands, the
rest is straight xml)...


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
       "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd";>

<!--
     This is the tile definition for the project
-->

<tiles-definitions>
  <definition name="btp.defaultLayout" path="/layout/defaultLayout.jsp">
    <put name="header"  value="/tiles/common/header.jsp" />
    <put name="footer"  value="/tiles/common/footer.jsp" />
    <put name="navbar"  value="/tiles/common/navbar.jsp" />
    <put name="body"    value="" />
  </definition>

<!--
     Index tile layout
-->

  <definition name="btp.index" extends="btp.defaultLayout">
    <put name="body" value="/tiles/home.jsp" />
  </definition>


#foreach ($tbl in $database.Tables)
#if (!$tbl.getContainsForeignPK())
<!--
     ${tbl.getJavaName()} related tile layouts
-->

  <definition name="${package}.list${tbl.getJavaName()}" 
extends="${package}.defaultLayout">
    <put name="body" value="/tiles/list${tbl.getJavaName()}.jsp" />
  </definition>
  <definition name="${package}.view${tbl.getJavaName()}" 
extends="${package}.defaultLayout">
    <put name="body" value="/tiles/view${tbl.getJavaName()}.jsp" />
  </definition>
  <definition name="${package}.edit${tbl.getJavaName()}" 
extends="${package}.defaultLayout">
    <put name="body" value="/tiles/edit${tbl.getJavaName()}.jsp" />
  </definition>

#end
#end

</tiles-definitions>


Now if I add a table, I just regenerate the file after just changing the schema.  If I 
have a bug
somewhere I change it once and the fix propagates throughout the code.  It may seem 
like a bit of a
waste for this particular file, but now every single file that may change due to a 
change in the
schema is automatically updated.  Totally worth it!

-----Original Message-----
From: TES [mailto:[EMAIL PROTECTED]
Sent: Monday, April 19, 2004 11:50 AM
To: Apache Torque Users List
Subject: Re: Status of download and confusion with tutorial


Hello,


> Personally I love torque (of course asking the torque user list if Torque is a good 
> choice is like
> asking Crest stockholders which toothpaste is better).  It is extremely powerful 
> once you get to
> know it, but it does take quite a bit of time to get to know.  Less time than 
> learning JDBC I
think.

I agree. I am new to Java, but not new to databases and am now basing a
serious project on Torque. I think it's such a time saver getting table
objects ready generated. OK, you have to add your custom code but you
can think Java rather than having to delve into JDBC details.

And you can always look at the code to see what's happening. Even the
templates, although I haven't got a scoobie what language they're
written in?, are quite readable and it is easy enough to adapt them
should you need to do so.

As far as I can see the Torque runtime seems stable, which is the most
important thing.


>
> I've managed to get Torque to generate most of the code for my project; not just 
> JDBC stuff; so I

Can you elaborate a wee bit more? What kind of code? I'd be interested
to get a few ideas for future reference.

Regards,
Tarlika Elisabeth Schmitz


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to