示例#1
0
  @Override
  public void remove(Iterable<Statement> triples, String namedGraphURI) {
    for (Statement stmt : triples)
      try {
        if (namedGraphURI == null) {
          connection.removeStatements(stmt.getSubject(), stmt.getPredicate(), stmt.getObject());
        } else {
          connection.removeStatements(
              stmt.getSubject(),
              stmt.getPredicate(),
              stmt.getObject(),
              new ValueFactoryImpl().createURI(namedGraphURI));
        }
      } catch (SailException e) {
        try {
          connection.rollback();
        } catch (SailException e1) {
          e1.printStackTrace();
        }
      }

    try {
      connection.commit();
    } catch (SailException e) {
      e.printStackTrace();
    }
  }
示例#2
0
 @Override
 public void delete(String graphURI) {
   try {
     if (graphURI == null) {
       connection.clear();
       connection.commit();
     } else {
       connection.clear(new ValueFactoryImpl().createURI(graphURI));
       connection.commit();
     }
   } catch (SailException e) {
     e.printStackTrace();
     try {
       connection.rollback();
     } catch (SailException e1) {
       e1.printStackTrace();
     }
   }
 }
 public void rollback() throws SailException {
   if (config.logTransactions) {
     queryHandler.handle(new RollbackCall(id));
   }
   baseSailConnection.rollback();
 }
 protected void rollbackInternal() throws SailException {
   baseSailConnection.rollback();
 }
  public static void postProcess(
      Map<String, NativeObject> types,
      Map<String, NativeObject> properties,
      List<NativeObject> items,
      String urlSpec,
      Sail dataSail,
      Sail metaSail)
      throws Exception {
    Map<String, Resource> typeIDToResource = new HashMap<String, Resource>();
    Map<String, Resource> propertyIDToResource = new HashMap<String, Resource>();

    String baseURL = _getBaseURL(urlSpec);
    Literal origin = (urlSpec == null || urlSpec.length() == 0) ? null : new LiteralImpl(urlSpec);

    SailConnection metaConnection = metaSail.getConnection();
    try {
      for (String typeID : types.keySet()) {
        Resource typeResource = _processType(typeID, types.get(typeID), baseURL, metaConnection);
        if (origin != null) {
          metaConnection.addStatement(typeResource, ExhibitOntology.ORIGIN, origin);
        }

        typeIDToResource.put(typeID, typeResource);
      }

      for (String propertyID : properties.keySet()) {
        if (!propertyID.equals("type")
            && !propertyID.equals("label")
            && !propertyID.equals("uri")
            && !propertyID.equals("id")) {

          Resource propertyResource =
              _processProperty(propertyID, properties.get(propertyID), baseURL, metaConnection);
          if (origin != null) {
            metaConnection.addStatement(propertyResource, ExhibitOntology.ORIGIN, origin);
          }

          propertyIDToResource.put(propertyID, propertyResource);
        }
      }

      metaConnection.commit();

      Map<String, String> itemIDToURI = new HashMap<String, String>();
      for (NativeObject itemNO : items) {
        String uri = _getStringProperty(itemNO, "uri");
        if (uri != null) {
          String id = _getStringProperty(itemNO, "id");
          if (id == null) {
            id = _getStringProperty(itemNO, "label");
          }
          if (id != null) {
            itemIDToURI.put(id, uri);
          }
        }
      }

      SailConnection dataConnection = dataSail.getConnection();
      try {
        for (NativeObject itemNO : items) {
          Resource itemResource =
              _processItem(itemNO, baseURL, dataConnection, metaConnection, itemIDToURI);
          if (origin != null) {
            dataConnection.addStatement(itemResource, ExhibitOntology.ORIGIN, origin);
          }
        }

        dataConnection.commit();
      } catch (Exception e) {
        dataConnection.rollback();
        throw e;
      } finally {
        dataConnection.close();
      }
    } catch (Exception e) {
      metaConnection.rollback();
      throw e;
    } finally {
      metaConnection.close();
    }
  }