details:   /erp/devel/pi/rev/30ac8883f558
changeset: 10194:30ac8883f558
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Fri Jan 28 13:09:10 2011 +0100
summary:   Add support for session variables, preferences, ..., in whereclauses

diffstat:

 
modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
 |  28 ++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diffs (42 lines):

diff -r 5936bc0b19b9 -r 30ac8883f558 
modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
       Fri Jan 28 13:03:49 2011 +0100
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/QueryBuilder.java
       Fri Jan 28 13:09:10 2011 +0100
@@ -341,10 +341,38 @@
     }
 
     whereClause = setRequestParameters(whereClause);
+    whereClause = substituteContextParameters(whereClause);
 
     return whereClause;
   }
 
+  private String substituteContextParameters(String currentWhereClause) {
+    // This method will check for any remaining @param@s
+    // If there are still some in the whereclause, they will be resolved by 
calling the getContext()
+    // method
+    if (!currentWhereClause.contains("@")) {
+      return currentWhereClause;
+    }
+    String localWhereClause = currentWhereClause;
+    while (localWhereClause.contains("@")) {
+      int firstAtIndex = localWhereClause.indexOf("@");
+      String prefix = localWhereClause.substring(0, firstAtIndex);
+      String restOfClause = localWhereClause.substring(firstAtIndex + 1);
+      int secondAtIndex = restOfClause.indexOf("@");
+      if (secondAtIndex == -1) {
+        // No second @. We return the clause as it is
+        return localWhereClause;
+      }
+      String suffix = restOfClause.substring(secondAtIndex + 1);
+      String param = restOfClause.substring(0, secondAtIndex);
+      String paramValue = Utility.getContext(new DalConnectionProvider(false), 
RequestContext.get()
+          .getVariablesSecureApp(), param, 
RequestContext.get().getRequestParameter("windowId"));
+      localWhereClause = prefix + getTypedParameterAlias() + suffix;
+      typedParameters.add(paramValue);
+    }
+    return localWhereClause;
+  }
+
   private String setRequestParameters(String currentWhereClause) {
     // no parameters
     if (!currentWhereClause.contains(PARAM_DELIMITER)) {

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to