Author: adrianc
Date: Tue Jan 17 12:40:34 2012
New Revision: 1232398

URL: http://svn.apache.org/viewvc?rev=1232398&view=rev
Log:
Fixed a bug where code assumed a GenericValue stored in the client session 
still exists in the database.

Modified:
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlEventListener.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/stats/ServerHitBin.java

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlEventListener.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlEventListener.java?rev=1232398&r1=1232397&r2=1232398&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlEventListener.java
 (original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ControlEventListener.java
 Tue Jan 17 12:40:34 2012
@@ -31,6 +31,7 @@ import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.serialize.XmlSerializer;
@@ -75,8 +76,12 @@ public class ControlEventListener implem
             // instead of using this message, get directly from session 
attribute so it won't create a new one: GenericValue visit = 
VisitHandler.getVisit(session);
             GenericValue visit = (GenericValue) session.getAttribute("visit");
             if (visit != null) {
-                visit.set("thruDate", new 
Timestamp(session.getLastAccessedTime()));
-                visit.store();
+                Delegator delegator = visit.getDelegator();
+                visit = delegator.findOne("Visit", UtilMisc.toMap("visitId", 
visit.get("visitId")), false);
+                if (visit != null) {
+                    visit.set("thruDate", new 
Timestamp(session.getLastAccessedTime()));
+                    visit.store();
+                }
             } else {
                 Debug.logWarning("Could not find visit value object in session 
[" + session.getId() + "] that is being destroyed", 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=1232398&r1=1232397&r2=1232398&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 
Tue Jan 17 12:40:34 2012
@@ -619,10 +619,16 @@ public class ServerHitBin {
             GenericValue visit = VisitHandler.getVisit(request.getSession());
             if (visit == null) {
                 // no visit info stored, so don't store the ServerHit
-                Debug.logWarning("Could not find a visitId, so not storing 
ServerHit. This is probably a configuration error. If you turn of persistance 
of visits you should also turn off persistence of hits.", module);
+                Debug.logWarning("Could not find a visitId, so not storing 
ServerHit. This is probably a configuration error. If you turn off persistance 
of visits you should also turn off persistence of hits.", module);
                 return;
             }
             String visitId = visit.getString("visitId");
+            visit = delegator.findOne("Visit", UtilMisc.toMap("visitId", 
visitId), true);
+            if (visit == null) {
+                // GenericValue stored in client session does not exist in 
database.
+                Debug.logInfo("The Visit GenericValue stored in the client 
session does not exist in the database, not storing server hit.", module);
+                return;
+            }
             
             Debug.logInfo("Visit delegatorName=" + 
visit.getDelegator().getDelegatorName() + ", ServerHitBin delegatorName=" + 
this.delegator.getDelegatorName(), module);
             


Reply via email to