@Test public void testExportStatements() throws Exception { Resource context1 = conn.getValueFactory().createURI("http: ValueFactory f= conn.getValueFactory(); final URI alice = f.createURI("http: URI name = f.createURI("http: Literal alicesName = f.createLiteral("Alice"); Statement st1 = f.createStatement(alice, name, alicesName); conn.add(st1, context1); ByteArrayOutputStream out = new ByteArrayOutputStream(); RDFXMLWriter rdfWriter = new RDFXMLWriter(out); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<rdf:RDF\n" + "\txmlns:rdf=\"http: "\n" + "<rdf:Description rdf:about=\"http: "\t<name xmlns=\"http: "</rdf:Description>\n" + "\n" + "</rdf:RDF>"; conn.exportStatements(alice, null, alicesName, true, rdfWriter, context1); Assert.assertEquals(expected, out.toString()); conn.clear(context1); }
@Override public void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { StringBuilder ob = new StringBuilder(); StringBuilder sb = new StringBuilder(); if(notNull(object) && object instanceof Literal) { if (object instanceof Literal) { Literal lit = (Literal) object; ob.append("\""); ob.append(SPARQLUtil.encodeString(lit.getLabel())); ob.append("\""); ob.append("^^<" + lit.getDatatype().stringValue() + ">"); ob.append(" "); } else { ob.append("<" + object.stringValue() + "> "); } sb.append("CONSTRUCT {?s ?p "+ob.toString()+"} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(notNull(contexts[i])) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p " + ob.toString() + " .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p "+ob.toString()+" .}"); } } sb.append("}"); }else{ sb.append("?s ?p "+ob.toString()+" }"); } }else{ sb.append("CONSTRUCT {?s ?p ?o} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(contexts[i] != null) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p ?o .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p ?o .}"); } } sb.append("}"); }else{ sb.append("?s ?p ?o }"); } } logger.debug(sb.toString()); MarkLogicGraphQuery query = prepareGraphQuery(sb.toString()); setBindings(query, subject, predicate, object, contexts); query.evaluate(handler); } catch (MalformedQueryException e) { throw new RepositoryException(e); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } }
MarkLogicRepositoryConnection extends RepositoryConnectionBase implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { StringBuilder ob = new StringBuilder(); StringBuilder sb = new StringBuilder(); if(notNull(object) && object instanceof Literal) { if (object instanceof Literal) { Literal lit = (Literal) object; ob.append("\""); ob.append(SPARQLUtil.encodeString(lit.getLabel())); ob.append("\""); ob.append("^^<" + lit.getDatatype().stringValue() + ">"); ob.append(" "); } else { ob.append("<" + object.stringValue() + "> "); } sb.append("CONSTRUCT {?s ?p "+ob.toString()+"} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(notNull(contexts[i])) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p " + ob.toString() + " .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p "+ob.toString()+" .}"); } } sb.append("}"); }else{ sb.append("?s ?p "+ob.toString()+" }"); } }else{ sb.append("CONSTRUCT {?s ?p ?o} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(contexts[i] != null) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p ?o .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p ?o .}"); } } sb.append("}"); }else{ sb.append("?s ?p ?o }"); } } logger.debug(sb.toString()); MarkLogicGraphQuery query = prepareGraphQuery(sb.toString()); setBindings(query, subject, predicate, object, contexts); query.evaluate(handler); } catch (MalformedQueryException e) { throw new RepositoryException(e); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } } }
MarkLogicRepositoryConnection extends RepositoryConnectionBase implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { StringBuilder ob = new StringBuilder(); StringBuilder sb = new StringBuilder(); if(notNull(object) && object instanceof Literal) { if (object instanceof Literal) { Literal lit = (Literal) object; ob.append("\""); ob.append(SPARQLUtil.encodeString(lit.getLabel())); ob.append("\""); ob.append("^^<" + lit.getDatatype().stringValue() + ">"); ob.append(" "); } else { ob.append("<" + object.stringValue() + "> "); } sb.append("CONSTRUCT {?s ?p "+ob.toString()+"} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(notNull(contexts[i])) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p " + ob.toString() + " .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p "+ob.toString()+" .}"); } } sb.append("}"); }else{ sb.append("?s ?p "+ob.toString()+" }"); } }else{ sb.append("CONSTRUCT {?s ?p ?o} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(contexts[i] != null) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p ?o .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p ?o .}"); } } sb.append("}"); }else{ sb.append("?s ?p ?o }"); } } logger.debug(sb.toString()); MarkLogicGraphQuery query = prepareGraphQuery(sb.toString()); setBindings(query, subject, predicate, object, contexts); query.evaluate(handler); } catch (MalformedQueryException e) { throw new RepositoryException(e); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); }
MarkLogicRepositoryConnection extends RepositoryConnectionBase implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { StringBuilder ob = new StringBuilder(); StringBuilder sb = new StringBuilder(); if(notNull(object) && object instanceof Literal) { if (object instanceof Literal) { Literal lit = (Literal) object; ob.append("\""); ob.append(SPARQLUtil.encodeString(lit.getLabel())); ob.append("\""); ob.append("^^<" + lit.getDatatype().stringValue() + ">"); ob.append(" "); } else { ob.append("<" + object.stringValue() + "> "); } sb.append("CONSTRUCT {?s ?p "+ob.toString()+"} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(notNull(contexts[i])) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p " + ob.toString() + " .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p "+ob.toString()+" .}"); } } sb.append("}"); }else{ sb.append("?s ?p "+ob.toString()+" }"); } }else{ sb.append("CONSTRUCT {?s ?p ?o} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(contexts[i] != null) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p ?o .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p ?o .}"); } } sb.append("}"); }else{ sb.append("?s ?p ?o }"); } } logger.debug(sb.toString()); MarkLogicGraphQuery query = prepareGraphQuery(sb.toString()); setBindings(query, subject, predicate, object, contexts); query.evaluate(handler); } catch (MalformedQueryException e) { throw new RepositoryException(e); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override /** * Releases the connection to the database. Ensures that open transactions * are complete. Stops write cache Timer. */ void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, URI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, URI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, URI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, URI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, URI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize); }
MarkLogicRepositoryConnection extends RepositoryConnectionBase implements RepositoryConnection,MarkLogicRepositoryConnectionDependent { @Override public void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { try { StringBuilder ob = new StringBuilder(); StringBuilder sb = new StringBuilder(); if(notNull(object) && object instanceof Literal) { if (object instanceof Literal) { Literal lit = (Literal) object; ob.append("\""); ob.append(SPARQLUtil.encodeString(lit.getLabel())); ob.append("\""); ob.append("^^<" + lit.getDatatype().stringValue() + ">"); ob.append(" "); } else { ob.append("<" + object.stringValue() + "> "); } sb.append("CONSTRUCT {?s ?p "+ob.toString()+"} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(notNull(contexts[i])) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p " + ob.toString() + " .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p "+ob.toString()+" .}"); } } sb.append("}"); }else{ sb.append("?s ?p "+ob.toString()+" }"); } }else{ sb.append("CONSTRUCT {?s ?p ?o} WHERE {"); if(notNull(contexts) && contexts.length>0) { for (int i = 0; i < contexts.length; i++) { if(contexts[i] != null) { sb.append("GRAPH <" + contexts[i].stringValue() + "> {?s ?p ?o .} "); }else{ sb.append("GRAPH <"+DEFAULT_GRAPH_URI+"> {?s ?p ?o .}"); } } sb.append("}"); }else{ sb.append("?s ?p ?o }"); } } logger.debug(sb.toString()); MarkLogicGraphQuery query = prepareGraphQuery(sb.toString()); setBindings(query, subject, predicate, object, contexts); query.evaluate(handler); } catch (MalformedQueryException e) { throw new RepositoryException(e); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } } MarkLogicRepositoryConnection(MarkLogicRepository repository, MarkLogicClient client, boolean quadMode); @Override ValueFactory getValueFactory(); void setValueFactory(ValueFactory f); @Override /** * Releases the connection to the database. Ensures that open transactions * are complete. Stops write cache Timer. */ void close(); @Override Query prepareQuery(String queryString); @Override Query prepareQuery(String queryString, String baseURI); @Override Query prepareQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicQuery prepareQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(String queryString,String baseURI); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicTupleQuery prepareTupleQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(String queryString,String baseURI); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicGraphQuery prepareGraphQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(String queryString,String baseURI); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString); @Override MarkLogicBooleanQuery prepareBooleanQuery(QueryLanguage queryLanguage, String queryString, String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(String queryString); @Override MarkLogicUpdateQuery prepareUpdate(String queryString,String baseURI); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString); @Override MarkLogicUpdateQuery prepareUpdate(QueryLanguage queryLanguage, String queryString, String baseURI); @Override RepositoryResult<Resource> getContextIDs(); RepositoryResult<Statement> getStatements(Resource subj, URI pred, Value obj, boolean includeInferred); @Override RepositoryResult<Statement> getStatements(Resource subj, URI pred, Value obj, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Statement st, boolean includeInferred, Resource... contexts); @Override boolean hasStatement(Resource subject, URI predicate, Value object, boolean includeInferred, Resource... contexts); @Override void export(RDFHandler handler, Resource... contexts); @Override void exportStatements(Resource subject, URI predicate, Value object, boolean includeInferred, RDFHandler handler, Resource... contexts); @Override long size(); @Override long size(Resource... contexts); @Override void clear(); @Override void clear(Resource... contexts); @Override boolean isEmpty(); @Override boolean isOpen(); @Override boolean isActive(); @Override IsolationLevel getIsolationLevel(); @Override void setIsolationLevel(IsolationLevel level); @Override void begin(); @Override void begin(IsolationLevel level); @Override void commit(); @Override void rollback(); @Override void add(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts); @Override void add(Resource subject, URI predicate, Value object, Resource... contexts); @Override void add(Statement st, Resource... contexts); @Override void add(Iterable<? extends Statement> statements, Resource... contexts); @Override void add(Iteration<? extends Statement, E> statements, Resource... contexts); @Override void remove(Resource subject, URI predicate, Value object, Resource... contexts); @Override void remove(Statement st, Resource... contexts); @Override void remove(Iterable<? extends Statement> statements); @Override void remove(Iterable<? extends Statement> statements, Resource... contexts); @Override void remove(Iteration<? extends Statement, E> statements); @Override void remove(Iteration<? extends Statement, E> statements, Resource... contexts); @Override RepositoryResult<Namespace> getNamespaces(); @Override String getNamespace(String prefix); @Override void setNamespace(String prefix, String name); @Override void removeNamespace(String prefix); @Override void clearNamespaces(); @Override void setDefaultGraphPerms(GraphPermissions graphPerms); @Override GraphPermissions getDefaultGraphPerms(); @Override void setDefaultConstrainingQueryDefinition(QueryDefinition queryDef); @Override QueryDefinition getDefaultConstrainingQueryDefinition(); @Override void setDefaultRulesets(SPARQLRuleset ... ruleset ); @Override SPARQLRuleset[] getDefaultRulesets(); @Override void sync(); @Override void configureWriteCache(long initDelay, long delayCache, long cacheSize);  }