/** * Get a {@link Model} containing all elements obtained from the specified * query result. * * @since 2.7.0 * @param iteration * the source iteration to get the statements from. This can be a * {@link GraphQueryResult}, a {@link RepositoryResult<Statement>}, or * any other instance of {@link CloseableIteration<Statement>} * @return a {@link Model} containing all statements obtained from the * specified source iteration. */ public static Model asModel(CloseableIteration<? extends Statement, ? extends OpenRDFException> iteration) throws QueryEvaluationException { Model model = new LinkedHashModel(); addAll(iteration, model); return model; }
@Override public void write(DataSource ds) { RepositoryConnection conn = null; try { conn = repo.getConnection(); RepositoryResult<Resource> contexts = conn.getContextIDs(); while (contexts.hasNext()) { Resource context = contexts.next(); LOG.info("Writing context {}", context); RepositoryResult<Statement> statements = conn.getStatements(null, null, null, true, context); Model model = new LinkedHashModel(); QueryResults.addAll(statements, model); copyNamespacesToModel(conn, model); String outname = context.toString(); write(model, outputStream(ds, outname)); } } catch (RepositoryException x) { throw new TripleStoreException(String.format("Writing on %s", ds), x); } finally { if (conn != null) { try { conn.close(); } catch (RepositoryException x) { LOG.error("Writing on {}. Closing repository connection", ds); } } } }