Package org.openrdf.repository

Examples of org.openrdf.repository.RepositoryConnection


    if (repository == null) {
      writeError("please open a repository first");
      return;
    }

    RepositoryConnection con = repository.getConnection();

    try {
      writeln("Evaluating query...");
      long startTime = System.nanoTime();

      Collection<Namespace> namespaces = con.getNamespaces().addTo(new ArrayList<Namespace>());

      GraphResult queryResult = con.prepareGraphQuery(ql, queryString).evaluate();

      try {
        int resultCount = 0;

        while (queryResult.hasNext()) {
          Statement st = queryResult.next();
          resultCount++;

          write(getStringRepForValue(st.getSubject(), namespaces));
          write("   ");
          write(getStringRepForValue(st.getPredicate(), namespaces));
          write("   ");
          write(getStringRepForValue(st.getObject(), namespaces));
          writeln();
        }

        long endTime = System.nanoTime();
        writeln(resultCount + " results (" + (endTime - startTime) / 1000000 + " ms)");
      }
      finally {
        queryResult.close();
      }
    }
    finally {
      con.close();
    }
  }
View Full Code Here


    if (repository == null) {
      writeError("please open a repository first");
      return;
    }

    RepositoryConnection con = repository.getConnection();

    try {
      writeln("Evaluating query...");
      long startTime = System.nanoTime();

      boolean booleanQueryResult = con.prepareBooleanQuery(ql, queryString).ask();

      writeln("Answer: " + booleanQueryResult);

      long endTime = System.nanoTime();
      writeln("Query evaluated in " + (endTime - startTime) / 1000000 + " ms");
    }
    finally {
      con.close();
    }
  }
View Full Code Here

  {
    Map<RepositoryConnection, Set<TupleExpr>> ownerExprMap = new HashMap<RepositoryConnection, Set<TupleExpr>>();

    for (Map.Entry<TupleExpr, Set<SignedConnection>> entry : exprOwnerMap.entrySet()) {
      if (entry.getValue().size() == 1) {
        RepositoryConnection owner = entry.getValue().iterator().next();

        Set<TupleExpr> joinArgs = ownerExprMap.get(owner);
        if (joinArgs == null) {
          joinArgs = new HashSet<TupleExpr>();
          ownerExprMap.put(owner, joinArgs = new HashSet<TupleExpr>());
View Full Code Here

  String queryString = "SELECT ?o WHERE { ?s ?p ?o}";

  public void testGraphQuery()
    throws Exception
  {
    RepositoryConnection stub = new RepositoryConnectionStub() {

      @Override
      public GraphQuery prepareGraphQuery(QueryLanguage ql, String query, String baseURI)
        throws MalformedQueryException, StoreException
      {
        assertEquals(SPARQL, ql);
        assertEquals(queryString, query);
        return new GraphQueryStub() {

          @Override
          public void setDataset(Dataset dataset) {
            Set<URI> contexts = Collections.singleton(context);
            assertEquals(contexts, dataset.getDefaultGraphs());
            super.setDataset(dataset);
          }
        };
      }
    };
    Repository repo = stub.getRepository();
    ContextAwareConnection con = new ContextAwareConnection(repo, stub);
    con.setReadContexts(context);
    con.setQueryLanguage(SERQL);
    con.prepareGraphQuery(SPARQL, queryString, null);
  }
View Full Code Here

  }

  public void testQuery()
    throws Exception
  {
    RepositoryConnection stub = new RepositoryConnectionStub() {

      @Override
      public Query prepareQuery(QueryLanguage ql, String query, String baseURI)
        throws MalformedQueryException, StoreException
      {
        assertEquals(SPARQL, ql);
        assertEquals(queryString, query);
        return new QueryStub() {

          @Override
          public void setDataset(Dataset dataset) {
            Set<URI> contexts = Collections.singleton(context);
            assertEquals(contexts, dataset.getDefaultGraphs());
            super.setDataset(dataset);
          }
        };
      }
    };
    Repository repo = stub.getRepository();
    ContextAwareConnection con = new ContextAwareConnection(repo, stub);
    con.setReadContexts(context);
    con.setQueryLanguage(SERQL);
    con.prepareQuery(SPARQL, queryString, null);
  }
View Full Code Here

  }

  public void testTupleQuery()
    throws Exception
  {
    RepositoryConnection stub = new RepositoryConnectionStub() {

      @Override
      public TupleQuery prepareTupleQuery(QueryLanguage ql, String query, String baseURI)
        throws MalformedQueryException, StoreException
      {
        assertEquals(SPARQL, ql);
        assertEquals(queryString, query);
        return new TupleQueryStub() {

          @Override
          public void setDataset(Dataset dataset) {
            Set<URI> contexts = Collections.singleton(context);
            assertEquals(contexts, dataset.getDefaultGraphs());
            super.setDataset(dataset);
          }
        };
      }
    };
    Repository repo = stub.getRepository();
    ContextAwareConnection con = new ContextAwareConnection(repo, stub);
    con.setReadContexts(context);
    con.setQueryLanguage(SERQL);
    con.prepareTupleQuery(SPARQL, queryString, null);
  }
View Full Code Here

  public void initialize()
    throws StoreException
  {
    super.initialize();

    RepositoryConnection con = getConnection();
    try {
      if (con.isEmpty()) {
        logger.debug("Initializing empty {} repository", ID);

        con.begin();
        con.setNamespace("rdf", RDF.NAMESPACE);
        con.setNamespace("sys", RepositoryConfigSchema.NAMESPACE);

        if (persist) {
          RepositoryConfig repConfig = new RepositoryConfig(TITLE, new SystemRepositoryConfig());
          updateRepositoryConfigs(con, ID, repConfig);
        }

        con.commit();
      }
    }
    catch (StoreConfigException e) {
      throw new StoreException(e.getMessage(), e);
    }
    finally {
      con.close();
    }
  }
View Full Code Here

  private Model getSystemModel()
    throws StoreConfigException
  {
    Repository system = getSystemRepository();
    try {
      RepositoryConnection con = system.getConnection();
      try {
        return con.match(null, null, null, false).addTo(new LinkedHashModel());
      }
      finally {
        con.close();
      }
    }
    catch (StoreException e) {
      throw new StoreConfigException(e);
    }
View Full Code Here

  private void addSystemModel(Model model)
    throws StoreConfigException
  {
    Repository systemRepo = getSystemRepository();
    try {
      RepositoryConnection con = systemRepo.getConnection();
      try {
        con.add(model);
      }
      finally {
        con.close();
      }
    }
    catch (StoreException e) {
      throw new StoreConfigException(e);
    }
View Full Code Here

  private void clearSystemModel(Resource context)
    throws StoreConfigException
  {
    Repository systemRepo = getSystemRepository();
    try {
      RepositoryConnection con = systemRepo.getConnection();
      try {
        con.clear(context);
      }
      finally {
        con.close();
      }
    }
    catch (StoreException e) {
      throw new StoreConfigException(e);
    }
View Full Code Here

TOP

Related Classes of org.openrdf.repository.RepositoryConnection

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.