Exemple #1
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;
  }
Exemple #2
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;
 }