• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Bad eodelegate method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bad eodelegate method?


  • Subject: Bad eodelegate method?
  • From: Randy Wigginton <email@hidden>
  • Date: Tue, 11 Jul 2006 12:23:45 -0400


I am getting a very strange error when I use my own EODelegate.  For management reasons I am required to use MySQL.  The PK support for MySQL out of the box for EOF is not thread safe; I can get duplicate IDs.  Thus, I've created a very simple delegate, which looks like this:

public myEODelegate() {
EODatabaseContext.setDefaultDelegate(this);
}
private  static NSArray keys = new NSArray("pk");
public NSDictionary databaseContextNewPrimaryKey(EODatabaseContext dbCtxt, Object object, EOEntity entity) {
NSArray keyNames = entity.primaryKeyAttributeNames();
if (keyNames.size()!=1)
return null;
String pkName = (String)keyNames.get(0);
try {
EOEditingContext ec = new EOEditingContext();
NSArray rawRows = EOUtilities.rawRowsForSQL(ec, "testit",  "UPDATE EO_PK_TABLE SET pk=pk+1 where lower(name)='"+entity.externalName().toLowerCase()+"'");
rawRows = EOUtilities.rawRowsForSQL(ec, "testit",  "select pk from eo_pk_table where lower(name)='"+entity.externalName().toLowerCase()+"'", keys);
NSDictionary foo = (NSDictionary)rawRows.get(0);
Long bd = (Long)foo.valueForKey("pk");
return new NSDictionary(bd, pkName);
} catch (Exception e) { // Use default delegate
return null;
}
}

The problem is this.  I have a relationship, Owner and subguy.  Owner has a primary key; subguy is owned by Owner.  In the relationship, Owner propagates the primary key and owns the destination.  Here is some code that will always fail:
allDelegate = new myEODelegate(); // turn on my delegate

       

EOEditingContext ec = new EOEditingContext();
NSLog.allowDebugLoggingForGroups(0x10000L);
Owner own = (Owner)EOUtilities.createAndInsertInstance(ec,"owner");
Subguy gag = aag.sub();
gag.setGoogleID(new Integer(1001));
ec.saveChanges(); 
gag.setContentBid(new Double(1.01));
ec.saveChanges();

What is VERY strange is that if I delete the first saveChanges(), everything works.  With it there, I get an exception:
<main> A fatal exception occurred: cannot update primary-key 'adGroupID' from '13' to '13' on object:{values = {googleID = 1001; contentBid = 1.01;  adGroupID = 13; }; this = "<Subguy 8a3fe6 _EOIntegralKeyGlobalID[subguy (java.lang.Integer)13]>"; } of entity: subguy in databaseContext com.webobjects.eoaccess.EODatabaseContext@a08be5

If I do not use my delegate, everything works... but I'm back to the multithreading problem.

What am I missing?


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Bad eodelegate method?
      • From: Chuck Hill <email@hidden>
    • Re: Bad eodelegate method?
      • From: Guido Neitzer <email@hidden>
  • Prev by Date: Re: WWDC WO Meet
  • Next by Date: Re: Bad eodelegate method?
  • Previous by thread: Re: webobjects 5.3 and windows
  • Next by thread: Re: Bad eodelegate method?
  • Index(es):
    • Date
    • Thread