Package spark.api

Examples of spark.api.Solutions


            new Object[] { null },
        });
   
    DummySherpaServer server = new DummySherpaServer(data);
    try {
      Solutions s = helpExecuteQuery(server, 10);
      String var = "a";
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(uri, s.getBinding(var));
      Assert.assertEquals(uri.getURI(), s.getURI(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(lit1, s.getBinding(var));
      Assert.assertEquals(lit1, s.getLiteral(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(lit2, s.getBinding(var));
      Assert.assertEquals(lit2, s.getLiteral(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(lit3, s.getBinding(var));
      Assert.assertEquals(lit3, s.getLiteral(var));
      Assert.assertEquals(d, s.getDateTime(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aInt, s.getBinding(var));
      Assert.assertEquals(aInt, s.getLiteral(var));
      Assert.assertEquals(20, s.getInt(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aLong, s.getBinding(var));
      Assert.assertEquals(aLong, s.getLiteral(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aBool, s.getBinding(var));
      Assert.assertEquals(aBool, s.getLiteral(var));
      Assert.assertEquals(true, s.getBoolean(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aFloat, s.getBinding(var));
      Assert.assertEquals(aFloat, s.getLiteral(var));
      Assert.assertTrue(Float.valueOf(aFloat.getLexical()).equals(s.getFloat(var)));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aDouble, s.getBinding(var));
      Assert.assertEquals(aDouble, s.getLiteral(var));
      Assert.assertTrue(Double.valueOf(aDouble.getLexical()).equals(s.getDouble(var)));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(aString, s.getBinding(var));
      Assert.assertEquals(aString, s.getLiteral(var));
      Assert.assertEquals("abcd", s.getString(var));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(bn, s.getBinding(var));
      Assert.assertEquals(bn, s.getBlankNode(var));
     
      Assert.assertTrue(s.next());
      Assert.assertNull(s.getBinding(var));
      Assert.assertFalse(s.isBound(var));
      Assert.assertNull(s.getNamedNode(var));
      Assert.assertNull(s.getLiteral(var));
      Assert.assertNull(s.getBlankNode(var));
     
      Assert.assertFalse(s.next());
    } finally {
      server.shutdown();
    }
  }
View Full Code Here


 
  public static void testQuery() throws Exception {
    DataSource myDS = new ProtocolDataSource("http://DBpedia.org/sparql");
    Connection conn = myDS.getConnection(NoCredentials.INSTANCE);
    Command query = conn.createCommand("SELECT ?p ?o WHERE { <http://dbpedia.org/resource/Terry_Gilliam> ?p ?o }");   
    Solutions solutions = query.executeQuery();
   
    showMetadata(solutions);
    logger.debug("vars = {}", solutions.getVariables());
    int row = 0;
    while(solutions.next()) {
      logger.debug("Row {}: {}", ++row, solutions.getResult());
    }
    solutions.close();
    query.close();
    conn.close();
    myDS.close();
  }
View Full Code Here

 
  public static void testQuery2() throws Exception {
    DataSource myDS = new ProtocolDataSource("http://DBpedia.org/sparql");
    Connection conn = myDS.getConnection(NoCredentials.INSTANCE);
    Command query = conn.createCommand("SELECT ?p ?o WHERE { <http://dbpedia.org/resource/Terry_Gilliam> ?p ?o }");   
    Solutions solutions = query.executeQuery();
   
    showMetadata(solutions);
    logger.debug("vars = {}", solutions.getVariables());
    int row = 0;
    for(Map<String, RDFNode> solution : solutions) {
      logger.debug("Row {}: {}", ++row, solution);
    }
    solutions.close();
    query.close();
    conn.close();
    myDS.close();
  }
View Full Code Here

      public void run() {
        Connection c = f.getSource().getConnection(NoCredentials.INSTANCE);
        Command cmd = c.createCommand("SELECT ?p ?o WHERE { <http://dbpedia.org/resource/Terry_Gilliam> ?p ?o }");
        cmd.setTimeout(30);
        try {
          Solutions s = cmd.executeQuery();
          Assert.assertNotNull(s);
          try {
            Assert.assertEquals(Arrays.asList("p", "o"), s.getVariables());
            int count = 0;
            while (s.next()) {
              count++;
              Assert.assertNotNull(s.getBinding("p"));
              Assert.assertNotNull(s.getBinding("o"));
            }
            Assert.assertEquals(121, count);
          } finally {
            try {
              s.close();
            } catch (IOException e) {
              throw new RuntimeException("Error closing solutions.", e);
            }
          }
        } finally {
View Full Code Here

  }
 
  static void exec(Command cmd) {
    try {
      log("submitting query");
      Solutions s = cmd.executeQuery();
      log("got response");
      try {
        int count = 0;
        while (s.next()) count++;
        log("found " + count + " solutions");
      } finally {
        s.close();
      }
    } catch (Exception e) {
      log("Exception (" + e.getMessage() + ")");
    }
  }
View Full Code Here

    final CountDownLatch done2 = new CountDownLatch(1);
    new Thread(new Runnable() {
      public void run() {
        try {
          log("executing query 2");
          Solutions s = c.executeQuery();
          log("query 2 done");
          try {
            query.countDown();
            cancel.await();
            log("getting query 2 result");
            int count = 0;
            while (s.next()) count++;
            log("query 2 found " + count + "results");
          } catch (InterruptedException e) {
            log("interrupted!");
          } finally {
            try {
              s.close();
            } catch (IOException e) {
              log("IOException (" + e + ")");
            }
          }
        } finally {
View Full Code Here

    Connection conn = ds.getConnection(NoCredentials.INSTANCE);
    Command command = conn.createCommand(query);
    command.setTimeout(120000);
   
    System.out.println("Executing query....");
    Solutions results = command.executeQuery();
   
    System.out.println("\nResults:");
    int count = 0;
    Iterator<Map<String,RDFNode>> iter = results.iterator();
    for (; iter.hasNext(); ) {
      Map<String,RDFNode> tuple = iter.next();
      count++;
      for(Map.Entry<String, RDFNode> entry : tuple.entrySet()) {
        System.out.print("\t" + entry.getKey() + ": " + entry.getValue());
View Full Code Here

 
  public void helpTestQueryCursor(int resultRows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(resultRows);

    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);

      TestCursor.assertCursor(solutions, BEFORE_FIRST);
     
      int counter = 0;
      while (solutions.next()) {
        Map<String,RDFNode> solution = solutions.getResult();
        Assert.assertNotNull(solution);
        Assert.assertEquals(++counter, solutions.getRow());
        int state = ((counter == 1) ? FIRST : NONE) | ((counter == resultRows) ? LAST : NONE);
        TestCursor.assertCursor(solutions, state);
      }

      TestCursor.assertCursor(solutions, AFTER_LAST);
View Full Code Here

  }

  public void helpTestIteratorNormal(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator in a normal fashion.
      while (iter.hasNext()) {
        data.add(iter.next());
View Full Code Here

  }
 
  public void helpTestIteratorParanoid(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator, with lots of extra checks to hasNext();
      Assert.assertEquals(rows > 0, iter.hasNext());
      Assert.assertEquals(rows > 0, iter.hasNext());
View Full Code Here

TOP

Related Classes of spark.api.Solutions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.