@Override public <RT> RT execute(RDFConnectionCallback<RT> operation) { RDFConnection connection = openConnection(); try { try { return operation.doInConnection(connection); } finally { connection.close(); } } catch (IOException io) { throw new RepositoryException(io); } }
@Before public void setUp() { MiniRepository repository = new MiniRepository(); MultiConnection connection = new MultiConnection(repository.openConnection(), repository.openConnection()); RDFBeanTransaction innerTx = EasyMock.createNiceMock(RDFBeanTransaction.class); tx = new MultiTransaction(connection, new RDFBeanTransaction[] { innerTx }); }
@Test public void Update_with_nulls() { RDFConnection conn = new MiniRepository().openConnection(); conn.update(Collections.<STMT> emptySet(), null); conn.update(null, Collections.<STMT> emptySet()); conn.update(null, null); }
@Test public void ToString() { MiniConnection connection = new MiniRepository().openConnection(); RDFQuery query = new RDFQueryImpl(connection); query.where(QNODE.s.a(RDFS.Resource)); assertEquals( "SELECT * WHERE { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> } ", query.toString().replaceAll("\\s+", " ")); }
@Test public void ToString_After_Invocation() { MiniConnection connection = new MiniRepository().openConnection(); RDFQuery query = new RDFQueryImpl(connection); query.where(QNODE.s.a(RDFS.Resource)); query.createBooleanQuery(); assertEquals( "SELECT * WHERE { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> } ", query.toString().replaceAll("\\s+", " ")); }
@Test public void Remove_With_Context() { MiniConnection conn = new MiniRepository().openConnection(); STMT stmt1 = new STMT(RDF.type, RDF.type, RDF.type); STMT stmt2 = new STMT(RDF.type, RDF.type, RDF.type, RDF.type); conn.update(null, Arrays.asList(stmt1, stmt2)); conn.update(Collections.singleton(stmt2), null); assertFalse(conn.exists(null, null, null, RDF.type, false)); assertTrue(conn.exists(RDF.type, RDF.type, RDF.type, null, false)); }
@Override public void export(Format format, Map<String, String> ns2prefix, UID context, OutputStream out) { RDFWriter writer = WriterUtils.createWriter(format, out, ns2prefix); RDFConnection conn = openConnection(); try { CloseableIterator<STMT> stmts = conn.findStatements(null, null, null, context, false); try { writer.begin(); while (stmts.hasNext()) { writer.handle(stmts.next()); } writer.end(); } finally { stmts.close(); } } finally { conn.close(); } }
@Test public void test() throws IOException { MultiConnection connection = new MultiConnection(repository.openConnection(), repository.openConnection()); // find CloseableIterator<STMT> stmts = connection.findStatements(null, null, null, null, false); assertFalse(stmts.hasNext()); stmts.close(); // update connection.update( Collections.<STMT> emptySet(), Collections.<STMT> singleton(dialect.createStatement(RDFS.label, RDF.type, RDF.Property))); // find again stmts = connection.findStatements(RDFS.label, RDF.type, null, null, false); assertTrue(stmts.hasNext()); stmts.close(); // close connection.close(); }
@BeforeClass public static void beforeClass() throws IOException { repository = new MiniRepository(); repository.initialize(); // enums Set<STMT> added = new HashSet<STMT>(); for (NoteType nt : NoteType.values()) { added.add(new STMT( new UID(TEST.NS, nt.name()), CORE.enumOrdinal, new LIT(String.valueOf(nt.ordinal()), XSD.integerType))); } RDFConnection connection = repository.openConnection(); connection.update(Collections.<STMT> emptySet(), added); connection.close(); }
@Before public void setUp() { metadata = new DefaultQueryMetadata(); RDFConnection connection = new MiniRepository().openConnection(); Configuration configuration = new DefaultConfiguration(User.class); Ontology ontology = new ConfigurationOntology(configuration); Session session = new SessionImpl(configuration, new ConfigurationOntology(configuration), connection); builder = new RDFQueryBuilder(connection, session, configuration, ontology, metadata); query = new QueryMixin(metadata); }
@Test public void Remove() { MiniConnection conn = new MiniRepository().openConnection(); conn.addStatements(new STMT(new BID(), RDF.type, RDFS.Resource)); assertTrue(conn.exists(null, null, null, null, false)); conn.remove(null, null, null, null); assertFalse(conn.exists(null, null, null, null, false)); }
@Test @Ignore // inverse properties are not stored public void testInverseIDMapping() { Song song = new Song(); MusicStore musicStore = new MusicStore(); SongPlayback songPlayback = new SongPlayback(); ID songLID = session.save(song); ID musicStoreLID = session.save(musicStore); session.flush(); song = session.get(Song.class, songLID); musicStore = session.get(MusicStore.class, musicStoreLID); session.clear(); songPlayback.datetime = new DateTime(); songPlayback.song = song.id; songPlayback.store = musicStore.id; session.save(songPlayback); session.flush(); session.clear(); MiniConnection conn = repository.openConnection(); assertTrue(conn.exists(null, new UID("http://www.foo.com#musicStore"), null, null, true)); assertTrue(conn.exists(null, new UID("http://www.foo.com#playback"), null, null, true)); conn.close(); } }