StorageConnector extends AbstractConnector { public void setRepository(Repository newRepository) { Objects.requireNonNull(newRepository); if (!isInMemoryRepository(repository)) { throw new UnsupportedOperationException("Cannot replace repository which is not in-memory."); } if (transaction.isActive()) { throw new IllegalStateException("Cannot replace repository in transaction."); } repository.shutDown(); assert newRepository.isInitialized(); this.repository = newRepository; } StorageConnector(DriverConfiguration configuration); @Override void close(); @Override TupleQueryResult executeSelectQuery(String query); @Override boolean executeBooleanQuery(String query); @Override void executeUpdate(String query); @Override List<Resource> getContexts(); @Override ValueFactory getValueFactory(); @Override void begin(); @Override void commit(); @Override void rollback(); @Override void addStatements(Collection<Statement> statements); @Override void removeStatements(Collection<Statement> statements); @Override Collection<Statement> findStatements(Resource subject, IRI property, Value value, boolean includeInferred); @Override Collection<Statement> findStatements(Resource subject, org.eclipse.rdf4j.model.IRI property,
                                                Value value, boolean includeInferred, IRI context); @Override boolean containsStatement(Resource subject, IRI property, Value value, boolean includeInferred); @Override boolean containsStatement(Resource subject, IRI property, Value value, boolean includeInferred, IRI context); @Override T unwrap(Class<T> cls); void setRepository(Repository newRepository);  }
@Test void setRepositoryThrowsUnsupportedOperationWhenOriginalRepositoryIsNotInMemory() throws Exception { this.repositoryFolder = Files.createTempDirectory("sesame-storage-connector-test").toFile(); connector = new StorageConnector(TestUtils.createDriverConfig(repositoryFolder .getAbsolutePath() + File.separator + "repositories" + File.separator + "test")); final Repository newRepository = new SailRepository(new MemoryStore()); try { final UnsupportedOperationException result = assertThrows(UnsupportedOperationException.class, () -> connector.setRepository(newRepository)); assertEquals("Cannot replace repository which is not in-memory.", result.getMessage()); } finally { newRepository.shutDown(); } }