Package org.openrdf.repository.sail

Examples of org.openrdf.repository.sail.SailRepositoryConnection


  private Repository createMember(String id)
    throws StoreException, RDFParseException, IOException
  {
    SailRepository member = new SailRepository(new MemoryStore());
    member.initialize();
    SailRepositoryConnection con = member.getConnection();
    try {
      String resource = "testcases/federation-member-" + id + ".ttl";
      con.add(cl.getResource(resource), "", RDFFormat.TURTLE);
      reference.add(cl.getResource(resource), "", RDFFormat.TURTLE);
    }
    finally {
      con.close();
    }
    return member;
  }
View Full Code Here


     * @throws RDFParseException if the stream is invalid (e.g. does not fit with the syntax)
     * @throws IOException
     */
    public void load(InputStream inStream, RDFFormat forFileName) throws RDFParseException, IOException {
        try {
            final SailRepositoryConnection con = repository.getConnection();
            try {
                con.begin();

                final Resource[] ctx;
                if (context != null) {
                    ctx = new Resource[] { con.getValueFactory().createURI(context) };
                } else {
                    ctx = new Resource[] {};
                }

                con.add(inStream, baseUri, forFileName, ctx);

                con.commit();
            } finally {
                if (con.isActive()) {
                    con.rollback();
                }
                con.close();
            }
        } catch (RepositoryException re) {
            log.error("RepositoryException: {}", re.getMessage());
        }
    }
View Full Code Here

          ScriptableArrayBuilder lenses = new ScriptableArrayBuilder();
         
          int count = 0;
         
          try {
              SailRepositoryConnection connection = (SailRepositoryConnection)
                  database.getRepository().getConnection();
             
              try {
                  TupleQuery query = _builder.makeTupleQuery(_itemVar, connection);
                  TupleQueryResult queryResult = query.evaluate();
                  try {
                      while (queryResult.hasNext()) {
                          BindingSet bindingSet = queryResult.next();
                          Value v = bindingSet.getValue(_itemVar.getName());
                          if (v instanceof URI) {
                              if (count < 20) {
                                String itemID = database.getItemId((URI) v);
                                  itemIDs.add(itemID);
                                  lenses.add(_context.generateLens(itemID));
                              }
                              count++;
                          }
                      }
                  } finally {
                      queryResult.close();
                  }
              } finally {
                  connection.close();
              }
          } catch (Exception e) {
              _logger.error("Error querying for restricted items", e);
          }
         
View Full Code Here

//    String encoding = EncodingDetector.detect(file);
//    String contents = EncodingDetector.getString(file, encoding);
   
    SailRepository myRepository = new SailRepository(new MemoryStore());
    myRepository.initialize();
    SailRepositoryConnection con = myRepository.getConnection();
    con.add(file, "", RDFFormat.TURTLE);
   
    RepositoryResult<Statement> result = con.getStatements(null, new URIImpl("http://isi.edu/integration/karma/dev#hasWorksheetHistory"), null, false);
    if(result.hasNext()) {
      Statement stmt = result.next();
      String history = stmt.getObject().stringValue();
      return new JSONArray(history);
    }
View Full Code Here

    @Override
    protected Object internalRun() {
          Database database = _context.getDatabase();
          try {
              SailRepositoryConnection connection = (SailRepositoryConnection)
                  database.getRepository().getConnection();
             
              try {
                  Group2 group = new Group2(_builder.makeFilterTupleExpr());
                  group.addGroupElement(new GroupElem(_countVar.getName(), new Count(_itemVar)));
                  group.addGroupBindingName(_valueVar.getName());
                 
                  ProjectionElemList projectionElements = new ProjectionElemList();
                  projectionElements.addElement(new ProjectionElem(_valueVar.getName()));
                  projectionElements.addElement(new ProjectionElem(_countVar.getName()));
                 
                  Projection projection = new Projection(group, projectionElements);
                  Order order = "value".equals(_sortMode) ?
                      new Order(projection, new OrderElem(_valueVar, "forward".equals(_sortDirection))) :
                      new Order(projection, new OrderElem(_countVar, !"forward".equals(_sortDirection)));
                 
                  TupleQuery query = new MyTupleQuery(new ParsedTupleQuery(order), connection);
                  TupleQueryResult queryResult = query.evaluate();
                  try {
                    return createComponentState(queryResult);
                  } finally {
                      queryResult.close();
                  }
              } finally {
                  connection.close();
              }
          } catch (Exception e) {
              _logger.error("Error querying to compute list facet", e);
          }
          return null;
View Full Code Here

                  connection.close();
              }
               
            Lens lens = _lensRegistry.getLens(typeId);
           
              SailRepositoryConnection connection2 = (SailRepositoryConnection) database.getRepository().getConnection();
              try {
                lens.render(itemURI, result, database, connection2);
              } finally {
                  connection2.close();
              }
          } catch (Exception e) {
              _logger.error("Error generating lens for " + _itemID, e);
              result.put("error", result, e.toString());
          }
View Full Code Here

        errSalt = UUID.randomUUID().toString();
       
        subject = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));
        predicate = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));

        final SailRepositoryConnection con = repository.getConnection();
        try {
            final ValueFactory vf = con.getValueFactory();

            con.add(vf.createStatement(subject, predicate, vf.createLiteral(text)));

            con.commit();
        } finally {
            con.close();
        }
    }
View Full Code Here

    @Before
    public void loadData() throws RepositoryException, RDFParseException, IOException {
        super.loadData("data.n3", RDFFormat.N3);
        resource = repository.getValueFactory().createURI(NSS.get("ex") + "Simple");
        prop2 = createURI("foo", "simple");
        final SailRepositoryConnection con = repository.getConnection();
        con.begin();
        con.add(resource, prop2, con.getValueFactory().createLiteral("Und sein Name war <strong>&quot;K&ouml;nig Ruprecht&quot;</stron>"));
        con.commit();
        con.close();
      
    }
View Full Code Here

        errSalt = UUID.randomUUID().toString();
       
        subject = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));
        predicate = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));

        final SailRepositoryConnection con = repository.getConnection();
        try {
            final ValueFactory vf = con.getValueFactory();

            con.add(vf.createStatement(subject, predicate, vf.createLiteral(text)));

            con.commit();
        } finally {
            con.close();
        }
    }
View Full Code Here

    protected final void loadData(String datafile, RDFFormat format, String baseURI) throws RepositoryException, RDFParseException, IOException {
        // load demo data
        InputStream data = this.getClass().getResourceAsStream(datafile);
        Assert.assertThat("Could not load test-data: " + datafile, data, notNullValue(InputStream.class));

        final SailRepositoryConnection con = repository.getConnection();
        try {

            con.add(data, baseURI, format);

            con.commit();
        } finally {
            con.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.openrdf.repository.sail.SailRepositoryConnection

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.