org.openrdf.query.Update类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中org.openrdf.query.Update类的一些代码示例,展示了Update类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Update类的具体详情如下:
包路径:org.openrdf.query.Update
类名称:Update

Update介绍

[英]An update operation on a repository that can be formulated in one of the supported query languages (for example SPARQL).
[中]存储库上的更新操作,可以用一种受支持的查询语言(例如SPARQL)表示。

代码示例

代码示例来源:origin: blazegraph/database

private void insertSparql(final BigdataSailRepositoryConnection cxn) throws Exception {
  cxn.prepareUpdate(QueryLanguage.SPARQL, INSERT_SPARQL).execute();
  
}

代码示例来源:origin: blazegraph/database

@Test
public void testInsertNonMatchingWhereWithBindings()
  throws Exception
{
  logger.debug("executing test testInsertNonMatchingWhereWithBindings");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT { ?x rdfs:label ?y . } WHERE { ?x rdfs:comment ?y }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("x", bob);
  operation.setBinding("y", f.createLiteral("Bob"));
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  operation.execute();
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
}

代码示例来源:origin: org.openrdf.sesame/sesame-repository-sail

@Override
public Update prepare(ParsedUpdate graphUpdate) {
  Update update = new SailUpdate(graphUpdate, con);
  update.setIncludeInferred(includeInferred);
  return update;
}

代码示例来源:origin: blazegraph/database

@Test
public void testDeleteDefaultGraph()
  throws Exception
{
  URI g1 = vf.createURI("urn:test:g1");
  URI g2 = vf.createURI("urn:test:g2");
  testCon.add(vf.createURI(URN_TEST_S1), vf.createURI(URN_TEST_P1), vf.createURI(URN_TEST_O1), g1);
  testCon.add(vf.createURI("urn:test:s2"), vf.createURI(URN_TEST_P2), vf.createURI("urn:test:o2"), g2);
  Update up = testCon.prepareUpdate(QueryLanguage.SPARQL, SPARQL_DEL_ALL);
  DatasetImpl ds = new DatasetImpl();
  ds.addDefaultGraph(g1);
  ds.addDefaultRemoveGraph(g1);
  up.setDataset(ds);
  up.execute();
  assertThat(size(g1), is(equalTo(0)));
  assertThat(size(g2), is(equalTo(1)));
}

代码示例来源:origin: blazegraph/database

@Test
public void testDeleteDefaultGraph()
  throws Exception
{
  URI g1 = vf.createURI("urn:test:g1");
  URI g2 = vf.createURI("urn:test:g2");
  testCon.add(vf.createURI(URN_TEST_S1), vf.createURI(URN_TEST_P1), vf.createURI(URN_TEST_O1), g1);
  testCon.add(vf.createURI("urn:test:s2"), vf.createURI(URN_TEST_P2), vf.createURI("urn:test:o2"), g2);
  Update up = testCon.prepareUpdate(QueryLanguage.SPARQL, SPARQL_DEL_ALL);
  DatasetImpl ds = new DatasetImpl();
  ds.addDefaultGraph(g1);
  ds.addDefaultRemoveGraph(g1);
  up.setDataset(ds);
  up.execute();
  assertThat(size(g1), is(equalTo(0)));
  assertThat(size(g2), is(equalTo(1)));
}

代码示例来源:origin: blazegraph/database

/**
 * Update graph using SPARQL Update.
 */
public void update(final String queryStr, final String extQueryId)
    throws Exception {
  
  try {
    
    final Update update = 
        cxn().prepareUpdate(QueryLanguage.SPARQL, queryStr);
    
    update.execute();
    
  } catch (RuntimeException e) {
    throw e;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testInsertNonMatchingWhereWithBindings()
  throws Exception
{
  logger.debug("executing test testInsertNonMatchingWhereWithBindings");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT { ?x rdfs:label ?y . } WHERE { ?x rdfs:comment ?y }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("x", bob);
  operation.setBinding("y", f.createLiteral("Bob"));
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  operation.execute();
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
}

代码示例来源:origin: org.openrdf.sesame/sesame-sail-spin

@Override
public Update prepare(ParsedUpdate graphUpdate) {
  Update update = new SailConnectionUpdate(graphUpdate, con, vf, parserConfig);
  update.setIncludeInferred(includeInferred);
  return update;
}

代码示例来源:origin: blazegraph/database

/**
 * A test which verifies that an exception is NOT thrown if
 * the named solution set does not exist and SILENT is specified.
 */
public void test_dropSolutionSet_02() throws UpdateExecutionException,
    RepositoryException, MalformedQueryException {
  if (!isSolutionSetUpdateEnabled()) {
    /*
     * Test requires this feature.
     */
    return;
  }
  
  con.prepareUpdate(QueryLanguage.SPARQL,
      "drop silent solutions %namedSet1").execute();
}

代码示例来源:origin: blazegraph/database

@Test
public void testInsertEmptyWhereWithBinding()
  throws Exception
{
  logger.debug("executing test testInsertEmptyWhereWithBinding");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT {?x rdfs:label ?y . } WHERE { }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("x", bob);
  operation.setBinding("y", f.createLiteral("Bob"));
  assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  operation.execute();
  assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
}

代码示例来源:origin: blazegraph/database

/**
 * A test which verifies that an exception is NOT thrown if
 * the named solution set does not exist and SILENT is specified.
 */
public void test_clearSolutionSet_02() throws UpdateExecutionException,
    RepositoryException, MalformedQueryException {
  if (!isSolutionSetUpdateEnabled()) {
    /*
     * Test requires this feature.
     */
    return;
  }
  con.prepareUpdate(QueryLanguage.SPARQL,
      "clear silent solutions %namedSet1").execute();
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testInsertEmptyWhereWithBinding()
  throws Exception
{
  logger.debug("executing test testInsertEmptyWhereWithBinding");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT {?x rdfs:label ?y . } WHERE { }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("x", bob);
  operation.setBinding("y", f.createLiteral("Bob"));
  assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
  operation.execute();
  assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bob"), true));
}

代码示例来源:origin: blazegraph/database

@Test
public void testUpdateBaseURI()
  throws Exception
{
  testCon.prepareUpdate(QueryLanguage.SPARQL, "INSERT DATA { <> a <> }", URN_TEST_S1).execute();
  assertThat(testCon.size(), is(equalTo(1L)));
}

代码示例来源:origin: blazegraph/database

@Test
public void testInsertWhereWithBindings()
  throws Exception
{
  logger.debug("executing test testInsertWhereWithBindings");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT { ?x rdfs:comment ?z . } WHERE { ?x foaf:name ?y }");
  Literal comment = f.createLiteral("Bob has a comment");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("x", bob);
  operation.setBinding("z", comment);
  assertFalse(con.hasStatement(null, RDFS.COMMENT, comment, true));
  operation.execute();
  assertTrue(con.hasStatement(bob, RDFS.COMMENT, comment, true));
  assertFalse(con.hasStatement(alice, RDFS.COMMENT, comment, true));
}

代码示例来源:origin: blazegraph/database

/**
 * Verify ability to load data from a gzip resource.
 */
public void testLoadGZip()
    throws Exception
  {

  //Depends on bigdata-rdf test resource
  final URL url = this.getClass().getClassLoader().getResource("com/bigdata/rdf/rio/small.rdf.gz");
  
  final String update = "LOAD <" + url.toExternalForm() + ">";
  
  final String ns = "http://bigdata.com/test/data#";
  
  con.prepareUpdate(QueryLanguage.SPARQL, update).execute();
  assertTrue(con.hasStatement(f.createURI(ns, "mike"), RDFS.LABEL,
      f.createLiteral("Michael Personick"), true));
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testInsertWhereWithBindings()
  throws Exception
{
  logger.debug("executing test testInsertWhereWithBindings");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT { ?x rdfs:comment ?z . } WHERE { ?x foaf:name ?y }");
  Literal comment = f.createLiteral("Bob has a comment");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("x", bob);
  operation.setBinding("z", comment);
  assertFalse(con.hasStatement(null, RDFS.COMMENT, comment, true));
  operation.execute();
  assertTrue(con.hasStatement(bob, RDFS.COMMENT, comment, true));
  assertFalse(con.hasStatement(alice, RDFS.COMMENT, comment, true));
}

代码示例来源:origin: blazegraph/database

@Test
public void testInsertNonMatchingWhere()
  throws Exception
{
  logger.debug("executing test testInsertNonMatchingWhere");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT { ?x rdfs:label ?y . } WHERE { ?x rdfs:comment ?y }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  operation.execute();
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
}

代码示例来源:origin: blazegraph/database

@Test
public void testInsertWhereWithBindings2()
  throws Exception
{
  logger.debug("executing test testInsertWhereWithBindings2");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT {?x rdfs:label ?z . } WHERE {?x foaf:name ?y }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("z", f.createLiteral("Bobbie"));
  operation.setBinding("x", bob);
  assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
  assertFalse(con.hasStatement(alice, RDFS.LABEL, null, true));
  operation.execute();
  assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
  assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testInsertNonMatchingWhere()
  throws Exception
{
  logger.debug("executing test testInsertNonMatchingWhere");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT { ?x rdfs:label ?y . } WHERE { ?x rdfs:comment ?y }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
  operation.execute();
  assertFalse(con.hasStatement(bob, RDFS.LABEL, null, true));
}

代码示例来源:origin: org.openrdf.sesame/sesame-sparql-testsuite

@Test
public void testInsertWhereWithBindings2()
  throws Exception
{
  logger.debug("executing test testInsertWhereWithBindings2");
  StringBuilder update = new StringBuilder();
  update.append(getNamespaceDeclarations());
  update.append("INSERT {?x rdfs:label ?z . } WHERE {?x foaf:name ?y }");
  Update operation = con.prepareUpdate(QueryLanguage.SPARQL, update.toString());
  operation.setBinding("z", f.createLiteral("Bobbie"));
  operation.setBinding("x", bob);
  assertFalse(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
  assertFalse(con.hasStatement(alice, RDFS.LABEL, null, true));
  operation.execute();
  assertTrue(con.hasStatement(bob, RDFS.LABEL, f.createLiteral("Bobbie"), true));
  assertFalse(con.hasStatement(alice, RDFS.LABEL, f.createLiteral("Alice"), true));
}

相关文章

微信公众号

最新文章

更多