Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-1006

How read and add triples to `Graph` at the same time?

    XMLWordPrintableJSON

    Details

    • Type: Question
    • Status: Closed
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: Jena 2.13.0
    • Fix Version/s: Jena 3.0.1
    • Component/s: Core, TDB
    • Labels:
      None

      Description

      Here is my code:

      public class App {
          public static void main(String[] args) {
              DatasetGraph datasetGraph = TDBFactory.createDatasetGraph();
              Graph graph = datasetGraph.getDefaultGraph();
      
              // Fill graph.
              graph.add(
                  new Triple(
                      NodeFactory.createURI("www.test.org/unit13"),
                      NodeFactory.createURI("name"),
                      NodeFactory.createLiteral("Unit 13", "en")
                  )
              );
      
              graph.add(
                  new Triple(
                      NodeFactory.createURI("www.test.org/unit13"),
                      NodeFactory.createURI("type"),
                      NodeFactory.createURI("robot")
                  )
              );
      
              graph.add(
                  new Triple(
                      NodeFactory.createURI("www.test.org/unit13"),
                      NodeFactory.createURI("creationYear"),
                      NodeFactory.createURI("2015")
                  )
              );
      
              // Test
              ExtendedIterator<Triple> iter = graph.find(
                  Node.ANY,
                  NodeFactory.createURI("creationYear"),
                  NodeFactory.createURI("2015")
              );
      
              while (iter.hasNext()) {
                  Triple triple = iter.next();
                  Node subject = triple.getSubject();
      
                  // Exception here.
                  graph.add(
                      new Triple(
                          subject, NodeFactory.createURI("status"), NodeFactory.createURI("available")
                      )
                  );
              }
          }
      }
      

      This code gives me exception:

      Exception in thread "main" java.util.ConcurrentModificationException: Iterator: started at 8, now 9
          at com.hp.hpl.jena.tdb.sys.DatasetControlMRSW.policyError(DatasetControlMRSW.java:157)
          at com.hp.hpl.jena.tdb.sys.DatasetControlMRSW.access$000(DatasetControlMRSW.java:32)
          at com.hp.hpl.jena.tdb.sys.DatasetControlMRSW$IteratorCheckNotConcurrent.checkCourrentModification(DatasetControlMRSW.java:110)
          at com.hp.hpl.jena.tdb.sys.DatasetControlMRSW$IteratorCheckNotConcurrent.hasNext(DatasetControlMRSW.java:118)
          at org.apache.jena.atlas.iterator.Iter$4.hasNext(Iter.java:318)
          at org.apache.jena.atlas.iterator.Iter$4.hasNext(Iter.java:318)
          at org.apache.jena.atlas.iterator.Iter$4.hasNext(Iter.java:318)
          at org.apache.jena.atlas.iterator.Iter.hasNext(Iter.java:942)
          at com.hp.hpl.jena.util.iterator.WrappedIterator.hasNext(WrappedIterator.java:90)
          at com.github.hronom.test.jena.App.main(App.java:48)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
      

      I accept this.
      But how I must change code, to add meta info <status> <available> to every <www.test.org/unit13> that has <creationYear> <2015>?

      Test project on GitHub

      Please help me

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Hronom Eugene Tenkaev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: