I'm about to complete a Torque tutorial (its an xdoc). It should be complete in a few days (hopefully tonight), then I'll post it to the list for comments. In the meantime, if anyone is interested, the draft can be found at:
http://www.kazmier.com/~kaz/torque/tutorial.html Thanks, Pete On Wed, Jan 23, 2002 at 08:10:35PM +0100, Martin Poeschl wrote: > would be nice if you could add your infoemation to the xdocs and send a patch ;-) > > also take a look at the testbed. it > > - generates the sql > - creates the db and tables > - creates the om/peer classes > - inserts some data to the db > - grabs the data from the db and generates data.xml and data.sql files > > you are right there should be better docs ... patches are very welcome ;-) > > martin > > > sbelt wrote: > > Let me start by saying that I am new to Torque as well. But I did get an > > application running (thanks in a large help to users on this list). Here > > would be my high-level view of how to use the classes. If anyone disagrees > > with me - believe THEM ;) > > > > Most of this is information I dug out of the site or the Mail Archives which > > was most useful to me. > > > > Suppose your schema.xml defined a table called Address (I'll leave it to > > your imagination to guess what fields would be in a table with this name;). > > You will find that Torque created files BaseAddressPeer, AddressPeer, > > BaseAddress, and Address. > > > > In your class constructor, add code which initializes torque if it is not > > already running. I used the following: > > // setup torque for database access and pooling > > try > > { > > if ( !Torque.isInit() ) > > { > > Torque.init("ndb.properties"); > > System.out.println( "[MyClass.constructor()] Torque.init completed > > successfully\n"); > > } > > else > > { > > System.out.println( "[MyClass.constructor()] Torque.init is already > > running\n"); > > } > > } > > catch( Exception e ) > > { > > System.out.println( "[MyClass.constructor()] error running > > Torque.init:\n" + e ); > > } > > > > Now all you need to do is instantiate the Address class, create criterias, > > and parse results. (This is off the top of my head, so consider it > > pseudo-code at best): > > > > Address address = new Address();// you now have a hook into all that Torque > > functionality > > Criteria criteria = new Criteria(); > > criteria.add(AddressPeer.LastName, "Jones");//LastName was a field defined > > in schema.xml > > Vector v = AddressPeer.doSelect( criteria ); // v contains a vector of > > address objects > > for (int x = 0; x<v.size; v++){ > > String firstName = ((Address)v.get(x)).getFirstName(); //FirstName is a > > field defined by schema.xml > > String lastName = ((Address)v.get(x)).getLastName(); //LastName is a > > field defined by schema.xml > > System.out.println(lastName +", "+ firstName); > > } > > > > If you need to start modifying the Torque code, here are some pointers: > > > > The Base* files you should never have to change. They are generated each > > time you run torque, and may change if, for example, you change databases. > > BTW, the when you re-run torque, unless you deleted them, the non-Base* > > files are not overwritten. > > > > I am new to this as well, but I have not had to modify any *Peer objects. I > > get the feeling that you could add methods to this file if you are sure they > > are not db dependent. > > > > Most effort will be in the Address class (in our example). When you look at > > this class as generated by Torque, it simply extends BaseAddress adding no > > methods of its own. I used this in my case to create selects from other > > tables to fetch field-values for this insert (does that make sense?). If I > > re-run Torqe for a new database - because only the Base* classes are > > replaced - my code should continue to function! > > > > I HTH. As I said, I am still learning myself. My experience so far has only > > been in using the Torque-generated stuff, so I know nothing of how Torque > > itself works. If you have any questions, I'll do my best to share any > > experince I might have in common. > > > > Steve B. > > ----- Original Message ----- > > From: "stewart titan" <[EMAIL PROTECTED]> > > To: "Turbine Users List" <[EMAIL PROTECTED]> > > Sent: Wednesday, January 23, 2002 5:37 AM > > Subject: Help with Torque > > > > > > > >> Hi > >> > >>(Apoloygise for the repost, but I forgot to change the > >>subject heading on my previous post) > >> > >> Are there an small example applications etc of how > >> to > >> use Torque? I'm able to generate the classes and > >> sql, > >> but how to use the classes - the peer classes and > >> "non > >> peer" classes, ie, > >> > >> There are two classes in which to put your own code > >> in: > >> project > >> ProjectPeer > >> > >> How do you use these? Ie, the code inside these > >> actually classes, the difference between the two, > >> and > >> how to use these classes in an application. > >> > >> I've read the docs, but still, no help, using the > >> criteria etc is fine, but there are missing examples > >> that I need to get going. So a sample application > >> would answer my questions. > >> > >> Help is very much appreciated. > >> > >> Thank You > >> > >> > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > -- Peter Kazmier http://www.kazmier.com PGP Fingerprint 4FE7 8DA3 D0B5 9CAA 69DC 7243 1855 BC2E 4B43 5654 -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
