Just curious how do you deal with editingContext.saveChanges() with
lots of EO inserted? Um, I don't think 150,000 should be a big deal in
21 century.

After trying to solve this in the other ways, I decided to just write stored procedure and avoid EO's altogether during the long insert operation.

The stored procedure must be EO_PK_TABLE-aware and then call refreshAllObjects() on the editing context once it was finished to make everything reload.


Calling the stored procedure:

EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(editingContext(), "MyModel");
EOAdaptorChannel channel = dbc.availableChannel().adaptorChannel();
String sql = "CALL InsertObjects()";
ERXJDBCUtilities.executeUpdateScript(channel, sql);
editingContext().refreshAllObjects();


A rough outline of the EO_PK_TABLE-aware stored procedure for MySQL is here:

CREATE PROCEDURE InsertObjects ()
BEGIN
  DECLARE done BOOLEAN DEFAULT FALSE;
  DECLARE good BOOLEAN DEFAULT FALSE;
  DECLARE var_object_id INTEGER;
  DECLARE curs CURSOR FOR
  SELECT
    source_objects.id AS object_id FROM SourceObjects
  WHERE
    conditions to select objects;
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
  OPEN curs;
  fetch_loop: LOOP
    IF done THEN LEAVE fetch_loop; END IF;
    FETCH curs INTO var_object_id;
    SELECT @var_old_pk := PK FROM EO_PK_TABLE WHERE NAME = 'Objects';
    SELECT @var_new_pk := @var_old_pk + 1;
    SET good = FALSE;
    REPEAT
UPDATE EO_PK_TABLE SET PK = @var_new_pk WHERE NAME = 'Objects' AND PK = @var_old_pk;
      IF ROW_COUNT() = 1 THEN
INSERT INTO Objects (id, object_id, more...) VALUES (@var_new_pk, var_object_id);
        SET good = TRUE;
      END IF;
    UNTIL good END REPEAT;
  END LOOP fetch_loop;
  CLOSE curs;
END;

P.S. Looks like there is a bug in my procedure... needs to increment var_new_pk inside the inner repeat loop. But you get the idea...

_______________________________________________
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