Differences between revisions 5 and 6
Revision 5 as of 2005-03-22 05:43:39
Size: 10395
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 6 as of 2009-09-20 23:04:18
Size: 10392
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
'''Navigation trail:'''[wiki:TorqueProjectPages Torque] '''Navigation trail:'''[[TorqueProjectPages|Torque]]

Navigation trail:Torque


Getting Torque To Work

Although Torque is a great tool and remarkably effective once you get it going, many people have trouble setting it up. The documentation seems particularly weak in this area (possibly because there are so many different databases, drivers, and parameters to consider.)

This document is an attempt to help people figure out what's going wrong with their setup by listing the problems and solutions that other people have had.

PLEASE, PLEASE, PLEASE!! If you have had problems setting up Torque and solved them, add your experiences to the list. The more people who contribute, the better the document!


Installing release 3.1

  • Basic install of torque and testing of example included in the tutorial

  

  • Download torque-3.1.zip and torque-3.1.zip and torque-gen-3.1.zip

Extract the zips, you will now have <your_installation_path>/torque-3.1 folder and <your_installation_path>/torque-gen-3.1 folder

  • Merge the folders and files from one folder into another (so you now have everything under one folder)

Edit build.properties (3 changes primarily -- torque.project , torque.database and the database connection related setting.)

  • Create a project-schema.xml file under <your_installation_path>/schema folder (you can copy the example given in the tutorials)

  • from the <your_installation_path> execute ant as follows

    • ant -f build-torque.xml
    • ant -f build-torque.xml create-db
    • ant -f build-torque.xml id-table-init-sql
    • ant -f build-torque.xml insert-sql

FreeSoul


Getting Torque to generate the schema and object files

This is a listing of the typical problems people have trying to get Torque to generate their object files and schema files.

1. My problem was that I couldn't generate the java source code by running ant -f build-torque.xml. Everything else was working perfect, I got no error messages from Ant, sql code was generated and I could run that to generate my mysql database and tables and everything else. My mistake was that I wasn't setting the right name for my database schema xml file. If the project name in build.properties is "pitchers" ("torque.project = pitchers"), the schema xml file (in the schema folder) needs to be named as "pitchers-schema.xml" i.e in the format "project-schema.xml"

Might be a dumb mistake but that's what it was.

Vikas

Another note on this issue---I was working from a database to XML, and was confused by the fact that when a schema is generated by from an existing database it is called schema.xml rather than xxx-schema.xml. It took me ages to work out that i had to rename to schema.xml to xxx-schema.xml, but after I had the .java files were generated correctly. Maybe the solution to this confusion is to have turbine issue a helpful warning message when it finds schema.xml but not xxx-schema.xml?

StuartYeates

tbd

2. My problem turned out to be fairly simple to fix. When I was browsing the site I didn't find any references to what column types were allowed. I mistakenly put LONG and BOOLEAN in. This causes the build to fail without any information on what went wrong or where. After I changed my types to BIGINT and BIT everything worked correctly. Below I am including the available types that I have found.

BIT , TINYINT , SMALLINT , INTEGER , BIGINT , FLOAT , REAL , DOUBLE , NUMERIC , DECIMAL , CHAR , VARCHAR , LONGVARCHAR , DATE , TIME , TIMESTAMP , BINARY , VARBINARY , LONGVARBINARY , NULL , OTHER , JAVA_OBJECT , DISTINCT , STRUCT , ARRAY , BLOB , CLOB , REF

They were found in my src/java/report.project.om.generation file.

Hope this helps

-pete


Data types from the DTD

The above list is missing BOOLEANINT and BOOLEANCHAR according to the DTD.

Dave

another hint

if you get an error like:

[torque-sql] Couldn't read DTD specified in XML schema: db.apache.org [torque-sql] java.net.MalformedURLException

check in your conf files the Doctypes. <!DOCTYPE database SYSTEM "http://jakarta.apache.org/turbine/dtd/database.dtd">

knex


Getting a Torque application to run from the command line

This is a listing of the typical problems people have trying to get their first Torque Application to run.

When you're using ant 1.4.1 you'll have this error when trying to execute jdbc ant task.

{{{ Error "Could not create task of type: torque-jdbc-transform"

  • ant -f build-torque.xml jdbc Buildfile: build-torque.xml jdbc:
    • ["echo"] +


+

  • ["echo"] | | ["echo"] | Generating XML from JDBC connection ! | ["echo"] | Woo hoo! | ["echo"] | |

    ["echo"] +


+

  • BUILD FAILED
  • .../build-torque.xml:351: Could not create task of type: torque-jdbc-transform

    due to java.lang.VerifyError: (class: org/apache/torque/task/TorqueJDBCTransformTask, method: generateXML signature: ()V) Incompatible object argument for function call Total time: 1 second }}}

Typical eror when using torque with Ant 1.4.1. You need Ant 1.5.1 to use torque.

tbd


Getting Torque to run within a web-server

This section deals with the trials and tribulations of getting your web-applications Torque-enabled.

There are several steps to help check that Torque is setup correctly with your web-application, before you start testing Criteria, Peers, etc.

  1. Make sure that you can run the Torque sample applications from the command line. MANY PEOPLE FAIL THIS STEP.

    • If you fail this step, you need to review the item on getting Torque to run on the command line. (Usually, there's a problem in the Torque.properties file, or libraries are missing, or something.)
  2. Write a very simple JSP file that contains a small scriplet that prints the results of "Torque.isInit()" Make sure it's true.
    • If this step fails, you need to check a number of things:
      • Make sure you are initializing Torque - many people make a TorqueInitServlet and call Torque.init() when the Servlet starts.

      • Make sure the webserver can find the Torque.properties file. Usually this means specify an absolute path to the file Because of the way many webservers start up, you can't guarantee what the starting directory is for the webserver. Thus, local paths to the file often fail.

      • Make sure that you've included your database driver in the WEB-INF/lib directory.
      • Make sure that you've included the appropriate Torque libraries in the WEB-INF/lib directory.


Getting Torque to run within a Junit test

This section deals with the trials and tribulations of getting your unit tests to work with Torque.

I have a base TorqueTestCase that I extend all of my test cases that use torque. I use this for any junit based tests I run. Although I have found that running Cactus style in-container tests works better for me over the long run where the container starts Torque up, but this will help you write tests if you are not in a webapp:

  1. Create a class looking like this:

{{{ public class TorqueTestCase extends TestCase {

  • public final static String TORQUE_PROPS = new String( "c:/fortius/src/test/conf/Torque.properties" );

    private static Category log = Category.getInstance( BaseTestCase.class.getName() );

  • /**

    public TorqueTestCase ( String name ) {

    • super( name ); if ( !Torque.isInit() ) {
      • log.debug( "Now starting Torque with path:" + TORQUE_PROPS ); try {
        • Torque.init( TORQUE_PROPS );
        }

        catch ( org.apache.torque.TorqueException te ) {

        • log.error( "Could not start Torque!" ); fail( te.toString() );
        }
      } }}}

}

  1. Now, admittedly the torque.props is hardcoded, but this should get you started. Just make sure all your constructors do call the <code>super( name)<code> method!

- EricPugh


Using Torque with multiple databases

This section deals with the trials and tribulations of using multiple databases with Torque.

It's fairly easy to get multiple databases working. The following examples assume you are using JNDI, since it's what I know best, but the differences are restricted to the torque.properties file. Start off by choosing a handle name for each of the databases to which you will connect. In this example there will be two databases, with handles dbA and dbB. Do the following:

  1. In the schema file for dbA, the <database> element must have a name attribute with value dbA. Likewise for the dbB schema file. When the object model files are generated (by ant -f build.properties om), the name will be hard-coded in them, and cannot be overriden.

  2. In the torque.properties file, create an adapter for each of your databases:
    torque.database.dbA.adapter=mysql
    torque.dsfactory.dbA.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
    torque.dsfactory.dbA.jndi.path=java:comp/env/jdbc/dbA
    
    torque.database.dbB.adapter=mysql
    torque.dsfactory.dbB.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
    torque.dsfactory.dbB.jndi.path=java:comp/env/jdbc/dbB
    [Note: your JNDI path may be different!]

    The key point here is the handle, emphasized in torque.database.dbA.adapter=mysql. The torque.properties file handles and the handles in the schema files must correspond. This is the a fundamental issue with getting multiple databases working with Torque.

  3. Every use of the database in the code must reference a handle [this is a simplification, there is a default handle, and rules for automatic creation of a default handle, but... let's not go there]. Here is an example:

      Criteria criteria = new Criteria("dbA");
      criteria.add(SomePeer.SOME_FIELD, "some value");
      SomePeer.doDelete(criteria);
    -- Gary Shea

TorqueProjectPages/GettingTorqueToWork (last edited 2009-09-20 23:04:18 by localhost)