@Override public void update(Collection<STMT> removedStatements, Collection<STMT> addedStatements) { if (removedStatements != null) { repository.removeStatements(removedStatements); } if (addedStatements != null) { repository.add(addedStatements.toArray(new STMT[addedStatements.size()])); } }
@Override public void export(Format format, UID context, OutputStream out) { export(format, Namespaces.DEFAULT, context, out); }
@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 MultiProperties() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, MultiPropertyTest.class); MultiPropertyTest test = new MultiPropertyTest(); test.names.add("Tom"); test.names.add("Jane"); test.namesList.add("Tom"); test.namesList.add("Jane"); test.namesArray = new String[] { "Tom", "Jane" }; session.save(test); session.clear(); List<STMT> stmts = IteratorAdapter.asList(repository.findStatements(null, NAME, null, null, false)); assertEquals(2, stmts.size()); stmts = IteratorAdapter.asList(repository.findStatements(null, NAME2, null, null, false)); assertEquals(2, stmts.size()); stmts = IteratorAdapter.asList(repository.findStatements(null, NAME3, null, null, false)); assertEquals(2, stmts.size()); MultiPropertyTest test2 = session.get(MultiPropertyTest.class, test.id); assertEquals(test.names, test2.names); // ordering is not preseved assertEquals(Sets.newHashSet(test.namesList), Sets.newHashSet(test2.namesList)); // ordering is not preseved assertEquals(Sets.newHashSet(test.namesArray), Sets.newHashSet(test2.namesArray)); }
@Test(expected = IllegalArgumentException.class) public void Error() { MiniRepository repository = new MiniRepository(); UID id = new UID("http://example2.com/abc"); UID type = new UID(TEST.NS, "IdMappingTest"); repository.add(new STMT(id, RDF.type, type)); Session session = SessionUtil.openSession(repository, IdMappingTest.class); session.get(IdMappingTest.class, id); }
@Override public CloseableIterator<STMT> findStatements(ID subject, UID predicate, NODE object, UID context, boolean includeInferred) { if (logger.isDebugEnabled()) { logger.debug("find " + subject + " " + predicate + " " + object + " " + context); } return repository.findStatements(subject, predicate, object, context, includeInferred); }
@Override public void remove(ID subject, UID predicate, NODE object, UID context) { repository.remove(subject, predicate, object, context); }
@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(); }
@Override public Repository createRepository() { return new MiniRepository(); } };
public void addStatements(STMT... stmts) { this.repository.add(stmts); }
@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); } }
@Test public void Success() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, IdMappingTest.class); IdMappingTest instance = new IdMappingTest(); instance.id = "abc"; session.save(instance); session.clear(); UID id = new UID("http://example.com/abc"); assertTrue(repository.exists(id, null, null, null)); IdMappingTest instance2 = session.get(IdMappingTest.class, id); assertEquals(instance.id, instance2.id); }
@Override public boolean exists(ID subject, UID predicate, NODE object, UID context, boolean includeInferred) { if (logger.isDebugEnabled()) { logger.debug("exists " + subject + " " + predicate + " " + object + " " + context); } return repository.exists(subject, predicate, object, context); }
@SuppressWarnings("unchecked") public CloseableIterator<STMT> findStatements(@Nullable ID subject, @Nullable UID predicate, @Nullable NODE object, @Nullable UID context, boolean includeInferred) { Iterator<STMT> iterator = null; if (subject != null) { iterator = getIndexed(subject, predicate, subjects); } else if (objects != null && object != null && object.isResource()) { iterator = getIndexed(object.asResource(), predicate, objects); } else { List<Iterator<STMT>> iterators = Lists.newArrayList(); for (PredicateCache stmtCache : subjects.values()) { iterators.add(stmtCache.iterator(predicate)); } iterator = Iterators.concat(iterators.toArray(new Iterator[iterators.size()])); } return new ResultIterator(iterator, subject, predicate, object, context, includeInferred); }
@After public void after() { repository.clear(); }
@AfterClass public static void afterClass() { try { // if (sessionFactory != null) sessionFactory.close(); if (repository != null) repository.close(); } finally { // sessionFactory = null; repository = null; } }
@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 Persistence() { MiniRepository repository = new MiniRepository(); Session session = SessionUtil.openSession(repository, Entity.class); Entity entity = new Entity(); entity.name = "John Doe"; session.save(entity); session.flush(); assertFalse(repository.findStatements(null, CORE.localId, null, null, false).hasNext()); } }
@Test public void ClassReference() { MiniRepository repository = new MiniRepository(); repository.add( new STMT(new UID(TEST.NS, "domainType"), RDF.type, new UID(TEST.NS, "DomainType")) ); Session session = SessionUtil.openSession(repository, DomainType.class); Command command = new Command(); assertNull(command.domainType); session.autowire(command); assertNotNull(command.domainType); assertNotNull(command.domainType.parametrizedClass); assertTrue(DomainType.class.isAssignableFrom(command.domainType.parametrizedClass)); }