/// <summary> /// Evaluates the Command in the given Context /// </summary> /// <param name="context">Evaluation Context</param> public abstract void Evaluate(SparqlUpdateEvaluationContext context);
/// <summary> /// Executes a single Update Command against the Triple Store /// </summary> /// <param name="update">SPARQL Update Command</param> public void ExecuteUpdate(SparqlUpdateCommand update) { SparqlUpdateEvaluationContext context = new SparqlUpdateEvaluationContext(new InMemoryDataset(this)); update.Evaluate(context); }
/// <summary> /// Executes a set of Update Commands against the Triple Store /// </summary> /// <param name="updates">SPARQL Update Command Set</param> public void ExecuteUpdate(SparqlUpdateCommandSet updates) { SparqlUpdateEvaluationContext context = new SparqlUpdateEvaluationContext(new InMemoryDataset(this)); for (int i = 0; i < updates.CommandCount; i++) { updates[i].Evaluate(context); } }
/// <summary> /// Processes an INSERT DATA command. /// </summary> /// <param name="cmd">Insert Data Command.</param> /// <param name="context">SPARQL Update Evaluation Context.</param> protected virtual void ProcessInsertDataCommandInternal(InsertDataCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }
/// <summary> /// Processes a MOVE command. /// </summary> /// <param name="cmd">Move Command.</param> /// <param name="context">SPARQL Update Evaluation Context.</param> protected virtual void ProcessMoveCommandInternal(MoveCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }
/// <summary> /// Processes a command set. /// </summary> /// <param name="commands">Command Set.</param> /// <remarks> /// Invokes <see cref="LeviathanUpdateProcessor.ProcessCommand">ProcessCommand()</see> on each command in turn. /// </remarks> public void ProcessCommandSet(SparqlUpdateCommandSet commands) { commands.UpdateExecutionTime = null; // Firstly check what Transaction mode we are running in bool autoCommit = _autoCommit; // Then create an Evaluation Context SparqlUpdateEvaluationContext context = GetContext(commands); // Remember to handle the Thread Safety // If the Dataset is Thread Safe use its own lock otherwise use our local lock ReaderWriterLockSlim currLock = (_dataset is IThreadSafeDataset) ? ((IThreadSafeDataset)_dataset).Lock : _lock; try { currLock.EnterWriteLock(); // Regardless of the Transaction Mode we turn auto-commit off for a command set so that individual commands // don't try and commit after each one is applied i.e. either we are in auto-commit mode and all the // commands must be evaluated before flushing/discarding the changes OR we are not in auto-commit mode // so turning it off doesn't matter as it is already turned off _autoCommit = false; if (autoCommit) { // Do a Flush() before we start to ensure changes from any previous commands are persisted _dataset.Flush(); } // Start the operation context.StartExecution(); for (int i = 0; i < commands.CommandCount; i++) { ProcessCommandInternal(commands[i], context); // Check for Timeout context.CheckTimeout(); } if (autoCommit) { // Do a Flush() when command set completed successfully to persist the changes _dataset.Flush(); } // Set Update Times context.EndExecution(); commands.UpdateExecutionTime = new TimeSpan(context.UpdateTimeTicks); } catch { if (autoCommit) { // Do a Discard() when a command set fails to discard the changes _dataset.Discard(); } else { _canCommit = false; } // Set Update Times context.EndExecution(); commands.UpdateExecutionTime = new TimeSpan(context.UpdateTimeTicks); throw; } finally { // Reset auto-commit setting and release our write lock _autoCommit = autoCommit; currLock.ExitWriteLock(); } }
/// <summary> /// Processes a command. /// </summary> /// <param name="cmd">Command.</param> /// <param name="context">SPARQL Update Evaluation Context.</param> /// <remarks> /// Invokes the type specific method for the command type. /// </remarks> private void ProcessCommandInternal(SparqlUpdateCommand cmd, SparqlUpdateEvaluationContext context) { // If auto-committing then Flush() any existing Transaction first if (_autoCommit) { Flush(); } // Then if possible attempt to get the lock and determine whether it needs releasing ReaderWriterLockSlim currLock = (_dataset is IThreadSafeDataset) ? ((IThreadSafeDataset)_dataset).Lock : _lock; bool mustRelease = false; try { if (!currLock.IsWriteLockHeld) { currLock.EnterWriteLock(); mustRelease = true; } // Then based on the command type call the appropriate protected method switch (cmd.CommandType) { case SparqlUpdateCommandType.Add: ProcessAddCommandInternal((AddCommand)cmd, context); break; case SparqlUpdateCommandType.Clear: ProcessClearCommandInternal((ClearCommand)cmd, context); break; case SparqlUpdateCommandType.Copy: ProcessCopyCommandInternal((CopyCommand)cmd, context); break; case SparqlUpdateCommandType.Create: ProcessCreateCommandInternal((CreateCommand)cmd, context); break; case SparqlUpdateCommandType.Delete: ProcessDeleteCommandInternal((DeleteCommand)cmd, context); break; case SparqlUpdateCommandType.DeleteData: ProcessDeleteDataCommandInternal((DeleteDataCommand)cmd, context); break; case SparqlUpdateCommandType.Drop: ProcessDropCommandInternal((DropCommand)cmd, context); break; case SparqlUpdateCommandType.Insert: ProcessInsertCommandInternal((InsertCommand)cmd, context); break; case SparqlUpdateCommandType.InsertData: ProcessInsertDataCommandInternal((InsertDataCommand)cmd, context); break; case SparqlUpdateCommandType.Load: ProcessLoadCommandInternal((LoadCommand)cmd, context); break; case SparqlUpdateCommandType.Modify: ProcessModifyCommandInternal((ModifyCommand)cmd, context); break; case SparqlUpdateCommandType.Move: ProcessMoveCommandInternal((MoveCommand)cmd, context); break; default: throw new SparqlUpdateException("Unknown Update Commands cannot be processed by the Leviathan Update Processor"); } // If auto-committing flush after every command if (_autoCommit) { Flush(); } } catch { // If auto-committing discard if an error occurs, if not then mark the transaction as uncomittable if (_autoCommit) { Discard(); } else { _canCommit = false; } throw; } finally { // Release locks if necessary if (mustRelease) { currLock.ExitWriteLock(); } } }
/// <summary> /// Processes a command /// </summary> /// <param name="cmd">Command</param> /// <param name="context">SPARQL Update Evaluation Context</param> /// <remarks> /// Invokes the type specific method for the command type /// </remarks> private void ProcessCommandInternal(SparqlUpdateCommand cmd, SparqlUpdateEvaluationContext context) { //If auto-committing then Flush() any existing Transaction first if (this._autoCommit) this.Flush(); //Then if possible attempt to get the lock and determine whether it needs releasing #if !NO_RWLOCK ReaderWriterLockSlim currLock = (this._dataset is IThreadSafeDataset) ? ((IThreadSafeDataset)this._dataset).Lock : this._lock; #endif bool mustRelease = false; try { #if !NO_RWLOCK if (!currLock.IsWriteLockHeld) { currLock.EnterWriteLock(); mustRelease = true; } #else //If ReaderWriteLockSlim is not available use a Monitor instead Monitor.Enter(this._dataset); mustRelease = true; #endif //Then based on the command type call the appropriate protected method switch (cmd.CommandType) { case SparqlUpdateCommandType.Add: this.ProcessAddCommandInternal((AddCommand)cmd, context); break; case SparqlUpdateCommandType.Clear: this.ProcessClearCommandInternal((ClearCommand)cmd, context); break; case SparqlUpdateCommandType.Copy: this.ProcessCopyCommandInternal((CopyCommand)cmd, context); break; case SparqlUpdateCommandType.Create: this.ProcessCreateCommandInternal((CreateCommand)cmd, context); break; case SparqlUpdateCommandType.Delete: this.ProcessDeleteCommandInternal((DeleteCommand)cmd, context); break; case SparqlUpdateCommandType.DeleteData: this.ProcessDeleteDataCommandInternal((DeleteDataCommand)cmd, context); break; case SparqlUpdateCommandType.Drop: this.ProcessDropCommandInternal((DropCommand)cmd, context); break; case SparqlUpdateCommandType.Insert: this.ProcessInsertCommandInternal((InsertCommand)cmd, context); break; case SparqlUpdateCommandType.InsertData: this.ProcessInsertDataCommandInternal((InsertDataCommand)cmd, context); break; case SparqlUpdateCommandType.Load: this.ProcessLoadCommandInternal((LoadCommand)cmd, context); break; case SparqlUpdateCommandType.Modify: this.ProcessModifyCommandInternal((ModifyCommand)cmd, context); break; case SparqlUpdateCommandType.Move: this.ProcessMoveCommandInternal((MoveCommand)cmd, context); break; default: throw new SparqlUpdateException("Unknown Update Commands cannot be processed by the Leviathan Update Processor"); } //If auto-committing flush after every command if (this._autoCommit) this.Flush(); } catch { //If auto-committing discard if an error occurs, if not then mark the transaction as uncomittable if (this._autoCommit) { this.Discard(); } else { this._canCommit = false; } throw; } finally { //Release locks if necessary if (mustRelease) { #if !NO_RWLOCK currLock.ExitWriteLock(); #else Monitor.Exit(this._dataset); #endif } } }
/// <summary> /// Processes a MOVE command /// </summary> /// <param name="cmd">Move Command</param> /// <param name="context">SPARQL Update Evaluation Context</param> protected virtual void ProcessMoveCommandInternal(MoveCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }
/// <summary> /// Processes an INSERT DATA command /// </summary> /// <param name="cmd">Insert Data Command</param> /// <param name="context">SPARQL Update Evaluation Context</param> protected virtual void ProcessInsertDataCommandInternal(InsertDataCommand cmd, SparqlUpdateEvaluationContext context) { cmd.Evaluate(context); }