public override void Run() { try { StoreWorker.TransactionLog.LogStartTransaction(this); var writeStore = StoreWorker.WriteStore; // process preconditions Logging.LogInfo("UpdateTransaction {0} - processing preconditions", JobId); try { var preconditionSink = new PreconditionSink(writeStore, PreconditionSink.PreconditionType.ExistsPrecondition); var parser = new NTriplesParser(); parser.Parse(new StringReader(_preconditions), preconditionSink, _defaultGraphUri); if (preconditionSink.FailedPreconditionCount > 0) { throw new PreconditionFailedException(preconditionSink.FailedPreconditionCount, preconditionSink.GetFailedPreconditions(), 0, String.Empty); } } catch (RdfParserException parserException) { throw new BrightstarClientException("Syntax error in preconditions.", parserException); } // process deletes Logging.LogInfo("UpdateTransaction {0} - processing deletes", JobId); try { var delSink = new DeletePatternSink(writeStore); var parser = new NTriplesParser(); parser.Parse(new StringReader(_deletePatterns), delSink, _defaultGraphUri); } catch (RdfParserException parserException) { throw new BrightstarClientException("Syntax error in delete patterns.", parserException); } try { // insert data Logging.LogInfo("UpdateTransaction {0} - processing inserts", JobId); var parser = new NTriplesParser(); parser.Parse(new StringReader(_insertData), new StoreTripleSink(writeStore, JobId, Configuration.TransactionFlushTripleCount), _defaultGraphUri); } catch (RdfParserException parserException) { throw new BrightstarClientException("Syntax error in triples to add.", parserException); } // commit changes Logging.LogInfo("UpdateTransaction {0} - committing changes", JobId); writeStore.Commit(JobId); // change read store Logging.LogInfo("UpdateTransaction {0} - invalidating read store", JobId); StoreWorker.InvalidateReadStore(); // log txn completed Logging.LogInfo("UpdateTransaction {0} - logging completion", JobId); StoreWorker.TransactionLog.LogEndSuccessfulTransaction(this); Logging.LogInfo("UpdateTransaction {0} - done", JobId); } catch (PreconditionFailedException ex) { StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogInfo("Preconditions failed in UpdateTransaction ({0}): Count={1}, Triples={2}", JobId, ex.ExistenceFailureCount, ex.ExistenceFailedTriples); throw; } catch (BrightstarClientException ex) { StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogError(BrightstarEventId.TransactionClientError, "Client error reported in UpdateTransaction ({0}): {1}", JobId, ex.InnerException.ToString()); throw; } catch (Exception ex) { StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogError(BrightstarEventId.TransactionServerError, "Unexpected exception caught in UpdateTransaction ({0}): {1}", JobId, ex); throw; } }
public override void Run() { try { StoreWorker.TransactionLog.LogStartTransaction(this); var writeStore = StoreWorker.WriteStore; // process preconditions Logging.LogInfo("UpdateTransaction {0} - processing preconditions", JobId); try { var preconditionSink = new PreconditionSink(writeStore); var parser = new NTriplesParser(); parser.Parse(new StringReader(_preconditions), preconditionSink, _defaultGraphUri); if (preconditionSink.FailedPreconditionCount > 0) { throw new PreconditionFailedException(preconditionSink.FailedPreconditionCount, preconditionSink.GetFailedPreconditions()); } } catch (RdfParserException parserException) { throw new BrightstarClientException("Syntax error in preconditions.", parserException); } // process deletes Logging.LogInfo("UpdateTransaction {0} - processing deletes", JobId); try { var delSink = new DeletePatternSink(writeStore); var parser = new NTriplesParser(); parser.Parse(new StringReader(_deletePatterns), delSink, _defaultGraphUri); } catch (RdfParserException parserException) { throw new BrightstarClientException("Syntax error in delete patterns.", parserException); } try { // insert data Logging.LogInfo("UpdateTransaction {0} - processing inserts", JobId); var parser = new NTriplesParser(); parser.Parse(new StringReader(_insertData), new StoreTripleSink(writeStore, JobId, Configuration.TransactionFlushTripleCount), _defaultGraphUri); } catch (RdfParserException parserException) { throw new BrightstarClientException("Syntax error in triples to add.", parserException); } // commit changes Logging.LogInfo("UpdateTransaction {0} - committing changes", JobId); writeStore.Commit(JobId); // change read store Logging.LogInfo("UpdateTransaction {0} - invalidating read store", JobId); StoreWorker.InvalidateReadStore(); // log txn completed Logging.LogInfo("UpdateTransaction {0} - logging completion", JobId); StoreWorker.TransactionLog.LogEndSuccessfulTransaction(this); Logging.LogInfo("UpdateTransaction {0} - done", JobId); } catch (PreconditionFailedException ex) { StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogInfo("Preconditions failed in UpdateTransaction ({0}): Count={1}, Triples={2}", JobId, ex.FailureCount, ex.FailedTriples); throw; } catch (BrightstarClientException ex) { StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogError(BrightstarEventId.TransactionClientError, "Client error reported in UpdateTransaction ({0}): {1}", JobId, ex.InnerException.ToString()); throw; } catch (Exception ex) { StoreWorker.TransactionLog.LogEndFailedTransaction(this); Logging.LogError(BrightstarEventId.TransactionServerError, "Unexpected exception caught in UpdateTransaction ({0}): {1}",JobId, ex); throw; } }
public void UpdateGraph(string graphUri, IEnumerable<Triple> additions, IEnumerable<Triple> removals) { string uniqueImportId = Guid.NewGuid().ToString(); if (graphUri == null) graphUri = Constants.DefaultGraphUri; if (removals != null) { var deleteSink = new DeletePatternSink(_store); foreach (var removal in removals) { var node = removal.Object as ILiteralNode; if (node != null) { deleteSink.Triple( Stringify(removal.Subject, uniqueImportId), removal.Subject is IBlankNode, Stringify(removal.Predicate, uniqueImportId), removal.Predicate is IBlankNode, node.Value, false, true, node.DataType == null ? null : node.DataType.ToString(), node.Language, removal.GraphUri == null ? graphUri : removal.GraphUri.ToString() ); } else { deleteSink.Triple( Stringify(removal.Subject, uniqueImportId), removal.Subject is IBlankNode, Stringify(removal.Predicate, uniqueImportId), removal.Predicate is IBlankNode, Stringify(removal.Object, uniqueImportId), removal.Object is IBlankNode, false, null, null, removal.GraphUri == null ? graphUri : removal.GraphUri.ToString() ); } } } if (additions != null) { foreach (var addition in additions) { var t = MakeBrighstarTriple(addition, uniqueImportId); t.Graph = graphUri; _store.InsertTriple(t); } } }