• 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
Re: Feedback about issue with MySQL and get primary key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feedback about issue with MySQL and get primary key


  • Subject: Re: Feedback about issue with MySQL and get primary key
  • From: Ray Kiddy <email@hidden>
  • Date: Sun, 04 Sep 2011 16:08:42 -0700


Your rawRowsForSql call through an exception because you are completely bypassing the primary key generation process, so it you want to insert rows using this call, you need to generate the primary keys yourself.

There is a better way to do this. See below.

- ray

On Sep 4, 2011, at 7:49 AM, Philippe Rabier wrote:

Hi all,

Not a question but a feedback if you have the same issue but I don't have explanation and I didn't look for any.

Env: 
WO 5.4.3, java 6 on Mac OS X 10.6.7, Eclipse 3.4, Wonder a bit old (several months), MySQL v5.0.88

Context: 
DA where informations are checked, fetched then if everything is fine, informations are saved. At the end, we write into a log the request plus the result and some informations (IP address, …).

When informations are saved, I decided to use EOUtilities.rawRowsForSQL to execute an insert sql command in order to optimize the complete R-R.

Then I write into the log the request, result, … as I said.

If the insert command is executed, when the log is saved (through its editingContext), I got an exception when the adaptor tries to get a new primary key:

Sep 04 14:52:56 YNP_NOWebServicesApp[5000] DEBUG NSLog  - Searching for primary key value for NO_Sent_Notification_Request_Log_TEST
Sep 04 14:52:56 YNP_NOWebServicesApp[5000] DEBUG NSLog  -  evaluateExpression: <com.webobjects.jdbcadaptor._MySQLPlugIn$MySQLExpression: "SELECT PK FROM EO_PK_TABLE WHERE NAME = 'NO_Sent_Notification_Request_Log_TEST' FOR UPDATE" withBindings: >
Sep 04 14:52:56 YNP_NOWebServicesApp[5000] INFO  er.extensions.ERXAdaptorChannelDelegate.sqlLogging  - "Unknown"@795485135 _expression_ took 232 ms: SELECT PK FROM EO_PK_TABLE WHERE NAME = 'NO_Sent_Notification_Request_Log_TEST' FOR UPDATE
Sep 04 14:52:56 YNP_NOWebServicesApp[5000] DEBUG NSLog  - fetch canceled
Sep 04 14:52:56 YNP_NOWebServicesApp[5000] DEBUG NSLog  - 0 row(s) processed
Sep 04 14:52:56 YNP_NOWebServicesApp[5000] INFO  er.transaction.adaptor.Exceptions  - Database Exception occured: java.lang.IllegalArgumentException: Array is empty

If I replace EOUtilities.rawRowsForSQL  with ERXEOAccessUtilities.insertRow(ec, NOAppOpenedAfterPushEvent.Keys.ENTITY_NAME, dic), everything works great.

For those who were wondering why I wanted to use EOUtilities.rawRowsForSQL(), the reason is that I wanted to use "INSERT DELAYED INTO ".

Have a good sunday.

Philippe



I used to know how to do this using only WebObjects classes, but I cannot remember any longer. But this works with Wonder classes. There may be a better way to get to the EOAdaptorChannel.Delegate, but I always seem to re-find the chain one has to follow. You can get the EODatabaseContext at any point that you have an eo and use that to get the EOAdaptorChannel. Once you have them, you do not need to find them again. In the code below, the setDelegate methods end up getting called more often than they need to be, but since I am using singletons for the delegate instances, this is harmless. I ran this and verified, after turning on the EOAdaptorDebugEnabled flag, I get:

Sep 04 15:07:54 TreeFul[51162] DEBUG NSLog  -  evaluateExpression: <com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT DELAYED INTO c_tree_closure(down, up, distance) VALUES (?, ?, ?)" withBindings: 1:39(down), 2:39(up), 3:0(distance)>
eosqlexpression statement: INSERT DELAYED INTO c_tree_closure(down, up, distance) VALUES (?, ?, ?)
Sep 04 15:07:54 TreeFul[51162] DEBUG NSLog  -  evaluateExpression: <com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT DELAYED INTO c_tree_closure(down, up, distance) VALUES (?, ?, ?)" withBindings: 1:39(down), 2:1(up), 3:1(distance)>

So, it does work. Anyway, good luck.

cheers - ray


This is pulled from a Main.java:

public class Main extends ERXComponent {

public Main(WOContext context) {
super(context);
}

<snip>

public WOActionResults editStuff() {
<snip>
EOEnterpriseObject eo = EOUtilities.createAndInsertInstance(ec, "MyEntity");
EODatabaseContext dbc = ERXEOAccessUtilities.databaseContextForObject(pObj);
dbc.setDelegate(dbcd);
<snip>
}

static DBCDelegate dbcd = new DBCDelegate();
static ACDelegate acd = new ACDelegate();

public static class DBCDelegate {

public NSArray databaseContextWillPerformAdaptorOperations(
EODatabaseContext eodatabasecontext, 
NSArray nsarray, 
EOAdaptorChannel eoadaptorchannel) {
eoadaptorchannel.setDelegate(acd);
return nsarray;
}
}

public static class ACDelegate {

public boolean adaptorChannelShouldEvaluateExpression(
EOAdaptorChannel eoadaptorchannel, 
EOSQLExpression eosqlexpression) {

if (eosqlexpression.statement().startsWith("INSERT")) {
String sql = eosqlexpression.statement().replaceAll("INSERT", "INSERT DELAYED");
eosqlexpression.setStatement(sql);
}
return true;
}
}
}

- ray

 _______________________________________________
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: Feedback about issue with MySQL and get primary key
      • From: Philippe Rabier <email@hidden>
References: 
 >Feedback about issue with MySQL and get primary key (From: Philippe Rabier <email@hidden>)

  • Prev by Date: Feedback about issue with MySQL and get primary key
  • Next by Date: Re: building new D2W app and get a missing web.xml?
  • Previous by thread: Feedback about issue with MySQL and get primary key
  • Next by thread: Re: Feedback about issue with MySQL and get primary key
  • Index(es):
    • Date
    • Thread