Package spark.api

Examples of spark.api.Command


    try {
      reader.close();
    } catch (XMLStreamException e) {
      throw new SparqlException("Error closing stream", e);
    } finally {
      Command c = getCommand();
      // Need this check because command can be null when testing the parser...
      if (c != null && c instanceof ProtocolCommand) {
        ((ProtocolCommand)c).release();
      }
    }
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 static void testAsk() throws Exception {
    DataSource myDS = new ProtocolDataSource("http://DBpedia.org/sparql");
    Connection conn = myDS.getConnection(NoCredentials.INSTANCE);
    Command query = conn.createCommand("ASK { <http://dbpedia.org/resource/Terry_Gilliam> ?p ?o }");   
   
    Result r = query.execute();
    showMetadata(r);
    logger.debug("result = {}", ((BooleanResult)r).getResult());
   
    r.close();
    query.close();
    conn.close();
    myDS.close();
  }
View Full Code Here

  }
 
  public static void testAsk2() throws Exception {
    DataSource myDS = new ProtocolDataSource("http://DBpedia.org/sparql");
    Connection conn = myDS.getConnection(NoCredentials.INSTANCE);
    Command query = conn.createCommand("ASK { <http://dbpedia.org/resource/Terry_Gilliam> ?p ?o }");   
   
    logger.debug("result = {}", query.executeAsk());
   
    query.close();
    conn.close();
    myDS.close();
  }
View Full Code Here

    final AtomicInteger counter = new AtomicInteger();

    Runnable r = new Runnable() {
      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()) {
View Full Code Here

 
  static void doQuery(DataSource ds, long timeout) {
    log("getting connection");
    Connection c = ds.getConnection(NoCredentials.INSTANCE);
    try {
      Command cmd = c.createCommand(query);
      cmd.setTimeout(timeout);
      exec(cmd);
    } catch (Exception e) {
      log("Exception (" + e.getMessage() + ")");
    } finally {
      try {
View Full Code Here

 
  public static void testCancel() throws Exception {
    final ProtocolDataSource ds = new ProtocolDataSource(url);
    ds.setConnectionPoolSize(1);
    Connection conn = ds.getConnection(NoCredentials.INSTANCE);
    final Command c = conn.createCommand(query);
    final Command c2 = conn.createCommand(query);
   
    final CountDownLatch done = new CountDownLatch(2);
    new Thread(new Runnable() {
      public void run() {
        exec(c);
        done.countDown();
      }
    }).start();
    new Thread(new Runnable() {
      public void run() {
        exec(c2);
        done.countDown();
      }
    }).start();
   
    Thread.sleep(5000);
    log("canceling query 1");
    c.cancel();
    c2.cancel();
    done.await();
    log("query 1 thread done");
   
    final CountDownLatch query = new CountDownLatch(1);
    final CountDownLatch cancel = new CountDownLatch(1);
View Full Code Here

    String port = args[1];
    String query = args[2];
    System.out.println("Connecting to " + host + ":" + port);
    DataSource ds = new SHPDataSource(host, Integer.parseInt(port));
    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(); ) {
View Full Code Here

  public Solutions helpExecuteQuery(DummySherpaServer server, int batchSize) {
    InetSocketAddress serverAddress = server.getAddress();
    DataSource ds = new SHPDataSource(serverAddress.getHostName(),
        serverAddress.getPort());
    Connection conn = ds.getConnection(NoCredentials.INSTANCE);
    Command command = conn
        .createCommand("SELECT ?x ?y WHERE { this should be a real query but the test doesn't actually do anything real.");
    ((SHPCommand) command).setBatchSize(batchSize);
    return command.executeQuery();
  }
View Full Code Here

TOP

Related Classes of spark.api.Command

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.