示例#1
0
 @Override
 public void remove(List<Statement> statements) {
   Model graph = null;
   GraphConnection graphConnection = null;
   try {
     graphConnection = openGraph();
     graph = graphConnection.getGraph();
     graph.enterCriticalSection(Lock.WRITE);
     for (Statement nuxStmt : statements) {
       com.hp.hpl.jena.graph.Node subject = getJenaNode(nuxStmt.getSubject());
       com.hp.hpl.jena.graph.Node predicate = getJenaNode(nuxStmt.getPredicate());
       com.hp.hpl.jena.graph.Node object = getJenaNode(nuxStmt.getObject());
       Triple jenaTriple = Triple.create(subject, predicate, object);
       com.hp.hpl.jena.rdf.model.Statement jenaStmt = graph.asStatement(jenaTriple);
       graph.remove(jenaStmt);
       // remove properties
       RSIterator it = graph.listReifiedStatements(jenaStmt);
       while (it.hasNext()) {
         ReifiedStatement rs = it.nextRS();
         rs.removeProperties();
       }
       // remove quadlets
       graph.removeAllReifications(jenaStmt);
       // graph.removeReification(reifiedStmt);
     }
   } finally {
     if (graph != null) {
       graph.leaveCriticalSection();
     }
     if (graphConnection != null) {
       graphConnection.close();
     }
   }
 }
 @Override
 public void consume() throws RepositoryException {
   while (stream.hasNext()) {
     final Statement t = m.asStatement(stream.next());
     LOGGER.debug("Operating on triple {}.", t);
     operateOnTriple(t);
   }
 }
示例#3
0
  @Override
  public void add(List<Statement> statements) {
    Model graph = null;
    GraphConnection graphConnection = null;
    try {
      graphConnection = openGraph();
      graph = graphConnection.getGraph();
      graph.enterCriticalSection(Lock.WRITE);
      for (Statement nuxStmt : statements) {
        com.hp.hpl.jena.graph.Node subject = getJenaNode(nuxStmt.getSubject());
        com.hp.hpl.jena.graph.Node predicate = getJenaNode(nuxStmt.getPredicate());
        com.hp.hpl.jena.graph.Node object = getJenaNode(nuxStmt.getObject());
        Triple jenaTriple = Triple.create(subject, predicate, object);
        com.hp.hpl.jena.rdf.model.Statement jenaStmt = graph.asStatement(jenaTriple);

        // properties
        Map<Resource, Node[]> properties = nuxStmt.getProperties();
        if (properties == null || properties.isEmpty()) {
          // no properties
          graph.add(jenaStmt);
        } else {
          List<com.hp.hpl.jena.rdf.model.Statement> stmts =
              new ArrayList<com.hp.hpl.jena.rdf.model.Statement>();
          stmts.add(jenaStmt);
          // create reified statement if it does not exist
          com.hp.hpl.jena.graph.Node reifiedStmt = graph.getAnyReifiedStatement(jenaStmt).asNode();
          for (Map.Entry<Resource, Node[]> property : properties.entrySet()) {
            com.hp.hpl.jena.graph.Node prop = getJenaNode(property.getKey());
            for (Node node : property.getValue()) {
              com.hp.hpl.jena.graph.Node value = getJenaNode(node);
              Triple propTriple = Triple.create(reifiedStmt, prop, value);
              stmts.add(graph.asStatement(propTriple));
            }
          }
          graph.add(stmts);
        }
      }
    } finally {
      if (graph != null) {
        graph.leaveCriticalSection();
      }
      if (graphConnection != null) {
        graphConnection.close();
      }
    }
  }
 @Test
 public void testWriteTo() throws WebApplicationException, IllegalArgumentException, IOException {
   final Triple t =
       create(createURI("info:test"), createURI("property:test"), createURI("info:test"));
   final RdfStream rdfStream = new RdfStream(t).session(mockSession);
   byte[] result;
   try (ByteArrayOutputStream entityStream = new ByteArrayOutputStream(); ) {
     testProvider.writeTo(
         rdfStream,
         RdfStream.class,
         null,
         null,
         MediaType.valueOf("application/rdf+xml"),
         null,
         entityStream);
     result = entityStream.toByteArray();
   }
   final Model postSerialization =
       createDefaultModel().read(new ByteArrayInputStream(result), null);
   assertTrue(
       "Didn't find our triple!", postSerialization.contains(postSerialization.asStatement(t)));
 }