コード例 #1
0
ファイル: AuditingConnection.java プロジェクト: stain/alibaba
 @Override
 public synchronized void removeStatements(
     Resource subj, URI pred, Value obj, Resource... contexts) throws SailException {
   if (sail.isArchiving()) {
     CloseableIteration<? extends Statement, SailException> stmts;
     stmts = super.getStatements(subj, pred, obj, false, contexts);
     try {
       while (stmts.hasNext()) {
         Statement st = stmts.next();
         Resource s = st.getSubject();
         URI p = st.getPredicate();
         Value o = st.getObject();
         Resource ctx = st.getContext();
         removeRevision(s, p);
         if (ctx instanceof URI && !ctx.equals(trx)) {
           if (modified.add(ctx)) {
             super.addStatement(getTrx(), MODIFIED, ctx, getTrx());
           }
           BNode node = vf.createBNode();
           super.addStatement(ctx, CONTAINED, node, getTrx());
           super.addStatement(node, RDF.SUBJECT, s, getTrx());
           super.addStatement(node, RDF.PREDICATE, p, getTrx());
           super.addStatement(node, RDF.OBJECT, o, getTrx());
         }
       }
     } finally {
       stmts.close();
     }
     super.removeStatements(subj, pred, obj, contexts);
   } else {
     if (sail.getMaxArchive() > 0 && arch.size() <= sail.getMaxArchive()) {
       CloseableIteration<? extends Statement, SailException> stmts;
       stmts = super.getStatements(subj, pred, obj, false, contexts);
       try {
         int maxArchive = sail.getMaxArchive();
         while (stmts.hasNext() && arch.size() <= maxArchive) {
           Statement st = stmts.next();
           Resource ctx = st.getContext();
           if (ctx instanceof URI && !ctx.equals(trx)) {
             arch.add(st);
           }
         }
       } finally {
         stmts.close();
       }
     }
     super.removeStatements(subj, pred, obj, contexts);
     removeRevision(subj, pred);
     if (contexts != null && contexts.length > 0) {
       for (Resource ctx : contexts) {
         if (ctx != null && modified.add(ctx)) {
           addMetadata(currentTrx, MODIFIED, ctx, currentTrx);
         }
       }
     }
   }
 }
コード例 #2
0
  @Override
  protected void handleClose() throws QueryEvaluationException {
    super.handleClose();

    leftIter.close();
    rightIter.close();

    hashTable = null;
    hashTableValues = null;
    scanList = null;
  }
コード例 #3
0
ファイル: AuditingConnection.java プロジェクト: stain/alibaba
 private void removeInforming(
     URI activity, URI entity, Resource subj, URI pred, Value obj, Resource... contexts)
     throws SailException {
   if (contexts != null && contexts.length == 0) {
     CloseableIteration<? extends Statement, SailException> stmts;
     stmts = super.getStatements(subj, pred, obj, false, contexts);
     try {
       while (stmts.hasNext()) {
         Statement st = stmts.next();
         Resource ctx = st.getContext();
         subj = st.getSubject();
         pred = st.getPredicate();
         obj = st.getObject();
         removeInformingGraph(activity, entity, subj, pred, obj, ctx);
       }
     } finally {
       stmts.close();
     }
   } else if (contexts == null) {
     removeInformingGraph(activity, entity, subj, pred, obj, null);
   } else {
     for (Resource ctx : contexts) {
       removeInformingGraph(activity, entity, subj, pred, obj, ctx);
     }
   }
 }
コード例 #4
0
ファイル: AuditingConnection.java プロジェクト: stain/alibaba
 private boolean isObsolete(Resource ctx) throws SailException {
   CloseableIteration<? extends Statement, SailException> stmts;
   stmts = super.getStatements(null, null, null, true, ctx);
   try {
     while (stmts.hasNext()) {
       Statement st = stmts.next();
       URI pred = st.getPredicate();
       Value obj = st.getObject();
       String ns = pred.getNamespace();
       if (Audit.NAMESPACE.equals(ns) || PROV.equals(ns) || AUDIT_2012.equals(ns)) continue;
       if (RDF.SUBJECT.equals(pred) || RDF.PREDICATE.equals(pred) || RDF.OBJECT.equals(pred))
         continue;
       if (RDF.TYPE.equals(pred) && obj instanceof URI) {
         ns = ((URI) obj).getNamespace();
         if (Audit.NAMESPACE.equals(ns)
             || PROV.equals(ns)
             || AUDIT_2012.equals(ns)
             || RDF.NAMESPACE.equals(ns)) continue;
       }
       return false;
     }
   } finally {
     stmts.close();
   }
   return true;
 }
コード例 #5
0
 public void close() throws QueryEvaluationException {
   try {
     baseIteration.close();
   } catch (SailException e) {
     throw new QueryEvaluationException(e);
   }
 }
コード例 #6
0
ファイル: RepositoryModel.java プロジェクト: stain/alibaba
 public boolean hasNext() {
   try {
     if (stmts.hasNext()) return true;
     stmts.close();
     return false;
   } catch (RepositoryException e) {
     throw new ModelException(e);
   }
 }
コード例 #7
0
  @Override
  public void handleClose() {
    closed = true;

    if (rightIter != null) {
      rightIter.close();
      rightIter = null;
    }
    result.close();
  }
コード例 #8
0
ファイル: RepositoryModel.java プロジェクト: stain/alibaba
 public Statement next() {
   try {
     last = stmts.next();
     if (last == null) {
       stmts.close();
     }
     return last;
   } catch (RepositoryException e) {
     throw new ModelException(e);
   }
 }
コード例 #9
0
  protected void testValueRoundTrip(Resource subj, URI pred, Value obj) throws Exception {
    con.begin();
    con.addStatement(subj, pred, obj);
    con.commit();

    CloseableIteration<? extends Statement, SailException> stIter =
        con.getStatements(null, null, null, false);

    try {
      assertTrue(stIter.hasNext());

      Statement st = stIter.next();
      assertEquals(subj, st.getSubject());
      assertEquals(pred, st.getPredicate());
      assertEquals(obj, st.getObject());
      assertTrue(!stIter.hasNext());
    } finally {
      stIter.close();
    }

    ParsedTupleQuery tupleQuery =
        QueryParserUtil.parseTupleQuery(
            QueryLanguage.SERQL,
            "SELECT S, P, O FROM {S} P {O} WHERE P = <" + pred.stringValue() + ">",
            null);

    CloseableIteration<? extends BindingSet, QueryEvaluationException> iter;
    iter = con.evaluate(tupleQuery.getTupleExpr(), null, EmptyBindingSet.getInstance(), false);

    try {
      assertTrue(iter.hasNext());

      BindingSet bindings = iter.next();
      assertEquals(subj, bindings.getValue("S"));
      assertEquals(pred, bindings.getValue("P"));
      assertEquals(obj, bindings.getValue("O"));
      assertTrue(!iter.hasNext());
    } finally {
      iter.close();
    }
  }
コード例 #10
0
 protected static Value _getObject(Resource subject, URI predicate, SailConnection c)
     throws SailException {
   CloseableIteration<? extends Statement, SailException> i =
       c.getStatements(subject, predicate, null, true);
   try {
     if (i.hasNext()) {
       return i.next().getObject();
     } else {
       return null;
     }
   } finally {
     i.close();
   }
 }
コード例 #11
0
  @Override
  public T getNextElement() {
    while (rightIter != null || result.hasNext()) {
      if (rightIter == null) {
        rightIter = result.next();
      }
      if (rightIter.hasNext()) {
        return rightIter.next();
      } else {
        rightIter.close();
        rightIter = null;
      }
    }

    return null;
  }
コード例 #12
0
  @Test
  public void testGetNamespaces() throws Exception {
    con.begin();
    con.setNamespace("rdf", RDF.NAMESPACE);
    con.commit();

    CloseableIteration<? extends Namespace, SailException> namespaces = con.getNamespaces();
    try {
      assertTrue(namespaces.hasNext());
      Namespace rdf = namespaces.next();
      assertEquals("rdf", rdf.getPrefix());
      assertEquals(RDF.NAMESPACE, rdf.getName());
      assertTrue(!namespaces.hasNext());
    } finally {
      namespaces.close();
    }
  }
コード例 #13
0
ファイル: AuditingConnection.java プロジェクト: stain/alibaba
 private void removeAllRevisions(Resource subj) throws SailException {
   CloseableIteration<? extends Statement, SailException> stmts;
   Resource s = getContainerURI(subj);
   stmts = super.getStatements(s, REVISION, null, true);
   try {
     while (stmts.hasNext()) {
       Statement st = stmts.next();
       Value ctx = st.getObject();
       if (ctx instanceof URI && modified.add((URI) ctx)) {
         addMetadata(getTrx(), MODIFIED, ctx, getTrx());
       }
       super.removeStatements(s, REVISION, ctx);
     }
   } finally {
     stmts.close();
   }
 }
コード例 #14
0
  private void cacheStatements(final Resource subj, final URI pred, final Value obj)
      throws SailException {
    boolean includeInferred = false;

    CloseableIteration<? extends Statement, SailException> iter =
        baseSailConnection.getStatements(subj, pred, obj, includeInferred);

    while (iter.hasNext()) {
      Statement st = iter.next();
      cacheConnection.addStatement(
          st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
    }

    iter.close();

    cacheConnection.commit();
  }
コード例 #15
0
    private void evaluateIntoStatements(ParsedGraphQuery query, Collection<Statement> statements)
        throws SailException, RDFHandlerException, QueryEvaluationException {
      CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter =
          getWrappedConnection()
              .evaluate(query.getTupleExpr(), null, EmptyBindingSet.getInstance(), true);

      try {
        ValueFactory vf = getValueFactory();

        while (bindingsIter.hasNext()) {
          BindingSet bindings = bindingsIter.next();

          Value subj = bindings.getValue("subject");
          Value pred = bindings.getValue("predicate");
          Value obj = bindings.getValue("object");

          if (subj instanceof Resource && pred instanceof IRI && obj != null) {
            statements.add(vf.createStatement((Resource) subj, (IRI) pred, obj));
          }
        }
      } finally {
        bindingsIter.close();
      }
    }
コード例 #16
0
 @Override
 public void release(CloseableIteration<T, QueryEvaluationException> item) {
   item.close();
 }