Пример #1
1
 /**
  * Returns a map with variable bindings.
  *
  * @param opts main options
  * @return bindings
  */
 public static HashMap<String, String> bindings(final MainOptions opts) {
   final HashMap<String, String> bindings = new HashMap<>();
   final String bind = opts.get(MainOptions.BINDINGS).trim();
   final StringBuilder key = new StringBuilder();
   final StringBuilder val = new StringBuilder();
   boolean first = true;
   final int sl = bind.length();
   for (int s = 0; s < sl; s++) {
     final char ch = bind.charAt(s);
     if (first) {
       if (ch == '=') {
         first = false;
       } else {
         key.append(ch);
       }
     } else {
       if (ch == ',') {
         if (s + 1 == sl || bind.charAt(s + 1) != ',') {
           bindings.put(key.toString().trim(), val.toString());
           key.setLength(0);
           val.setLength(0);
           first = true;
           continue;
         }
         // literal commas are escaped by a second comma
         s++;
       }
       val.append(ch);
     }
   }
   if (key.length() != 0) bindings.put(key.toString().trim(), val.toString());
   return bindings;
 }
Пример #2
0
 /**
  * Parses the query.
  *
  * @param p performance
  * @throws QueryException query exception
  */
 private void parse(final Performance p) throws QueryException {
   qp.http(http);
   for (final Entry<String, String[]> entry : vars.entrySet()) {
     final String name = entry.getKey();
     final String[] value = entry.getValue();
     if (name == null) qp.context(value[0], value[1]);
     else qp.bind(name, value[0], value[1]);
   }
   qp.parse();
   if (p != null) info.parsing += p.time();
 }
Пример #3
0
 /**
  * Binds a variable.
  *
  * @param name name of variable (if {@code null}, value will be bound as context value)
  * @param value value to be bound
  * @param type type
  * @return reference
  */
 public AQuery bind(final String name, final String value, final String type) {
   vars.put(name, new String[] {value, type});
   return this;
 }