@Test public void testGetTriplesGraph() throws Exception { TcProvider provider = getInstance(); Graph graph = provider.createGraph(graphIRI); Graph tc = provider.getGraph(graphIRI); assertNotNull(tc); provider.deleteGraph(graphIRI); }
@Test public void testCreateGraphExtended() throws Exception { TcProvider provider = getInstance(); Graph graph = provider.createGraph(graphIRI); assertNotNull(graph); //get a new provider and check that graph is there provider = getInstance(); graph = provider.getGraph(graphIRI); assertNotNull(graph); //check that there is no such graph, but only the mgraph boolean expThrown = false; try { ImmutableGraph g = provider.getImmutableGraph(graphIRI); } catch(NoSuchEntityException e) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(graphIRI); }
@Test public void testCreateImmutableGraphExtended() throws Exception { TcProvider provider = getInstance(); ImmutableGraph graph = provider.createImmutableGraph(graphIRI, null); assertNotNull(graph); //get a new provider and check that graph is there provider = getInstance(); graph = provider.getImmutableGraph(graphIRI); assertNotNull(graph); //check that there is no such mgraph, but only the graph boolean expThrown = false; try { Graph g = provider.getMGraph(graphIRI); } catch(NoSuchEntityException e) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(graphIRI); }
OntologyToTcMapper() { if (store == null) throw new IllegalArgumentException("TcProvider cannot be null"); try { graph = store.createMGraph(graphId); } catch (EntityAlreadyExistsException e) { graph = store.getMGraph(graphId); } }
OntologyToTcMapper() { if (store == null) throw new IllegalArgumentException("TcProvider cannot be null"); IRI graphId = new IRI(metaGraphId); try { graph = store.createGraph(graphId); } catch (EntityAlreadyExistsException e) { graph = store.getGraph(graphId); } }
@Test public void testCreateGraphNoDuplicateNames2() throws Exception { TcProvider provider = getInstance(); Graph graph = provider.createGraph(graphIRI); assertNotNull(graph); boolean expThrown = false; try { Graph other = provider.createGraph(otherGraphIRI); } catch(EntityAlreadyExistsException eaee) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(graphIRI); }
@Test public void testCreateGraphNoDuplicateNames() throws Exception { TcProvider provider = getInstance(); ImmutableGraph graph = provider.createImmutableGraph(graphIRI, null); assertNotNull(graph); boolean expThrown = false; try { ImmutableGraph other = provider.createImmutableGraph(otherGraphIRI, null); } catch(EntityAlreadyExistsException eaee) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(graphIRI); }
@Test public void testGetTriples() { TcProvider simpleTcmProvider = getInstance(); // add Graphs Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB)); simpleTcmProvider.createImmutableGraph(uriRefB, mGraph); // add Graphs mGraph = simpleTcmProvider.createGraph(uriRefA1); mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1)); mGraph = simpleTcmProvider.createGraph(uriRefB1); mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1)); // get a ImmutableGraph Graph tripleCollection = simpleTcmProvider.getGraph(uriRefA); // get a Graph Graph tripleCollection2 = simpleTcmProvider.getGraph(uriRefB1); Iterator<Triple> iterator = tripleCollection.iterator(); assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next()); assertFalse(iterator.hasNext()); iterator = tripleCollection2.iterator(); assertEquals(new TripleImpl(uriRefB1, uriRefB1, uriRefB1), iterator.next()); assertFalse(iterator.hasNext()); simpleTcmProvider.deleteGraph(uriRefA); simpleTcmProvider.deleteGraph(uriRefA1); simpleTcmProvider.deleteGraph(uriRefB); simpleTcmProvider.deleteGraph(uriRefB1); }
@Test public void testGraphDeletion() throws Exception { Graph triples = createTestTripleCollection(createTestTriple()); TcProvider provider = getInstance(); IRI name1 = new IRI("http://myGraph1"); ImmutableGraph graph = provider.createImmutableGraph(name1, triples); IRI name2 = new IRI("http://myGraph2"); ImmutableGraph secondGraph = provider.createImmutableGraph(name2, triples); //if we delete graph with name1, the second graph should still be there provider.deleteGraph(name1); provider = getInstance(); ImmutableGraph firstGraph = provider.getImmutableGraph(name2); assertNotNull(firstGraph); //check second name is not there boolean expThrown = false; try { ImmutableGraph g = provider.getImmutableGraph(name1); } catch(NoSuchEntityException nses) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(name2); }
@Test public void testDeleteEntity() { TcProvider simpleTcmProvider = getInstance(); Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); ImmutableGraph graph = mGraph.getImmutableGraph(); simpleTcmProvider.createImmutableGraph(uriRefA, graph); simpleTcmProvider.createImmutableGraph(uriRefC, graph); simpleTcmProvider.deleteGraph(uriRefA); try { simpleTcmProvider.getGraph(uriRefA); assertTrue(false); } catch (NoSuchEntityException e) { assertTrue(true); } // Check that graph is still available under uriRefC ImmutableGraph cGraph = simpleTcmProvider.getImmutableGraph(uriRefC); assertNotNull(cGraph); simpleTcmProvider.deleteGraph(uriRefC); }
if (!force && graphName != null && store.listGraphs().contains(graphName)) { boolean condition = true; // Any failed check will abort the scan. Graph tc = store.getGraph(graphName); OWLOntologyID idFromStore = OWLUtils.extractOntologyID(tc); condition &= (extractedId == null && idFromStore == null) || extractedId.equals(idFromStore); targetGraph = store.getGraph(graphName); } else { String iri = null; log.debug("Storing ontology with graph ID {}", graphName); try { targetGraph = store.createGraph(graphName); } catch (EntityAlreadyExistsException e) { if (graphName.equals(e.getEntityName())) targetGraph = store.getGraph(graphName); else targetGraph = store.createGraph(graphName);
@Override public void deleteGraph(IRI name) { for (TcProvider provider : providerList) { try { provider.deleteGraph(name); final MGraphHolder holder = mGraphCache.get(name); if ((holder != null) && (holder.getWeightedTcProvider() != null) && holder.getWeightedTcProvider().equals(provider)) { tcDisappears(name); mGraphCache.remove(name); } return; } catch (UnsupportedOperationException e) { // we do nothing and try our luck with the next provider } catch (NoSuchEntityException e) { //we do nothing and try our luck with the next provider } catch (IllegalArgumentException e) { //we do nothing and try our luck with the next provider } } // this throws a NoSuchEntityException if the ImmutableGraph doesn't exist getGraph(name); // the entity exists but cannot be deleted throw new UnsupportedOperationException( "No provider could delete the entity."); }
@SuppressWarnings("unchecked") @Override public <O extends Graph> O getMetaGraph(Class<O> returnType) { if (!Graph.class.isAssignableFrom(returnType)) throw new IllegalArgumentException( "Only subtypes of " + Graph.class + " are allowed."); return (O) store.getGraph(new IRI(metaGraphId)); }
@Override public Set<IRI> listGraphs() { Set<IRI> result = new HashSet<IRI>(); for (TcProvider provider : providerList) { result.addAll(provider.listGraphs()); } return result; }
if (!getStore().listTripleCollections().contains(uriref) || force) { try { graph = store.createMGraph(uriref); } catch (EntityAlreadyExistsException e) { if (uriref.equals(e.getEntityName())) graph = store.getMGraph(uriref); else graph = store.createMGraph(uriref); graph = store.getTriples(uriref);
@Override public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException { for (TcProvider provider : providerList) { try { return provider.getImmutableGraph(name); } catch (NoSuchEntityException e) { //we do nothing and try our luck with the next provider } catch (IllegalArgumentException e) { //we do nothing and try our luck with the next provider } } throw new NoSuchEntityException(name); }
@Test public void testCreateGraphNoDuplicateNames2() throws Exception { TcProvider provider = getInstance(); Graph graph = provider.createGraph(graphIRI); assertNotNull(graph); boolean expThrown = false; try { Graph other = provider.createGraph(otherGraphIRI); } catch(EntityAlreadyExistsException eaee) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(graphIRI); }
@Test public void testCreateGraphNoDuplicateNames() throws Exception { TcProvider provider = getInstance(); ImmutableGraph graph = provider.createImmutableGraph(graphIRI, null); assertNotNull(graph); boolean expThrown = false; try { ImmutableGraph other = provider.createImmutableGraph(otherGraphIRI, null); } catch(EntityAlreadyExistsException eaee) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(graphIRI); }
@Test public void testGetTriples() { TcProvider simpleTcmProvider = getInstance(); // add Graphs Graph mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA)); simpleTcmProvider.createImmutableGraph(uriRefA, mGraph); mGraph = new SimpleGraph(); mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB)); simpleTcmProvider.createImmutableGraph(uriRefB, mGraph); // add Graphs mGraph = simpleTcmProvider.createGraph(uriRefA1); mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1)); mGraph = simpleTcmProvider.createGraph(uriRefB1); mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1)); // get a ImmutableGraph Graph tripleCollection = simpleTcmProvider.getGraph(uriRefA); // get a Graph Graph tripleCollection2 = simpleTcmProvider.getGraph(uriRefB1); Iterator<Triple> iterator = tripleCollection.iterator(); assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next()); assertFalse(iterator.hasNext()); iterator = tripleCollection2.iterator(); assertEquals(new TripleImpl(uriRefB1, uriRefB1, uriRefB1), iterator.next()); assertFalse(iterator.hasNext()); simpleTcmProvider.deleteGraph(uriRefA); simpleTcmProvider.deleteGraph(uriRefA1); simpleTcmProvider.deleteGraph(uriRefB); simpleTcmProvider.deleteGraph(uriRefB1); }
@Test public void testGraphDeletion() throws Exception { Graph triples = createTestTripleCollection(createTestTriple()); TcProvider provider = getInstance(); IRI name1 = new IRI("http://myGraph1"); ImmutableGraph graph = provider.createImmutableGraph(name1, triples); IRI name2 = new IRI("http://myGraph2"); ImmutableGraph secondGraph = provider.createImmutableGraph(name2, triples); //if we delete graph with name1, the second graph should still be there provider.deleteGraph(name1); provider = getInstance(); ImmutableGraph firstGraph = provider.getImmutableGraph(name2); assertNotNull(firstGraph); //check second name is not there boolean expThrown = false; try { ImmutableGraph g = provider.getImmutableGraph(name1); } catch(NoSuchEntityException nses) { expThrown = true; } assertTrue(expThrown); provider.deleteGraph(name2); }