Hi,

I have several cases where I want to retrieve an om object by a unique value.
Therefore I have to insert new methods in the Peer-Classes. 

Here is an example:

the entry in the schema-xml-file: 

<table 
        name="TEAM" 
        idMethod="idbroker">
....
        <column 
                name="NAME" 
                size="80" 
                type="VARCHAR"/>
        <unique>
                <unique-column 
                        name="NAME"/>
        </unique>        

</table>


and the method in TeamPeer.java:


        /**
         * retrieves a team by it's name 
         *
         * @param       name
         *              name of the team
         *
         * @return      Team with the given name or null, if such a Team
         *                      does not exist
         *
         * @throws      Exception
         *              exception
         */
        public static Team getByName( String name )
                throws Exception
        {
                
                /*
                 * generate criteria
                 */
                Criteria c = new Criteria();
                
                c.add( NAME , name );
                
                /*
                 * retrieve elements
                 */
                List l = doSelect( c );
                
                /*
                 * check vector size & return result
                 */
                if ( l.size() > 0 )
                {
                        return (Team) l.get( 0 );
                }
                else
                {
                        return null;
                }
        
        }


Wouldn't it be neat to autogenerate these methods with torque?


Lars Grammel

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

Reply via email to