Example #1
0
 private boolean addRevision(Resource subj) throws SailException {
   if (subj instanceof URI) {
     Resource h = getContainerURI(subj);
     Boolean b = revised.get(h);
     if (b != null && b) return false;
     revised.put(h, Boolean.TRUE);
     if (!subj.equals(trx)) {
       removeAllRevisions(subj);
       super.addStatement(h, REVISION, getTrx(), getTrx());
       if (b == null) {
         super.addStatement(getTrx(), CONTRIBUTED, h, getTrx());
       }
       return true;
     }
   }
   return false;
 }
Example #2
0
 private void storeStatement(Resource subj, URI pred, Value obj, Resource... contexts)
     throws SailException {
   if (subj.equals(currentTrx)) {
     subj = getTrx();
   }
   if (obj.equals(currentTrx)) {
     obj = getTrx();
   }
   if (contexts != null && contexts.length == 1) {
     if (currentTrx.equals(contexts[0])) {
       contexts[0] = getTrx();
     }
   } else if (contexts != null) {
     for (int i = 0; i < contexts.length; i++) {
       if (currentTrx.equals(contexts[i])) {
         contexts[i] = getTrx();
       }
     }
   }
   if (contexts == null || contexts.length == 0 || contexts.length == 1 && contexts[0] == null) {
     addRevision(subj);
     super.addStatement(subj, pred, obj, getTrx());
   } else if (contexts.length == 1) {
     if (contexts[0].equals(trx)) {
       addRevision(subj);
     }
     super.addStatement(subj, pred, obj, contexts);
     Resource ctx = contexts[0];
     if (isURI(ctx) && !ctx.equals(trx) && modified.add(ctx)) {
       addMetadata(currentTrx, MODIFIED, ctx, currentTrx);
     }
   } else {
     for (Resource ctx : contexts) {
       if (ctx == null || ctx.equals(trx)) {
         addRevision(subj);
         break;
       }
     }
     super.addStatement(subj, pred, obj, contexts);
     for (Resource ctx : contexts) {
       if (isURI(ctx) && !ctx.equals(trx) && modified.add(ctx)) {
         addMetadata(currentTrx, MODIFIED, ctx, currentTrx);
       }
     }
   }
 }
Example #3
0
 @Override
 public synchronized void rollback() throws SailException {
   trx = null;
   metadata.clear();
   revised.clear();
   modified.clear();
   arch.clear();
   super.rollback();
 }
Example #4
0
 @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);
         }
       }
     }
   }
 }
Example #5
0
 private void flushArchive() throws SailException {
   if (arch.size() <= sail.getMaxArchive()) {
     for (Statement st : arch) {
       Resource s = st.getSubject();
       URI p = st.getPredicate();
       Value o = st.getObject();
       Resource ctx = st.getContext();
       removeRevision(s, p);
       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());
       if (ctx instanceof URI && modified.add(ctx)) {
         super.addStatement(getTrx(), MODIFIED, ctx, getTrx());
       }
     }
     arch.clear();
   }
 }
Example #6
0
 @Override
 public synchronized void commit() throws SailException {
   flushArchive();
   if (trx != null) {
     for (Statement st : arch) {
       Resource ctx = st.getContext();
       if (ctx instanceof URI) {
         modified.add(ctx);
       }
     }
     for (Resource ctx : modified) {
       if (isObsolete(ctx)) {
         super.addStatement(ctx, RDF.TYPE, Audit.OBSOLETE, trx);
       }
     }
     GregorianCalendar cal = new GregorianCalendar();
     XMLGregorianCalendar xgc = factory.newXMLGregorianCalendar(cal);
     Literal now = vf.createLiteral(xgc);
     super.addStatement(trx, RDF.TYPE, TRANSACTION, trx);
     super.addStatement(trx, COMMITTED_ON, now, trx);
     for (Resource predecessor : predecessors) {
       super.addStatement(trx, PREDECESSOR, predecessor, trx);
     }
     sail.recent(trx, getWrappedConnection());
   }
   super.commit();
   metadata.clear();
   revised.clear();
   modified.clear();
   arch.clear();
   if (trx != null) {
     sail.committed(trx, predecessors);
     predecessors = Collections.singleton(trx);
     trx = null;
   }
 }
Example #7
0
 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();
   }
 }
Example #8
0
 private void reify(URI activity, URI entity, Resource subj, URI pred, Value obj, Resource ctx)
     throws SailException {
   String ns = activity.stringValue();
   if (ctx instanceof URI) {
     super.addStatement(activity, informedBy, ctx, activity);
   }
   if (entity == null || GENERATED_BY.equals(pred.stringValue())) return;
   URI operation = vf.createURI(ns + "#" + hash(ctx, entity));
   if (ctx instanceof URI) {
     super.addStatement(ctx, qualifiedUsage, operation, activity);
   }
   super.addStatement(activity, qualifiedUsage, operation, activity);
   super.addStatement(operation, usedEntity, entity, activity);
   Resource node = vf.createBNode();
   super.addStatement(operation, changed, node, activity);
   super.addStatement(node, subject, subj, activity);
   super.addStatement(node, predicate, pred, activity);
   super.addStatement(node, object, obj, activity);
 }
Example #9
0
 private boolean removeRevision(Resource subj, URI pred) throws SailException {
   if (subj instanceof URI) {
     Resource h = getContainerURI(subj);
     if (revised.containsKey(h)) return false;
     revised.put(h, Boolean.TRUE);
     if (pred != null && !REVISION.equals(pred)) {
       removeAllRevisions(subj);
       addMetadata(h, REVISION, currentTrx, currentTrx);
     } else {
       URI uri = (URI) subj;
       String ns = uri.getNamespace();
       if (ns.charAt(ns.length() - 1) != '#') {
         if (trx != null) {
           super.removeStatements(subj, REVISION, trx, trx);
         }
         revised.put(subj, Boolean.FALSE);
       }
     }
     addMetadata(currentTrx, CONTRIBUTED, h, currentTrx);
     return true;
   }
   return false;
 }
Example #10
0
 private void removeInformingGraph(
     URI activity, URI entity, Resource subj, URI pred, Value obj, Resource ctx)
     throws SailException {
   reify(activity, entity, subj, pred, obj, ctx);
   super.removeStatements(subj, pred, obj, ctx);
 }