Exemple #1
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindDynamic() throws IOException {
   final Query query = session.query("declare variable $a as xs:integer external; $a");
   query.bind("a", "1");
   assertEqual("1", query.execute());
   query.close();
 }
Exemple #2
0
  /**
   * Runs a query and checks the updating flag.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryUpdating() throws IOException {
    // test non-updating query
    Query query = session.query("12345678");
    assertFalse(query.updating());
    assertEqual("12345678", query.execute());
    assertFalse(query.updating());
    query.close();

    // test updating query
    query = session.query("insert node <a/> into <b/>");
    assertTrue(query.updating());
    assertEqual("", query.execute());
    assertTrue(query.updating());
    query.close();
  }
Exemple #3
0
 /**
  * Runs a query and checks the serialization parameters.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryOptions() throws IOException {
   final Query query = session.query("declare option output:encoding 'US-ASCII';()");
   query.execute();
   final SerializerOptions sp = new SerializerOptions();
   sp.parse(query.options());
   assertEquals("US-ASCII", sp.get(SerializerOptions.ENCODING));
   query.close();
 }
Exemple #4
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBind() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("$a", "4");
   assertEqual("4", query.execute());
   query.bind("$a", "5");
   assertEqual("5", query.next());
   query.bind("$a", "6");
   assertEqual("6", query.next());
   query.close();
 }
Exemple #5
0
 /**
  * Binds maps to external variables via JSON.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindJson() throws IOException {
   final String var = "declare variable $x external;",
       map = "{\"foo\":[1,2,3],\"bar\":{\"a\":null,\"\":false}}";
   final String[][] tests = {
     {"for $k in map:keys($x) order by $k descending return $k", "foo bar"},
     {"every $k in map:keys($x('foo')) satisfies $k eq $x('foo')($k)", "true"},
     {"empty($x('bar')('a')) and not($x('bar')(''))", "true"},
   };
   for (final String[] test : tests) {
     final Query q = session.query(var + test[0]);
     try {
       q.bind("$x", map, "json");
       assertEqual(test[1], q.execute());
     } finally {
       q.close();
     }
   }
 }
Exemple #6
0
 /**
  * Runs a query, omitting more().
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryInfo() throws IOException {
   final Query query = session.query("1 to 2");
   query.execute();
   query.close();
 }
Exemple #7
0
 /**
  * Binds a document node to an external variable.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindDoc() throws IOException {
   final Query query = session.query("declare variable $a external; $a//text()");
   query.bind("$a", "<a>XML</a>", "document-node()");
   assertEqual("XML", query.execute());
 }
Exemple #8
0
 /**
  * Runs a query and retrieves the result as string.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void query() throws IOException {
   final Query query = session.query("1");
   assertEqual("1", query.execute());
 }