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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to