svn commit: r582142 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/survey/ applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/product/inventory/ applications/securityext/src/org/ofbiz/securityext/cert...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r582142 - in /ofbiz/trunk: applications/content/src/org/ofbiz/content/survey/ applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/product/inventory/ applications/securityext/src/org/ofbiz/securityext/cert...

jonesde
Author: jonesde
Date: Fri Oct  5 02:02:49 2007
New Revision: 582142

URL: http://svn.apache.org/viewvc?rev=582142&view=rev
Log:
Some improvements to how sequencing is done, including a new method in the GenericDelegator that does a sequence and create all in one, including a single retry with bank refresh on failure because of duplicate ID just in case two sequencers somehow get the same ID bank; in theory that is impossible but it has been observed in production and this is part of the 2 part solution to handle the problem more elegantly than having to restart the servers, and to try to find out just how two sequencers got the same bank of values; this includes changing a number of key code blocks to use the combined sequence and create for retry, and a little bit of code cleanup too

Modified:
    ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java
    ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/cert/CertificateServices.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceRule.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/survey/PdfSurveyServices.java Fri Oct  5 02:02:49 2007
@@ -93,12 +93,12 @@
             GenericValue survey = null;
             surveyId = (String) context.get("surveyId");
             if (UtilValidate.isEmpty(surveyId)) {
-                surveyId = delegator.getNextSeqId("Survey");
                 survey = delegator.makeValue("Survey", UtilMisc.toMap("surveyName", surveyName));
                 survey.set("surveyId", surveyId);
                 survey.set("allowMultiple", "Y");
                 survey.set("allowUpdate", "Y");
-                survey.create();
+                survey = delegator.createSetNextSeqId(survey);
+                surveyId = survey.getString("surveyId");
             }
             
             // create a SurveyQuestionCategory to put the questions in

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Fri Oct  5 02:02:49 2007
@@ -1093,7 +1093,6 @@
                 throw new GeneralException("Problem getting parsed currency amount from DecimalFormat", e);
             }
             GenericValue newPref = delegator.makeValue("OrderPaymentPreference", null);
-            newPref.set("orderPaymentPreferenceId", delegator.getNextSeqId("OrderPaymentPreference"));
             newPref.set("orderId", orderId);
             newPref.set("paymentMethodTypeId", "CASH");
             newPref.set("statusId", "PAYMENT_RECEIVED");
@@ -1102,7 +1101,7 @@
             if (userLogin != null) {
                 newPref.set("createdByUserLogin", userLogin.getString("userLoginId"));
             }
-            delegator.create(newPref);
+            delegator.createSetNextSeqId(newPref);
         }
     }
 

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java Fri Oct  5 02:02:49 2007
@@ -110,15 +110,7 @@
                     newItem.set("availableToPromiseTotal", new Double(0));
                     newItem.set("quantityOnHandTotal", new Double(0));
                     
-                    String newSeqId = null;
-                    try {
-                        newSeqId = delegator.getNextSeqId("InventoryItem");
-                    } catch (IllegalArgumentException e) {
-                        return ServiceUtil.returnError("ERROR: Could not get next sequence id for InventoryItem, cannot create item.");
-                    }
-                    
-                    newItem.set("inventoryItemId", newSeqId);
-                    newItem.create();
+                    delegator.createSetNextSeqId(newItem);
                     
                     results.put("inventoryItemId", newItem.get("inventoryItemId"));
     

Modified: ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/cert/CertificateServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/cert/CertificateServices.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/cert/CertificateServices.java (original)
+++ ofbiz/trunk/applications/securityext/src/org/ofbiz/securityext/cert/CertificateServices.java Fri Oct  5 02:02:49 2007
@@ -84,7 +84,6 @@
         Map x500Map = KeyStoreUtil.getCertX500Map(cert);      
         if (importIssuer != null && "Y".equalsIgnoreCase(importIssuer)) {
             GenericValue provision = delegator.makeValue("X509IssuerProvision", null);
-            provision.set("certProvisionId", delegator.getNextSeqId("X509IssuerProvision"));
             provision.set("commonName", x500Map.get("CN"));
             provision.set("organizationalUnit", x500Map.get("OU"));
             provision.set("organizationName", x500Map.get("O"));
@@ -94,7 +93,7 @@
             provision.set("serialNumber", cert.getSerialNumber().toString(16));
 
             try {
-                delegator.create(provision);
+                delegator.createSetNextSeqId(provision);
             } catch (GenericEntityException e) {
                 return ServiceUtil.returnError(e.getMessage());
             }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Fri Oct  5 02:02:49 2007
@@ -511,6 +511,89 @@
         return this.create(value, true);
     }
 
+    /** Sets the sequenced ID (for entity with one primary key field ONLY), and then does a create in the database
+     * as normal. The reason to do it this way is that it will retry and fix the sequence if somehow the sequencer
+     * is in a bad state and returning a value that already exists.
+     *@param value The GenericValue to create a value in the datasource from
+     *@return GenericValue instance containing the new instance
+     */
+    public GenericValue createSetNextSeqId(GenericValue value) throws GenericEntityException {
+        boolean doCacheClear = true;
+        
+        GenericHelper helper = getEntityHelper(value.getEntityName());
+        // just make sure it is this delegator...
+        value.setDelegator(this);
+        // this will throw an IllegalArgumentException if the entity for the value does not have one pk field, or if it already has a value set for the one pk field
+        value.setNextSeqId();
+        
+        boolean beganTransaction = false;
+        try {
+            if (alwaysUseTransaction) {
+                beganTransaction = TransactionUtil.begin();
+            }
+
+            Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName());
+            this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_CREATE, value, ecaEventMap, (ecaEventMap == null), false);
+
+            if (value == null) {
+                throw new GenericEntityException("Cannot create a null value");
+            }
+
+            this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_CREATE, value, ecaEventMap, (ecaEventMap == null), false);
+
+            value.setDelegator(this);
+            this.encryptFields(value);
+            try {
+                value = helper.create(value);
+            } catch (GenericEntityException e) {
+                // see if this was caused by an existing record before resetting the sequencer and trying again
+                // NOTE: use the helper directly so ECA rules, etc won't be run
+                GenericValue existingValue = helper.findByPrimaryKey(value.getPrimaryKey());
+                if (existingValue == null) {
+                    throw e;
+                } else {
+                    Debug.logInfo("Error creating entity record with a sequenced value [" + value.getPrimaryKey() + "], trying again about to refresh bank for entity [" + value.getEntityName() + "]", module);
+                    
+                    // found an existing value... was probably a duplicate key, so clean things up and try again
+                    this.sequencer.forceBankRefresh(value.getEntityName(), 1);
+                    
+                    value.setNextSeqId();
+                    value = helper.create(value);
+                    Debug.logInfo("Successfully created new entity record on retry with a sequenced value [" + value.getPrimaryKey() + "], after getting refreshed bank for entity [" + value.getEntityName() + "]", module);
+                }
+            }
+
+            if (value != null) {
+                value.setDelegator(this);
+                if (value.lockEnabled()) {
+                    refresh(value, doCacheClear);
+                } else {
+                    if (doCacheClear) {
+                        this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_CREATE, value, ecaEventMap, (ecaEventMap == null), false);
+                        this.clearCacheLine(value);
+                    }
+                }
+            }
+
+            this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_CREATE, value, ecaEventMap, (ecaEventMap == null), false);
+            return value;
+        } catch (GenericEntityException e) {
+            String errMsg = "Failure in create operation for entity [" + value.getEntityName() + "]: " + e.toString() + ". Rolling back transaction.";
+            Debug.logError(e, errMsg, module);
+            try {
+                // only rollback the transaction if we started one...
+                TransactionUtil.rollback(beganTransaction, errMsg, e);
+            } catch (GenericEntityException e2) {
+                Debug.logError(e2, "[GenericDelegator] Could not rollback transaction: " + e2.toString(), module);
+            }
+            // after rolling back, rethrow the exception
+            throw e;
+        } finally {
+            // only commit the transaction if we started one... this will throw an exception if it fails
+            TransactionUtil.commit(beganTransaction);
+        }
+    }
+
     /** Creates a Entity in the form of a GenericValue and write it to the datasource
      *@param value The GenericValue to create a value in the datasource from
      *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation
@@ -640,9 +723,8 @@
 
         if (serializedPK != null) {
             GenericValue entitySyncRemove = this.makeValue("EntitySyncRemove", null);
-            entitySyncRemove.set("entitySyncRemoveId", this.getNextSeqId("EntitySyncRemove"));
             entitySyncRemove.set("primaryKeyRemoved", serializedPK);
-            entitySyncRemove.create();
+            this.createSetNextSeqId(entitySyncRemove);
         }
     }
 

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Fri Oct  5 02:02:49 2007
@@ -24,6 +24,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
@@ -513,6 +514,21 @@
      */
     public void setBytes(String name, byte[] bytes) {
         this.set(name, new ByteWrapper(bytes));
+    }
+    
+    public void setNextSeqId() {
+        List pkFieldNameList = this.modelEntity.getPkFieldNames();
+        if (pkFieldNameList.size() != 1) {
+            throw new IllegalArgumentException("Cannot setNextSeqId for entity [" + this.getEntityName() + "] that does not have a single primary key field, instead has [" + pkFieldNameList.size() + "]");
+        }
+        
+        String pkFieldName = (String) pkFieldNameList.get(0);
+        if (this.get(pkFieldName) != null) {
+            // don't throw exception, too much of a pain and usually intended: throw new IllegalArgumentException("Cannot setNextSeqId, pk field [" + pkFieldName + "] of entity [" + this.getEntityName() + "] already has a value [" + this.get(pkFieldName) + "]");
+        }
+        
+        String sequencedValue = this.getDelegator().getNextSeqId(this.getEntityName());
+        this.set(pkFieldName, sequencedValue);
     }
 
     public Boolean getBoolean(String name) {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Fri Oct  5 02:02:49 2007
@@ -179,7 +179,7 @@
                 int status = ut.getStatus();
                 Debug.logVerbose("[TransactionUtil.commit] current status : " + getTransactionStateString(status), module);
 
-                if (status != STATUS_NO_TRANSACTION) {
+                if (status != STATUS_NO_TRANSACTION && status != STATUS_COMMITTING && status != STATUS_COMMITTED && status != STATUS_ROLLING_BACK && status != STATUS_ROLLEDBACK) {
                     ut.commit();
 
                     // clear out the stamps to keep it clean
@@ -190,7 +190,7 @@
 
                     Debug.logVerbose("[TransactionUtil.commit] transaction committed", module);
                 } else {
-                    Debug.logWarning("[TransactionUtil.commit] Not committing transaction, status is STATUS_NO_TRANSACTION", module);
+                    Debug.logWarning("[TransactionUtil.commit] Not committing transaction, status is " + getStatusString(), module);
                 }
             } catch (RollbackException e) {
                 RollbackOnlyCause rollbackOnlyCause = getSetRollbackOnlyCause();

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/SequenceUtil.java Fri Oct  5 02:02:49 2007
@@ -76,6 +76,21 @@
     }
 
     public Long getNextSeqId(String seqName, long staggerMax, ModelEntity seqModelEntity) {
+        SequenceBank bank = this.getBank(seqName, seqModelEntity);
+        return bank.getNextSeqId(staggerMax);
+    }
+    
+    public void forceBankRefresh(String seqName, long staggerMax) {
+        // don't use the get method because we don't want to create if it fails
+        SequenceBank bank = (SequenceBank) sequences.get(seqName);
+        if (bank == null) {
+            return;
+        }
+        
+        bank.refresh(staggerMax);
+    }
+    
+    private SequenceBank getBank(String seqName, ModelEntity seqModelEntity) {
         SequenceBank bank = (SequenceBank) sequences.get(seqName);
 
         if (bank == null) {
@@ -87,11 +102,11 @@
                 }
             }
         }
-        return bank.getNextSeqId(staggerMax);
+        
+        return bank;
     }
 
     class SequenceBank {
-
         public static final long defaultBankSize = 10;
         public static final long maxBankSize = 5000;
         public static final long startSeqId = 10000;
@@ -126,7 +141,7 @@
                 curSeqId += stagger;
                 return retSeqId;
             } else {
-                fillBank(stagger, seqModelEntity);
+                fillBank(stagger, this.seqModelEntity);
                 if ((curSeqId + stagger) <= maxSeqId) {
                     Long retSeqId = new Long(curSeqId);
                     curSeqId += stagger;
@@ -136,6 +151,11 @@
                     return null;
                 }
             }
+        }
+        
+        public void refresh(long staggerMax) {
+            this.curSeqId = this.maxSeqId;
+            this.fillBank(staggerMax, this.seqModelEntity);
         }
 
         protected synchronized void fillBank(long stagger, ModelEntity seqModelEntity) {

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java Fri Oct  5 02:02:49 2007
@@ -296,12 +296,11 @@
         try {
             RecurrenceRule r = RecurrenceRule.makeRule(delegator, frequency, interval, count, endTime);
             String ruleId = r.primaryKey();
-            String infoId = delegator.getNextSeqId("RecurrenceInfo");
-            GenericValue value = delegator.makeValue("RecurrenceInfo", UtilMisc.toMap("recurrenceInfoId", infoId));
+            GenericValue value = delegator.makeValue("RecurrenceInfo", null);
 
             value.set("recurrenceRuleId", ruleId);
             value.set("startDateTime", new java.sql.Timestamp(startTime));
-            delegator.create(value);
+            delegator.createSetNextSeqId(value);
             RecurrenceInfo newInfo = new RecurrenceInfo(value);
 
             return newInfo;

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceRule.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceRule.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceRule.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceRule.java Fri Oct  5 02:02:49 2007
@@ -653,8 +653,7 @@
         String freqStr = freq[frequency];
 
         try {
-            String ruleId = delegator.getNextSeqId("RecurrenceRule");
-            GenericValue value = delegator.makeValue("RecurrenceRule", UtilMisc.toMap("recurrenceRuleId", ruleId));
+            GenericValue value = delegator.makeValue("RecurrenceRule", null);
 
             value.set("frequency", freqStr);
             value.set("intervalNumber", new Long(interval));
@@ -662,9 +661,8 @@
             if (endTime > 0) {
                 value.set("untilDateTime", new java.sql.Timestamp(endTime));
             }
-            delegator.create(value);
+            delegator.createSetNextSeqId(value);
             RecurrenceRule newRule = new RecurrenceRule(value);
-
             return newRule;
         } catch (GenericEntityException ee) {
             throw new RecurrenceRuleException(ee.getMessage(), ee);

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java Fri Oct  5 02:02:49 2007
@@ -204,7 +204,6 @@
 
     public synchronized void reloadCrashedJobs() {
         String instanceId = UtilProperties.getPropertyValue("general.properties", "unique.instanceId", "ofbiz0");
-        List toStore = new ArrayList();
         List crashed = null;
 
         List exprs = UtilMisc.toList(new EntityExpr("finishDateTime", EntityOperator.EQUALS, null));
@@ -217,48 +216,46 @@
         }
 
         if (crashed != null && crashed.size() > 0) {
-            Iterator i = crashed.iterator();
-            while (i.hasNext()) {
-                GenericValue job = (GenericValue) i.next();
-                long runtime = job.getTimestamp("runTime").getTime();
-                RecurrenceInfo ri = JobManager.getRecurrenceInfo(job);
-                if (ri != null) {
-                    long next = ri.next();
-                    if (next <= runtime) {
-                        Timestamp now = UtilDateTime.nowTimestamp();
-                        // only re-schedule if there is no new recurrences since last run
-                        Debug.log("Scheduling Job : " + job, module);
-
-                        String newJobId = job.getDelegator().getNextSeqId("JobSandbox");
-                        String pJobId = job.getString("parentJobId");
-                        if (pJobId == null) {
-                            pJobId = job.getString("jobId");
+            try {
+                int rescheduled = 0;
+                Iterator i = crashed.iterator();
+                while (i.hasNext()) {
+                    GenericValue job = (GenericValue) i.next();
+                    long runtime = job.getTimestamp("runTime").getTime();
+                    RecurrenceInfo ri = JobManager.getRecurrenceInfo(job);
+                    if (ri != null) {
+                        long next = ri.next();
+                        if (next <= runtime) {
+                            Timestamp now = UtilDateTime.nowTimestamp();
+                            // only re-schedule if there is no new recurrences since last run
+                            Debug.log("Scheduling Job : " + job, module);
+    
+                            String pJobId = job.getString("parentJobId");
+                            if (pJobId == null) {
+                                pJobId = job.getString("jobId");
+                            }
+                            GenericValue newJob = GenericValue.create(job);
+                            newJob.set("statusId", "SERVICE_PENDING");
+                            newJob.set("runTime", now);
+                            newJob.set("previousJobId", job.getString("jobId"));
+                            newJob.set("parentJobId", pJobId);
+                            newJob.set("startDateTime", null);
+                            newJob.set("runByInstanceId", null);
+                            delegator.createSetNextSeqId(newJob);
+    
+                            // set the cancel time on the old job to the same as the re-schedule time
+                            job.set("statusId", "SERVICE_CRASHED");
+                            job.set("cancelDateTime", now);
+                            delegator.store(job);
+                            
+                            rescheduled++;
                         }
-                        GenericValue newJob = GenericValue.create(job);
-                        newJob.set("statusId", "SERVICE_PENDING");
-                        newJob.set("runTime", now);
-                        newJob.set("jobId", newJobId);
-                        newJob.set("previousJobId", job.getString("jobId"));
-                        newJob.set("parentJobId", pJobId);
-                        newJob.set("startDateTime", null);
-                        newJob.set("runByInstanceId", null);
-                        toStore.add(newJob);
-
-                        // set the cancel time on the old job to the same as the re-schedule time
-                        job.set("statusId", "SERVICE_CRASHED");
-                        job.set("cancelDateTime", now);
-                        toStore.add(job);
                     }
                 }
-            }
-
-            if (toStore.size() > 0) {
-                try {
-                    delegator.storeAll(toStore);
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                if (Debug.infoOn()) Debug.logInfo("-- " + toStore.size() + " jobs re-scheduled", module);
+    
+                if (Debug.infoOn()) Debug.logInfo("-- " + rescheduled + " jobs re-scheduled", module);
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
             }
 
         } else {
@@ -343,11 +340,10 @@
         // persist the context
         String dataId = null;
         try {
-            dataId = delegator.getNextSeqId("RuntimeData");
-            GenericValue runtimeData = delegator.makeValue("RuntimeData", UtilMisc.toMap("runtimeDataId", dataId));
-
+            GenericValue runtimeData = delegator.makeValue("RuntimeData", null);
             runtimeData.set("runtimeInfo", XmlSerializer.serialize(context));
-            delegator.create(runtimeData);
+            runtimeData = delegator.createSetNextSeqId(runtimeData);
+            dataId = runtimeData.getString("runtimeDataId");
         } catch (GenericEntityException ee) {
             throw new JobManagerException(ee.getMessage(), ee);
         } catch (SerializeException se) {
@@ -405,8 +401,7 @@
         if (UtilValidate.isEmpty(jobName)) {
             jobName = Long.toString((new Date().getTime()));
         }
-        String jobId = delegator.getNextSeqId("JobSandbox");
-        Map jFields = UtilMisc.toMap("jobId", jobId, "jobName", jobName, "runTime", new java.sql.Timestamp(startTime),
+        Map jFields = UtilMisc.toMap("jobName", jobName, "runTime", new java.sql.Timestamp(startTime),
                 "serviceName", serviceName, "recurrenceInfoId", infoId, "runtimeDataId", dataId);
 
         // set the pool ID
@@ -426,7 +421,7 @@
         GenericValue jobV = null;
         try {
             jobV = delegator.makeValue("JobSandbox", jFields);
-            delegator.create(jobV);
+            delegator.createSetNextSeqId(jobV);
         } catch (GenericEntityException e) {
             throw new JobManagerException(e.getMessage(), e);
         }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java Fri Oct  5 02:02:49 2007
@@ -140,13 +140,12 @@
         if (Debug.verboseOn()) Debug.logVerbose("Next runtime returned: " + next, module);
 
         if (next > runtime) {
-            String newJobId = job.getDelegator().getNextSeqId("JobSandbox");
             String pJobId = job.getString("parentJobId");
             if (pJobId == null) {
                 pJobId = job.getString("jobId");
             }
             GenericValue newJob = GenericValue.create(job);
-            newJob.set("jobId", newJobId);
+            newJob.remove("jobId");
             newJob.set("previousJobId", job.getString("jobId"));
             newJob.set("parentJobId", pJobId);
             newJob.set("statusId", "SERVICE_PENDING");
@@ -154,7 +153,7 @@
             newJob.set("runByInstanceId", null);
             newJob.set("runTime", new java.sql.Timestamp(next));
             nextRecurrence = next;
-            delegator.create(newJob);
+            delegator.createSetNextSeqId(newJob);
             if (Debug.verboseOn()) Debug.logVerbose("Created next job entry: " + newJob, module);
         }
     }

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java Fri Oct  5 02:02:49 2007
@@ -549,7 +549,6 @@
                 // persist each bin when time ends if option turned on
                 if (UtilProperties.propertyValueEqualsIgnoreCase("serverstats", "stats.persist." + ServerHitBin.typeIds[type] + ".bin", "true")) {
                     GenericValue serverHitBin = delegator.makeValue("ServerHitBin", null);
-                    serverHitBin.set("serverHitBinId", getDelegator().getNextSeqId("ServerHitBin"));
                     serverHitBin.set("contentId", this.id);
                     serverHitBin.set("hitTypeId", ServerHitBin.typeIds[this.type]);
                     serverHitBin.set("binStartDateTime", new java.sql.Timestamp(this.startTime));
@@ -572,7 +571,7 @@
                         Debug.logError("Unable to get localhost internet address: " + e.toString(), module);
                     }
                     try {
-                        serverHitBin.create();
+                        delegator.createSetNextSeqId(serverHitBin);
                     } catch (GenericEntityException e) {
                         Debug.logError(e, "Could not save ServerHitBin:", module);
                     }

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java?rev=582142&r1=582141&r2=582142&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/VisitHandler.java Fri Oct  5 02:02:49 2007
@@ -131,7 +131,6 @@
                             }
                             
                             visit = delegator.makeValue("Visit", null);
-                            visit.set("visitId", delegator.getNextSeqId("Visit"));
                             visit.set("sessionId", session.getId());
                             visit.set("fromDate", new Timestamp(session.getCreationTime()));
 
@@ -167,7 +166,7 @@
                                 Debug.logError("Unable to get localhost internet address: " + e.toString(), module);
                             }
                             try {
-                                visit.create();
+                                visit = delegator.createSetNextSeqId(visit);
                                 session.setAttribute("visit", visit);
                             } catch (GenericEntityException e) {
                                 Debug.logError(e, "Could not create new visit:", module);
@@ -207,45 +206,40 @@
                             Debug.logError("Could not find delegator in request or with delegatorName [" + delegatorName + "] in session, not creating/getting Visitor entity", module);
                         } else {
                             // first try to get the current ID from the visitor cookie
-                            String visitorId = null;
+                            String cookieVisitorId = null;
                             Cookie[] cookies = request.getCookies();
                             if (Debug.verboseOn()) Debug.logVerbose("Cookies:" + cookies, module);
                             if (cookies != null) {
                                 for (int i = 0; i < cookies.length; i++) {
                                     if (cookies[i].getName().equals(visitorCookieName)) {
-                                        visitorId = cookies[i].getValue();
+                                        cookieVisitorId = cookies[i].getValue();
                                         break;
                                     }
                                 }
                             }
                             
-                            if (Debug.infoOn()) Debug.logInfo("Found visitorId [" + visitorId + "] in cookie", module);
+                            if (Debug.infoOn()) Debug.logInfo("Found visitorId [" + cookieVisitorId + "] in cookie", module);
                             
-                            if (UtilValidate.isEmpty(visitorId)) {
+                            if (UtilValidate.isEmpty(cookieVisitorId)) {
                                 // no visitor cookie? create visitor and send back cookie too
-                                visitorId = delegator.getNextSeqId("Visitor");
-            
                                 visitor = delegator.makeValue("Visitor", null);
-                                visitor.set("visitorId", visitorId);
                                 try {
-                                    visitor.create();
+                                    delegator.createSetNextSeqId(visitor);
                                 } catch (GenericEntityException e) {
                                     Debug.logError(e, "Could not create new visitor:", module);
                                     visitor = null;
                                 }
                             } else {
                                 try {
-                                    visitor = delegator.findByPrimaryKey("Visitor", UtilMisc.toMap("visitorId", visitorId));
+                                    visitor = delegator.findByPrimaryKey("Visitor", UtilMisc.toMap("visitorId", cookieVisitorId));
                                     if (visitor == null) {
                                         // looks like we have an ID that doesn't exist in our database, so we'll create a new one
-                                        String cookieVisitorId = visitorId;
-                                        visitorId = delegator.getNextSeqId("Visitor");
-                                        visitor = delegator.makeValue("Visitor", UtilMisc.toMap("visitorId", visitorId));
-                                        delegator.create(visitor);
-                                        if (Debug.infoOn()) Debug.logInfo("The visitorId [" + cookieVisitorId + "] found in cookie was invalid, creating new Visitor with ID [" + visitorId + "]", module);
+                                        visitor = delegator.makeValue("Visitor", null);
+                                        visitor = delegator.createSetNextSeqId(visitor);
+                                        if (Debug.infoOn()) Debug.logInfo("The visitorId [" + cookieVisitorId + "] found in cookie was invalid, creating new Visitor with ID [" + visitor.getString("visitorId") + "]", module);
                                     }
                                 } catch (GenericEntityException e) {
-                                    Debug.logError(e, "Error finding visitor with ID from cookie: " + visitorId, module);
+                                    Debug.logError(e, "Error finding visitor with ID from cookie: " + cookieVisitorId, module);
                                     visitor = null;
                                 }
                             }