Package org.openrdf.repository

Examples of org.openrdf.repository.RepositoryConnection


    negativeTests.setName("Negative Syntax Tests");

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();
    RepositoryConnection con = manifestRep.getConnection();

    URL manifestURL = SeRQLParserTestCase.class.getResource(MANIFEST_FILE);
    RDFFormat format = RDFFormat.forFileName(MANIFEST_FILE, RDFFormat.TURTLE);
    con.add(manifestURL, base(manifestURL.toExternalForm()), format);

    String query = "SELECT testName, query, result " + "FROM {} mf:name {testName}; "
        + "        mf:action {query}; " + "        mf:result {result} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  mfx = <http://www.openrdf.org/test-manifest-extensions#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = testBindings.getValue("testName").toString();
      String queryFile = testBindings.getValue("query").toString();
      Value result = testBindings.getValue("result");
      if (MFX_CORRECT.equals(result)) {
        positiveTests.addTest(factory.createTest(testName, queryFile, result));
      }
      else if (MFX_PARSE_ERROR.equals(result)) {
        negativeTests.addTest(factory.createTest(testName, queryFile, result));
      }
      else {
        logger.warn("Unexpected result value for test \"" + testName + "\": " + result);
      }
    }

    tests.close();
    con.close();
    manifestRep.shutDown();

    suite.addTest(positiveTests);
    suite.addTest(negativeTests);
    return suite;
View Full Code Here


    String query = readQuery();

    File dataDir = FileUtil.createTempDir("serql");
    Repository dataRep = createRepository(dataDir, entailment);
    try {
      RepositoryConnection con = dataRep.getConnection();
      try {
        // Add unnamed graph
        con.add(url(dataFile), base(dataFile), RDFFormat.forFileName(dataFile));

        // add named graphs
        for (String graphName : graphNames) {
          con.add(url(graphName), base(graphName), RDFFormat.forFileName(graphName), new URIImpl(
              graphName));
        }

        // Evaluate the query on the query data
        GraphResult result = con.prepareGraphQuery(getQueryLanguage(), query).evaluate();
        try {
          actualStatements = result.asList();
        }
        finally {
          result.close();
        }
      }
      finally {
        con.close();
      }
    }
    finally {
      dataRep.shutDown();
      FileUtil.deleteDir(dataDir);
    }

    // Create a repository with the expected result data
    dataDir = FileUtil.createTempDir("serql");
    Repository expectedResultRep = createRepository(dataDir);
    try {
      RepositoryConnection con = expectedResultRep.getConnection();
      try {
        con.add(url(resultFile), base(resultFile), RDFFormat.forFileName(resultFile));

        expectedStatements = con.match(null, null, null, false).asList();
      }
      finally {
        con.close();
      }
    }
    finally {
      expectedResultRep.shutDown();
      FileUtil.deleteDir(dataDir);
View Full Code Here

  {
    Repository dataRep = new SailRepository(createSail(entailment));
    dataRep.setDataDir(dataDir);
    dataRep.initialize();

    RepositoryConnection con = dataRep.getConnection();
    try {
      con.clear();
      con.clearNamespaces();
    }
    finally {
      con.close();
    }

    return dataRep;
  }
View Full Code Here

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();

    RepositoryConnection con = manifestRep.getConnection();

    URL manifestURL = SeRQLQueryTestCase.class.getResource(MANIFEST_FILE);
    RDFFormat format = RDFFormat.forFileName(MANIFEST_FILE, RDFFormat.TURTLE);
    con.add(manifestURL, base(manifestURL.toExternalForm()), format);

    String query = "SELECT testName, entailment, input, query, result " + "FROM {} mf:name {testName};"
        + "        mf:result {result}; " + "        tck:entailment {entailment}; "
        + "        mf:action {} qt:query {query}; " + "                     qt:data {input} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>, "
        + "  tck = <urn:openrdf.org:sesame:tests#> ";

    TupleResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = ((Literal)testBindings.getValue("testName")).getLabel();
      String inputFile = testBindings.getValue("input").toString();
      String queryFile = testBindings.getValue("query").toString();
      String resultFile = testBindings.getValue("result").toString();
      String entailment = ((Literal)testBindings.getValue("entailment")).getLabel();

      query = "SELECT graph " + "FROM {} mf:name {testName}; "
          + "        mf:action {} qt:graphData {graph} " + "WHERE testName = \""
          + SeRQLUtil.encodeString(testName) + "\" " + "USING NAMESPACE"
          + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>,"
          + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

      List<String> graphNames = new ArrayList<String>();

      TupleResult graphs = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
      while (graphs.hasNext()) {
        BindingSet graphBindings = graphs.next();
        graphNames.add(graphBindings.getValue("graph").toString());
      }
      graphs.close();

      if (testName.startsWith("test-029:")) {
        logger.error("test-029 SKIPPED in {}", SeRQLQueryTestCase.class.getName());
        continue;
      }
      suite.addTest(factory.createTest(testName, inputFile, graphNames, queryFile, resultFile, entailment));
    }

    tests.close();
    con.close();
    manifestRep.shutDown();

    return suite;
  }
View Full Code Here

    Collection<? extends Statement> expectedStatements = null;

    Repository repository = new SailRepository(sailStack);
    repository.initialize();

    RepositoryConnection con = repository.getConnection();

    // clear the input store
    con.clear();

    // Upload input data
    InputStream stream = getClass().getResourceAsStream(inputData);
    try {
      con.add(stream, inputData, RDFFormat.NTRIPLES);
      entailedStatements = con.match(null, null, null, true).asSet();
    }
    finally {
      stream.close();
      con.close();
    }

    // Upload output data
    Repository outputRepository = new SailRepository(new MemoryStore());
    outputRepository.initialize();
    con = outputRepository.getConnection();

    stream = getClass().getResourceAsStream(outputData);
    try {
      con.add(stream, outputData, RDFFormat.NTRIPLES);
      expectedStatements = con.match(null, null, null, false).asSet();
    }
    finally {
      stream.close();
      con.close();
      outputRepository.shutDown();
      repository.shutDown();
    }

    // Check whether all expected statements are present in the entailment
View Full Code Here

    throws Exception
  {
    Repository rep1 = new SailRepository(new MemoryStore());
    rep1.initialize();

    RepositoryConnection con1 = rep1.getConnection();

    URL rdf = this.getClass().getResource("/testcases/rdfa-test.rdf");

    con1.add(rdf, rdf.toExternalForm(), RDFFormat.forFileName(rdf.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.setBaseURI(rdf.toExternalForm());
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();

    Repository rep2 = new SailRepository(new MemoryStore());
    rep2.initialize();

    RepositoryConnection con2 = rep2.getConnection();

    con2.add(new StringReader(writer.toString()), rdf.toExternalForm(), rdfWriterFactory.getRDFFormat());
    long after = con2.size();
    con2.close();

    assertEquals("result of serialization and re-upload should be equal to original", before, after);

    assertTrue("result of serialization and re-upload should be equal to original", RepositoryUtil.equals(
        rep1, rep2));
View Full Code Here

    QueryLanguage queryLn = getQueryLanguage(params, response);
    String baseURI = params.getFirstValue(BASEURI_PARAM_NAME);

    try {
      RepositoryConnection connection = RequestAtt.getConnection(request);
      Query query = connection.prepareQuery(queryLn, queryStr, baseURI);
      parseQueryParameters(query, params, connection.getValueFactory());
      return query;
    }
    catch (StoreException e) {
      throw new ResourceException(SERVER_ERROR_INTERNAL, "Failed to prepare query", e);
    }
View Full Code Here

  public String returnCodeListURI(String codeList)
  {
   
    String codeListURI="";
    try {
         RepositoryConnection con = _repository.getConnection();
         try
         {
           BindingSet bindingSet;

           TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, String.format(SELECT_CodeList_TEMPLATE,codeList));
           TupleQueryResult result = tupleQuery.evaluate();
              
           if(result.hasNext())
             {                
               bindingSet = result.next();
               codeListURI = bindingSet.getValue("sub").toString();
               codeListURI = codeListURI.substring(codeListURI.indexOf("#")+1);
              
             }
              
             result.close();              
         }
         finally {
           con.close();
         }
      }
    catch (OpenRDFException e) {
     
    }
View Full Code Here

     */
    private void assertEncodingDetection(String encoding, String input, String expectedContent)
    throws Exception {
        DocumentSource fileDocumentSource = getDocumentSourceFromResource(input);
        Any23 any23;
        RepositoryConnection conn;
        RepositoryWriter repositoryWriter;
       
        any23 = new Any23();
        Sail store = new MemoryStore();
        store.initialize();
        conn = new SailRepository(store).getConnection();
        repositoryWriter = new RepositoryWriter(conn);
        Assert.assertTrue( any23.extract(fileDocumentSource, repositoryWriter, encoding).hasMatchingExtractors() );

        RepositoryResult<Statement> statements = conn.getStatements(null, vDCTERMS.title, null, false);
        try {
            while (statements.hasNext()) {
                Statement statement = statements.next();
                printStatement(statement);
                org.junit.Assert.assertTrue(statement.getObject().stringValue().contains(expectedContent));
            }
        } finally {
            statements.close();
        }

        fileDocumentSource = null;
        any23 = null;
        conn.close();
        repositoryWriter.close();
    }
View Full Code Here

    model.open();

    // fetch the Repository, a Connection and a ValueFactory
    Repository repository = (Repository) model
        .getUnderlyingModelImplementation();
    RepositoryConnection connection = repository.getConnection();
    ValueFactory factory = repository.getValueFactory();

    // add a statement
    model.addStatement(subject, predicate, object);

    // convert the statement parts to OpenRDF data types
    Resource openRdfSubject = ConversionUtil.toOpenRDF(subject, factory);
    org.openrdf.model.URI openRdfPredicate = ConversionUtil.toOpenRDF(
        predicate, factory);
    Value openRdfObject = ConversionUtil.toOpenRDF(object, factory);
    org.openrdf.model.URI context = RepositoryModel.DEFAULT_OPENRDF_CONTEXT;

    // make sure this statement is contained in this model
    assertTrue(connection.hasStatement(openRdfSubject, openRdfPredicate,
        openRdfObject, false, context));

    // make sure this statement can also be found through the Model API
    ClosableIterator<? extends Statement> sit = model.findStatements(
        subject, predicate, object);
    assertNotNull(sit);
    assertTrue(sit.hasNext());

    Statement s2 = sit.next();
    URI s2s = (URI) s2.getSubject();
    URI s2p = s2.getPredicate();
    URI s2o = (URI) s2.getObject();

    assertEquals(subject, s2s);
    assertEquals(predicate, s2p);
    assertEquals(object, s2o);

    // make sure that this statement is only returned once
    assertFalse(sit.hasNext());

    // clean-up
    sit.close();
    connection.close();
    model.close();
  }
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.