Examples of RepositoryConnection


Examples of org.openrdf.repository.RepositoryConnection

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

Examples of org.openrdf.repository.RepositoryConnection

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

Examples of org.openrdf.repository.RepositoryConnection

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

Examples of org.openrdf.repository.RepositoryConnection

  {
    TestSuite suite = new TestSuite(factory.getClass().getName());

    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();
    RepositoryConnection con = manifestRep.getConnection();

    addTurtle(con, new URL(MANIFEST_FILE), MANIFEST_FILE);

    String query = "SELECT DISTINCT manifestFile FROM {x} rdf:first {manifestFile} "
        + "USING NAMESPACE mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleResult manifestResults = con.prepareTupleQuery(QueryLanguage.SERQL, query, MANIFEST_FILE).evaluate();

    while (manifestResults.hasNext()) {
      BindingSet bindingSet = manifestResults.next();
      String manifestFile = bindingSet.getValue("manifestFile").toString();
      suite.addTest(SPARQLQueryTest.suite(manifestFile, factory));
    }

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

    logger.info("Created aggregated test suite with " + suite.countTestCases() + " test cases.");
    return suite;
  }

Examples of org.openrdf.repository.RepositoryConnection

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

    RepositoryConnection con = manifestRep.getConnection();

    logger.debug("Loading manifest data");
    URL manifest = new URL(MANIFEST_FILE);
    ManifestTest.addTurtle(con, manifest, MANIFEST_FILE);

    logger.info("Searching for sub-manifests");
    List<String> subManifestList = new ArrayList<String>();

    TupleResult subManifests = con.prepareTupleQuery(QueryLanguage.SERQL, SUBMANIFEST_QUERY).evaluate();
    while (subManifests.hasNext()) {
      BindingSet bindings = subManifests.next();
      subManifestList.add(bindings.getValue("subManifest").toString());
    }
    subManifests.close();

    logger.info("Found {} sub-manifests", subManifestList.size());

    for (String subManifest : subManifestList) {
      logger.info("Loading sub manifest {}", subManifest);
      con.clear();

      URL subManifestURL = new URL(subManifest);
      ManifestTest.addTurtle(con, subManifestURL, subManifest);

      TestSuite subSuite = new TestSuite(subManifest.substring(HOST.length()));

      logger.info("Creating test cases for {}", subManifest);
      TupleResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, TESTCASE_QUERY).evaluate();
      while (tests.hasNext()) {
        BindingSet bindingSet = tests.next();

        String testURI = bindingSet.getValue("TestURI").toString();
        String testName = bindingSet.getValue("Name").toString();
        String testAction = bindingSet.getValue("Action").toString();
        boolean positiveTest = bindingSet.getValue("Type").toString().equals(
            "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#PositiveSyntaxTest");

        subSuite.addTest(factory.createSPARQLSyntaxTest(testURI, testName, testAction, positiveTest));
      }
      tests.close();

      suite.addTest(subSuite);
    }

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

    logger.info("Created test suite containing " + suite.countTestCases() + " test cases");
    return suite;
  }

Examples of org.openrdf.repository.RepositoryConnection

  protected Repository createRepository()
    throws Exception
  {
    Repository repo = newRepository();
    repo.initialize();
    RepositoryConnection con = repo.getConnection();
    try {
      con.clear();
      con.clearNamespaces();
    }
    finally {
      con.close();
    }
    return repo;
  }

Examples of org.openrdf.repository.RepositoryConnection

  }

  private void uploadDataset(Dataset dataset)
    throws Exception
  {
    RepositoryConnection con = dataRep.getConnection();
    try {
      // Merge default and named graphs to filter duplicates
      Set<URI> graphURIs = new HashSet<URI>();
      graphURIs.addAll(dataset.getDefaultGraphs());
      graphURIs.addAll(dataset.getNamedGraphs());

      for (Resource graphURI : graphURIs) {
        upload(((URI)graphURI), graphURI);
      }
    }
    finally {
      con.close();
    }
  }

Examples of org.openrdf.repository.RepositoryConnection

  }

  private void upload(URI graphURI, Resource context)
    throws Exception
  {
    RepositoryConnection con = dataRep.getConnection();

    con.begin();
    try {
      RDFFormat rdfFormat = Rio.getParserFormatForFileName(graphURI.toString(), RDFFormat.TURTLE);
      RDFParser rdfParser = Rio.createParser(rdfFormat, con.getValueFactory());
      rdfParser.setVerifyData(false);
      rdfParser.setDatatypeHandling(DatatypeHandling.IGNORE);
      // rdfParser.setPreserveBNodeIDs(true);

      RDFInserter rdfInserter = new RDFInserter(con);
      rdfInserter.enforceContext(context);
      rdfParser.setRDFHandler(rdfInserter);

      URL graphURL = new URL(graphURI.toString());
      InputStream in = graphURL.openStream();
      try {
        rdfParser.parse(in, graphURI.toString());
      }
      finally {
        in.close();
      }

      con.commit();
    }
    finally {
      con.close();
    }
  }

Examples of org.openrdf.repository.RepositoryConnection

    TestSuite suite = new TestSuite(factory.getClass().getName());

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

    ManifestTest.addTurtle(con, new URL(manifestFileURL), manifestFileURL);

    suite.setName(getManifestName(manifestRep, con, manifestFileURL));

    // Extract test case information from the manifest file. Note that we only
    // select those test cases that are mentioned in the list.
    StringBuilder query = new StringBuilder(512);
    query.append(" SELECT DISTINCT testURI, testName, resultFile, action, queryFile, defaultGraph ");
    query.append(" FROM {} rdf:first {testURI} dawgt:approval {dawgt:Approved}; ");
    query.append("                             mf:name {testName}; ");
    query.append("                             mf:result {resultFile}; ");
    query.append("                             mf:action {action} qt:query {queryFile}; ");
    query.append("                                               [qt:data {defaultGraph}] ");
    query.append(" USING NAMESPACE ");
    query.append("  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, ");
    query.append("  dawgt = <http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#>, ");
    query.append("  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
    TupleQuery testCaseQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());

    query.setLength(0);
    query.append(" SELECT graph ");
    query.append(" FROM {action} qt:graphData {graph} ");
    query.append(" USING NAMESPACE ");
    query.append(" qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
    TupleQuery namedGraphsQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());

    query.setLength(0);
    query.append("SELECT 1 ");
    query.append(" FROM {testURI} mf:resultCardinality {mf:LaxCardinality}");
    query.append(" USING NAMESPACE mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>");
    TupleQuery laxCardinalityQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());

    logger.debug("evaluating query..");
    TupleResult testCases = testCaseQuery.evaluate();
    while (testCases.hasNext()) {
      BindingSet bindingSet = testCases.next();

      URI testURI = (URI)bindingSet.getValue("testURI");
      String testName = bindingSet.getValue("testName").toString();
      String resultFile = bindingSet.getValue("resultFile").toString();
      String queryFile = bindingSet.getValue("queryFile").toString();
      URI defaultGraphURI = (URI)bindingSet.getValue("defaultGraph");
      Value action = bindingSet.getValue("action");

      logger.debug("found test case : {}", testName);

      // Query named graphs
      namedGraphsQuery.setBinding("action", action);
      TupleResult namedGraphs = namedGraphsQuery.evaluate();

      DatasetImpl dataset = null;

      if (defaultGraphURI != null || namedGraphs.hasNext()) {
        dataset = new DatasetImpl();

        if (defaultGraphURI != null) {
          dataset.addDefaultGraph(defaultGraphURI);
        }

        while (namedGraphs.hasNext()) {
          BindingSet graphBindings = namedGraphs.next();
          URI namedGraphURI = (URI)graphBindings.getValue("graph");
          dataset.addNamedGraph(namedGraphURI);
        }
      }

      // Check for lax-cardinality conditions
      boolean laxCardinality = false;
      laxCardinalityQuery.setBinding("testURI", testURI);
      TupleResult laxCardinalityResult = laxCardinalityQuery.evaluate();
      try {
        laxCardinality = laxCardinalityResult.hasNext();
      }
      finally {
        laxCardinalityResult.close();
      }

      SPARQLQueryTest test = factory.createSPARQLQueryTest(testURI.toString(), testName, queryFile,
          resultFile, dataset, laxCardinality);
      if (test != null) {
        suite.addTest(test);
      }
    }

    testCases.close();
    con.close();

    manifestRep.shutDown();
    logger.info("Created test suite with " + suite.countTestCases() + " test cases.");
    return suite;
  }

Examples of org.openrdf.repository.RepositoryConnection

    throws Exception
  {
    // DEBUG
    SessionManager.getOrCreate().setUsername("administrator");

    RepositoryConnection conn = repository.getConnection();
    try {
      conn.add(AccessControlSailTest.class.getResource(policyFile), "", RDFFormat.forFileName(policyFile),
          ACL.CONTEXT);
      conn.add(AccessControlSailTest.class.getResource(dataFile), "", RDFFormat.forFileName(dataFile));
    }
    finally {
      conn.close();
    }

    SessionManager.remove();
  }
TOP
Copyright © 2018 www.massapi.com. 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.