On Tue, 2003-08-12 at 13:50, Mark Lowe wrote:
> Thanks.. for pointing me to the docs, they're great aren't they i've 
> been reading them for days, its just a shame that as soon as you try 
> anything useful they don't seem to be right.. 

Yeah, Jakarta documentation often leaves much to be desired. That's a
pain in the ass and wastes a lot of time. *sigh* OTOH, it's free :D

> Tell you what i'll even give you 
> back the pics I've got of you and your ma.

Even if that was meant as a joke it's pretty rude.

> So come on then Dave show me how stupid I am

Redundancy sucks. You'll do fine.

> The api gives me a setApplicant(Applicant v) method which is great.. 
> Despite the fact it doesn't work.. Now I don't mind the fact this 
> doesn't work, just that all these little not worky things seem to be a 
> tad esoteric and not mentioned in the docs.. Variations of this have be 
> trying the addApplication(Application v) in the applicant api, but alas 
> no.

What do you mean by "doesn't work?" Do you get an exception or does it
appear as though nothing at all is happening?

Here's a simple schema file and some Jython code that works fine. I use
Jython features, but it's mostly syntactic sugar around getters/setters.

--- schema snippet ---

  <table name="publisher" description="Publisher Table">
    <column name="publisher_id" required="true" type="INTEGER" [...]/>
    <!-- etc. -->
  </table>

  <table name="author" description="Author Table">
    <column name="author_id" required="true" type="INTEGER" [...]/>
    <!-- etc. -->
  </table>

  <table name="book" description="Book Table">
    <column name="book_id" required="true" type="INTEGER" [...]/>
    <!-- etc. -->
    <foreign-key foreignTable="publisher">
      <reference local="publisher_id" foreign="publisher_id"/>
    </foreign-key>
    <foreign-key foreignTable="author">
      <reference local="author_id" foreign="author_id"/>
    </foreign-key>
  </table>

--- jython snippet ---

#
# _MY_ question: What's a good way to delete all objects from
#                a table w/o knowing table structure or writing
#                SQL or modifying the templates?
#

# Blechy code to delete all from the publisher table
allpub = Crit().add(PubPeer.NAME, "%", Crit.LIKE)
PubPeer.doDelete(allpub)

# Add publishers
addison = Pub(name = "Addison Wesley Professional")
oreilly = Pub(name = "O'Reilly")
addison.save()
oreilly.save()

# Add authors
dave = Author(firstName = "Dave", lastName = "Newton", \
              email="[EMAIL PROTECTED]", lastLogin = awhileago)

matt = Author(firstName = "Matt", lastName = "Stoops", \
              email="[EMAIL PROTECTED]", lastLogin = lastlogin)

dave.save()
matt.save()

# Add books
b1 = Book(title="Struts for Dave", ISBN="", pages=666, \
          publisher=addison, author=matt)
b2 = Book(title="JDBC does MySQL", ISBN="", pages=300, \
          publisher=oreilly ,author=matt)
b3 = Book(title="Extreme Programming", ISBN="", pages=666, \
          publisher=addison ,author=dave)
b4 = Book(title="Jython Cookbook", ISBN="", pages=300, \
          publisher=addison ,author=dave)
b5 = Book(title="Physical Security", ISBN="", pages=500, \
          publisher=oreilly ,author=dave)
books = [b1, b2, b3, b4, b5]
for book in books:
    book.save()

--- end snippets --

I've done a few other mappings with Torque and have Jython code for
most; I can send it to you if necessary (once I find it--switching
machines/states/etc.)

Dave

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_1.dtd";>

<database name="emailtool" defaultIdMethod="idbroker">

  <table name="book" description="Book Table">
    <column
      name="book_id"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="Book Id"/>
    <column
      name="title"
      required="true"
      type="VARCHAR"
      size="255"
      description="Book Title"/>
    <column
      name="isbn"
      required="true"
      type="VARCHAR"
      size="24"
      javaName="ISBN"
      description="ISBN Number"/>
    <column
      name="pages"
      required="true"
      type="INTEGER"
      description="Number of pages in book"/>
    <column
      name="publisher_id"
      required="true"
      type="INTEGER"
      description="Foreign Key Publisher"/>
    <column
      name="author_id"
      required="true"
      type="INTEGER"
      description="Foreign Key Author"/>
    <foreign-key foreignTable="publisher">
      <reference
        local="publisher_id"
        foreign="publisher_id"/>
    </foreign-key>
    <foreign-key foreignTable="author">
      <reference
        local="author_id"
        foreign="author_id"/>
    </foreign-key>
  </table>

  <table name="publisher" description="Publisher Table">
    <column
      name="publisher_id"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="Publisher Id"/>
    <column
      name="name"
      required="true"
      type="VARCHAR"
      size="128"
      default=""
      description="Publisher Name"/>
  </table>

  <table name="author" description="Author Table">
    <column
      name="author_id"
      required="true"
      primaryKey="true"
      type="INTEGER"
      description="Author Id"/>
    <column
      name="first_name"
      required="true"
      type="VARCHAR"
      size="128"
      default=""
      description="First Name"/>
    <column
      name="last_name"
      required="true"
      type="VARCHAR"
      size="128"
      default=""
      description="Last Name"/>
    <column
      name="email"
      required="true"
      type="VARCHAR"
      size="128"
      default=""
      description="Email Address"/>
    <column
      name="last_login"
      required="false"
      type="TIMESTAMP"
      description="Author's last login date"/>
  </table>
</database>

Attachment: populate.py
Description: application/python

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

Reply via email to