Example #1
0
  /**
   * Batch insert statements into the graph
   *
   * @param statements
   * @return true if and only if the query execution was successful
   */
  public boolean batchInsertStatements(Collection<? extends RDFStatement> statements) {
    if (statements == null || statements.isEmpty()) {
      return false;
    }

    try {
      StringBuilder sb = new StringBuilder();
      statements
          .stream()
          .forEach(
              s -> {
                s.setObject(RDFUtils.escapeString(s.getObject()));
                sb.append("INSERT INTO GRAPH <")
                    .append(this.graphName)
                    .append("> { ")
                    .append(s.toString())
                    .append(" };\n");
              });

      VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(sb.toString(), this.graph);
      vur.exec();
      return true;
    } catch (Exception ex) {
      logger.error("Exception while batch inserting statements", ex);
    }
    return false;
  }
Example #2
0
  /**
   * Inserts a statement into the graph
   *
   * @param stmt Statement (RDFStatement triple)
   * @return true if and only if the query execution was successful
   */
  public boolean insertStatement(RDFStatement stmt) {
    if (stmt == null) {
      return false;
    }

    try {
      stmt.setObject(RDFUtils.escapeString(stmt.getObject()));
      String query = "INSERT INTO GRAPH <" + this.graphName + "> { " + stmt.toString() + "}";
      VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(query, this.graph);
      vur.exec();
      return true;
    } catch (Exception ex) {
      logger.error("Exception while inserting a statement", ex);
    }
    return false;
  }
Example #3
0
 /**
  * Delete a statement from a graph
  *
  * @param stmt (RDFStatement triple)
  * @return true if and only if the query execution was successful
  */
 public boolean deleteStatement(RDFStatement stmt) {
   if (stmt == null) {
     return false;
   }
   try {
     stmt.setObject(RDFUtils.escapeString(stmt.getObject()));
     String query =
         String.format(
             "DELETE FROM GRAPH <%s> { %s }",
             this.graphName, RDFUtils.escapeString(stmt.toString()));
     VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(query, this.graph);
     vur.exec();
     return true;
   } catch (Exception ex) {
     logger.error("Exception while deleting a statement", ex);
   }
   return false;
 }