public static void close(RepositoryConnection connection) throws SesameRepositoryFailure { if(connection==null) { return; } try { connection.close(); } catch (RepositoryException e) { throw new SesameRepositoryFailure("Could not close connection",e); } }
public static RepositoryConnection getConnection(Repository repository) throws SesameRepositoryFailure { Objects.requireNonNull(repository, "Repository cannot be null"); if(!repository.isInitialized()) { throw new IllegalStateException("Template support has been disposed"); } try { return repository.getConnection(); } catch(RepositoryException e) { throw new SesameRepositoryFailure(COULD_NOT_CONNECT_TO_THE_REPOSITORY,e); } }
public static String prettyPrint(RepositoryConnection connection, Resource... contexts) throws SesameUtilsException { try { StringWriter writer = new StringWriter(); connection.export(new TurtlePrettyPrinter(writer), contexts); return writer.toString(); } catch(RepositoryException e) { throw new SesameRepositoryFailure(COULD_NOT_SERIALIZE_CONTENTS,e); } catch (RDFHandlerException e) { throw new SesameUtilsAssertionError("Unexpected pretty printer failure",e); } catch(UnsupportedRDFormatException e) { throw new SesameUtilsAssertionError(TURTLE_FORMAT_SHOULD_BE_SUPPORTED, e); } }
@Override public void visitString(Source<String> source) throws SesameUtilsException { StringReader reader=new StringReader(source.getData()); try { if(context!=null) { connection.add(reader, base, RDFFormat.TURTLE,context); } else { connection.add(reader, base, RDFFormat.TURTLE); } } catch (IOException e) { throw new ContentProcessingException(READ_EXCEPTION, e); } catch (RDFParseException e) { throw new ContentProcessingException(PARSE_EXCEPTION, e); } catch (RepositoryException e) { throw new SesameRepositoryFailure(STORAGE_EXCEPTION, e); } finally { reader.close(); } } }
private void loadFrom(URL url) throws SesameUtilsException { try { if(context!=null) { connection.add(url, base, RDFFormat.TURTLE,context); } else { connection.add(url, base, RDFFormat.TURTLE); } } catch (IOException e) { throw new ContentProcessingException(READ_EXCEPTION, e); } catch (RDFParseException e) { throw new ContentProcessingException(PARSE_EXCEPTION, e); } catch (RepositoryException e) { throw new SesameRepositoryFailure(STORAGE_EXCEPTION, e); } }