]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/IndexQueries.java
Index query fixes after commit 5e340942
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / IndexQueries.java
index 212da3830a1decfaac2ef541ba0f0d5155070252..2be6bf5d0e1f270655ed0828acbc07975e075b52 100644 (file)
@@ -159,18 +159,57 @@ public class IndexQueries {
        }
 
        public static String escapeTerm(String field, String term, boolean escapeWildcards) {
-               StringBuilder sb = new StringBuilder();
-               return escapeTerm(field, term, escapeWildcards, sb).toString();
+               return escapeTerm(field, term, escapeWildcards, new StringBuilder()).toString();
        }
-       
+
+       public static StringBuilder quoteTerm(String field, String term, StringBuilder result) {
+               if (field != null)
+                       result.append(field).append(':');
+               result.append("\"");
+               result.append(term.replaceAll("(\"|\\\\)", "\\\\$0"));
+               result.append("\"");
+               return result;
+       }
+
        public static String quoteTerm(String term) {
-               StringBuilder sb = new StringBuilder();
-               sb.append("\"");
-               sb.append(term.replaceAll("(\"|\\\\)", "\\\\$0"));
-               sb.append("\"");
+               return quoteTerm(null, term, new StringBuilder(term.length()*2)).toString();
+       }
+
+       public static String quoteTerm(String field, String term) {
+               return quoteTerm(field, term,
+                               new StringBuilder(
+                                               term.length()*2
+                                               + (field != null ? field.length() + 1 : 0))
+                               ).toString();
+       }
+
+       private static String join(String withString, String... exps) {
+               if (exps.length == 0)
+                       return "";
+               StringBuilder sb = new StringBuilder(128);
+               for (int i = 0; i < exps.length - 1; ++i) {
+                       sb.append(exps[i]).append(withString);
+               }
+               sb.append(exps[exps.length - 1]);
                return sb.toString();
        }
 
+       public static String and(String exp1, String exp2) {
+               return exp1 + " AND " + exp2;
+       }
+
+       public static String and(String... exps) {
+               return join(" AND ", exps);
+       }
+
+       public static String or(String exp1, String exp2) {
+               return exp1 + " OR " + exp2;
+       }
+
+       public static String or(String... exps) {
+               return join(" OR ", exps);
+       }
+
 //     public static void main(String[] args) {
 //             System.out.println("esc: " + escape("AND01", true, true));
 //             System.out.println("esc: " + escape("AND 01", true, true));