Package spark.api

Examples of spark.api.Connection


    }
  }
 
  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


    myDS.close();
  }
 
  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

    myDS.close();
  }
 
  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

    myDS.close();
  }
 
  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 AtomicLong timer = new AtomicLong();
    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()) {
              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 {
          try {
            c.close();
          } catch (IOException e) {
            throw new RuntimeException("Error closing connection.", e);
          }
        }
      }
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 {
        c.close();
      } catch (IOException e) {
        log("IOException (" + e.getMessage() + ")");
      }
    }
  }
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);
View Full Code Here

    String host = args[0];
    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();
   
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

        });
    InetSocketAddress serverAddress = server.getAddress();
   
    try {
      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. }");
      command.setTimeout(1234);
      command.executeQuery();
     
      // Kind of tricky here - the keys and values are now Avro Utf8 instances which don't compare equal to Strings
      Map<CharSequence,CharSequence> serverProps = (Map<CharSequence,CharSequence>)results.get(0);
View Full Code Here

TOP

Related Classes of spark.api.Connection

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.