Extending the Base Classes

Much of the power of Torque stems from the fact that you can easily add to and change the behaviour of the generated Peer and Data Object classes by adding or overriding methods. To keep your changes apart from the autogenerated code, Torque provides two Peer classes and two Data Object classes per table: The Base<table-name>Peer and Base<table-name> classes are overwritten each time you regenerate the classes from the schema and contain all functionality provided by Torque. The <table-name>Peer and <table-name> classes inherit from their respective Base Classes, but are empty initially. They are not overwritten if you regenerate the classes from the schema. All code which you add to the data model should go into the <table-name>Peer and <table-name> classes.

Adding Methods to Peers

Adding methods to Peers will be one of the most common things you will do while using Torque. For example, if you want to retrieve objects from the database without creating a Criteria objects, you would typically add a corresponding method to the Peer class.

As an example, consider the bookstore example from the Tutorial. If you often retrieve Books by their ISBN number, you would add the following method to the BookPeer class:

public List doSelectByISBN(String isbn)
{
    Criteria crit = new Criteria();
    crit.add(BookPeer.ISBN, isbn);
    List books = BookPeer.doSelect(crit);
    return books;
}