Ejemplo n.º 1
0
  /**
   * Runs a query with an external variable declaration.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryBindSequence() throws IOException {
    Query query = session.query("declare variable $a external; $a");
    query.bind("a", "1\u00012", "xs:integer");
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", "09\u0002xs:hexBinary\u00012", "xs:integer");
    assertEqual("09", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", Seq.get(new Item[] {Int.get(1), Str.get("X")}, 2));
    assertEqual("1", query.next());
    assertEqual("X", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT));
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT), "xs:integer");
    assertEqual("1", query.next());
    assertEqual("2", query.next());
    query.close();
  }
Ejemplo n.º 2
0
  /**
   * Runs a query with an external variable declaration.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void queryBindInt() throws IOException {
    Query query = session.query("declare variable $a as xs:integer external; $a");
    query.bind("a", "5", "xs:integer");
    assertEqual("5", query.next());
    query.close();

    query = session.query("declare variable $a external; $a");
    query.bind("a", Int.get(1), "xs:integer");
    assertEqual("1", query.next());
    query.close();
  }
Ejemplo n.º 3
0
 /**
  * Runs two queries in parallel.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryParallel() throws IOException {
   final Query query1 = session.query("1 to 2");
   final Query query2 = session.query("reverse(3 to 4)");
   assertEqual("1", query1.next());
   assertEqual("4", query2.next());
   assertEqual("2", query1.next());
   assertEqual("3", query2.next());
   assertNull(query1.next());
   assertNull(query2.next());
   query1.close();
   query2.close();
 }
Ejemplo n.º 4
0
 /**
  * Runs a query with a bound context value.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryContextVar() throws IOException {
   final Query query = session.query("declare variable $a := .; $a");
   query.context("<a/>", "element()");
   assertEqual("<a/>", query.next());
   query.close();
 }
Ejemplo n.º 5
0
 /**
  * Runs a query with a bound context value.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryContextInt() throws IOException {
   final Query query = session.query(". * 2");
   query.context("6", "xs:integer");
   assertEqual("12", query.next());
   query.close();
 }
Ejemplo n.º 6
0
 /**
  * Runs a query with a bound context value.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryContext() throws IOException {
   final Query query = session.query(".");
   query.context("5");
   assertEqual("5", query.next());
   query.close();
 }
Ejemplo n.º 7
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindURI() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("$a", "X", "xs:anyURI");
   assertEqual("X", query.next());
   query.close();
 }
Ejemplo n.º 8
0
 /**
  * Runs a query with an external variable declaration.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBindEmptySequence() throws IOException {
   final Query query = session.query("declare variable $a external; $a");
   query.bind("a", "()", "empty-sequence()");
   assertNull(query.next());
   query.close();
 }
Ejemplo n.º 9
0
 /**
  * Runs a query and retrieves multiple results as string.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryMore() throws IOException {
   final Query query = session.query("1 to 3");
   int c = 0;
   while (query.more()) assertEqual(++c, query.next());
   query.close();
 }
Ejemplo n.º 10
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();
  }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
0
 /**
  * Runs 5 queries in parallel.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryParallel2() throws IOException {
   final int size = 8;
   final Query[] cqs = new Query[size];
   for (int q = 0; q < size; q++) cqs[q] = session.query(Integer.toString(q));
   for (int q = 0; q < size; q++) assertEqual(q, cqs[q].next());
   for (final Query query : cqs) query.close();
 }
Ejemplo n.º 13
0
 /**
  * Runs a query, omitting more().
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryNoMore() throws IOException {
   final Query query = session.query("1 to 2");
   assertEqual("1", query.next());
   assertEqual("2", query.next());
   assertNull(query.next());
   query.close();
 }
Ejemplo n.º 14
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();
 }
Ejemplo n.º 15
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();
 }
Ejemplo n.º 16
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();
     }
   }
 }
Ejemplo n.º 17
0
 /**
  * Tolerate multiple close calls.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryClose() throws IOException {
   final Query query = session.query("()");
   query.close();
   query.close();
 }
Ejemplo n.º 18
0
 /**
  * Runs a query and retrieves the empty result as string.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryNoResult() throws IOException {
   final Query query = session.query("()");
   assertFalse("No result was expected.", query.more());
   query.close();
 }
Ejemplo n.º 19
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();
 }