Eugene Tenkaev created JENA-1006:
------------------------------------
Summary: How read and add triples to `Graph` at the same time?
Key: JENA-1006
URL: https://issues.apache.org/jira/browse/JENA-1006
Project: Apache Jena
Issue Type: Question
Components: Core, TDB
Affects Versions: Jena 2.13.0
Reporter: Eugene Tenkaev
Here is my code:
{code:java}
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")
)
);
}
}
}
{code}
This code gives me exception:
{noformat}
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)
{noformat}
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|https://github.com/Hronom/test-jena]
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)