db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <d...@solaraccess.com>
Subject Re: Foreign keys another great mystery... (longish w/ code)
Date Tue, 12 Aug 2003 18:59:27 GMT
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="dave@sa.com", lastLogin = awhileago)

matt = Author(firstName = "Matt", lastName = "Stoops", \
              email="matt@sa.com", 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


Mime
View raw message