[SPY-62] need more than setKey(String) or setRange(String, String) to be able to express queires Created: 21/Oct/11  Updated: 29/May/13  Resolved: 29/May/13

Status: Resolved
Project: Spymemcached Java Client
Component/s: None
Affects Version/s: 2.8.0-dp2
Fix Version/s: None
Security Level: Public

Type: Improvement Priority: Major
Reporter: Matt Ingenthron Assignee: Michael Nitschinger
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Views can have integer datatypes. I do see that we check for that in StringUtils, but it's a bit of an odd API at the moment to have to quote your own string if you want your string as a string and not numbers. Perhaps we need to think this through a bit further.

Comment by Alan Wood [ 08/May/12 ]
Related to this:

I have a key that looks like an integer in some cases (it is just a sequence of characters). When the string based key looks like a integer, this code in Query.java treats it as one and doesn't quote it:

    // Special case
    if (key.equals(STARTKEYDOCID)) {
      return key + "=" + value;
    } else if (value instanceof Stale) {
      return key + "=" + ((Stale) value).toString();
    } else if (StringUtils.isJsonObject(value.toString())) {
      return key + "=" + value.toString();
    } else {
      return key + "=\"" + value + "\"";

For some reason a string like 100 will trigger the StringUtils.isJsonObject to return true.
Passing in a quoted string like "100" ends up NOT firing that same code (even though it is a valid JSON object) which ends up double quoting the string.

As such, for keys that look like "integers", the current Query code fails to return any documents since it is either passing through the literal 100 or the literal ""100"".
Comment by Alan Wood [ 08/May/12 ]
Changing this function in Query.java worked for my case (if I also pre-quote the string being passed into Query.setKey from my main code).
Not the most elegant fix, but it may be handy for someone else running into a similar issue until a more official fix is in place.

  private String getArg(String key, Object value) {
String valStr = value.toString();
    // Special case
    if (key.equals(STARTKEYDOCID)) {
      return key + "=" + valStr;
    } else if (value instanceof Stale) {
      return key + "=" + valStr;
    } else if (StringUtils.isJsonObject(valStr)) {
      return key + "=" + valStr;
    // Don't requote a pre-quoted string
    } else if ((valStr.length() >= 2) && (valStr.charAt(0) == '\"') && (valStr.charAt(valStr.length() - 1) == '\"')) {
      return key + "=" + valStr;
    } else {
      return key + "=\"" + valStr + "\"";
Comment by Michael Nitschinger [ 08/Oct/12 ]
There have been some recent changes with the ComplexKey additions in the couchbase client, I guess this can be closed soon since most of this has been fixed already.
Comment by Michael Nitschinger [ 29/May/13 ]
Handled in the JCBC library through the ComplexKey class.
Generated at Thu Jul 24 05:53:44 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.