<?xml version="1.0"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-->

<document>

 <properties>
    <title>Torque Runtime Reference - Extending the Base Classes</title>
    <author email="fischer@seitenbau.de">Thomas Fischer</author>
    <author email="leon@opticode.co.za">Leon Messerschmidt</author>
    <author email="jvanzyl@periapt.com">Jason van Zyl</author>
    <author email="seade@backstagetech.com.au">Scott Eade</author>
 </properties>
 
 <body>
  <section name="Extending the Base Classes">
    <p>
      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&lt;table-name&gt;Peer and 
      Base&lt;table-name&gt; classes are overwritten each time you regenerate
      the classes from the schema and contain all functionality provided by 
      Torque.  
      The &lt;table-name&gt;Peer and &lt;table-name&gt; 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 &lt;table-name&gt;Peer and 
      &lt;table-name&gt; classes.
    </p>
  </section>
  
  
  <section name="Adding Methods to Peers">
 
    <p>
      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.
    </p>
  
    <p>
      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:
    </p>
 
<source><![CDATA[
public List doSelectByISBN(String isbn)
{
    Criteria crit = new Criteria();
    crit.add(BookPeer.ISBN, isbn);
    List books = BookPeer.doSelect(crit);
    return books;
}
]]></source>
    
  </section>
  
 </body>
</document>
