//#region ObjectManagersResolver //class ObjectManagersResolver : IObjectManagerResolver { // private readonly Transaction transaction; // public ObjectManagersResolver(Transaction transaction) { // this.transaction = transaction; // } // public IEnumerable<IObjectManager> ResolveAll() { // return new IObjectManager[] { // transaction.schemaManager, // transaction.tableManager, // transaction.sequenceManager, // transaction.variableManager, // transaction.viewManager, // transaction.triggerManager // }; // } // public IObjectManager ResolveForType(DbObjectType objType) { // if (objType == DbObjectType.Schema) // return transaction.schemaManager; // if (objType == DbObjectType.Table) // return transaction.tableManager; // if (objType == DbObjectType.Sequence) // return transaction.sequenceManager; // if (objType == DbObjectType.Variable) // return transaction.variableManager; // if (objType == DbObjectType.View) // return transaction.viewManager; // if (objType == DbObjectType.Trigger) // return transaction.triggerManager; // return null; // } //} //#endregion #region Variables /* * void IVariableScope.OnVariableDefined(Variable variable) { * if (variable.Name.Equals(TransactionSettingKeys.CurrentSchema, StringComparison.OrdinalIgnoreCase)) { * currentSchema = variable.Value; * } else if (variable.Name.Equals(TransactionSettingKeys.ReadOnly, StringComparison.OrdinalIgnoreCase)) { * if (dbReadOnly) * throw new InvalidOperationException("The database is read-only: cannot change access of the transaction."); * * // TODO: handle special cases like "ON", "OFF", "ENABLE" and "DISABLE" * readOnly = ParseBoolean(variable.Value); * } else if (variable.Name.Equals(TransactionSettingKeys.IgnoreIdentifiersCase, StringComparison.OrdinalIgnoreCase)) { * ignoreCase = ParseBoolean(variable.Value); * } else if (variable.Name.Equals(TransactionSettingKeys.AutoCommit, StringComparison.OrdinalIgnoreCase)) { * autoCommit = ParseBoolean(variable.Value); * } else if (variable.Name.Equals(TransactionSettingKeys.ParameterStyle, StringComparison.OrdinalIgnoreCase)) { * parameterStyle = variable.Value; * } else if (variable.Name.Equals(TransactionSettingKeys.IsolationLevel, StringComparison.OrdinalIgnoreCase)) { * var isolation = ParseIsolationLevel(variable.Value); * //TODO: support multiple isolations! * if (isolation != IsolationLevel.Serializable) * throw new NotSupportedException(); * } * } * * private static IsolationLevel ParseIsolationLevel(DataObject value) { * var s = value.Value.ToString(); * if (String.Equals(s, "serializable", StringComparison.OrdinalIgnoreCase)) * return IsolationLevel.Serializable; * if (String.Equals(s, "read committed", StringComparison.OrdinalIgnoreCase)) * return IsolationLevel.ReadCommitted; * if (String.Equals(s, "read uncommitted", StringComparison.OrdinalIgnoreCase)) * return IsolationLevel.ReadUncommitted; * if (String.Equals(s, "snapshot", StringComparison.OrdinalIgnoreCase)) * return IsolationLevel.Snapshot; * * return IsolationLevel.Unspecified; * } * * private static bool ParseBoolean(DataObject value) { * if (value.Type is BooleanType) * return value; * if (value.Type is StringType) { * var s = value.Value.ToString(); * if (String.Equals(s, "true", StringComparison.OrdinalIgnoreCase) || * String.Equals(s, "on", StringComparison.OrdinalIgnoreCase)) * return true; * if (String.Equals(s, "false", StringComparison.OrdinalIgnoreCase) || * String.Equals(s, "off", StringComparison.OrdinalIgnoreCase)) * return false; * } else if (value.Type is NumericType) { * int i = value; * if (i == 0) * return false; * if (i == 1) * return true; * } * * throw new NotSupportedException(); * } * * void IVariableScope.OnVariableDropped(Variable variable) { * if (variable.Name.Equals(TransactionSettingKeys.CurrentSchema, StringComparison.OrdinalIgnoreCase)) { * currentSchema = Database.DatabaseContext.DefaultSchema(); * } else if (variable.Name.Equals(TransactionSettingKeys.ReadOnly, StringComparison.OrdinalIgnoreCase)) { * readOnly = dbReadOnly; * } else if (variable.Name.Equals(TransactionSettingKeys.IgnoreIdentifiersCase, StringComparison.OrdinalIgnoreCase)) { * ignoreCase = Database.DatabaseContext.IgnoreIdentifiersCase(); * } else if (variable.Name.Equals(TransactionSettingKeys.AutoCommit, StringComparison.OrdinalIgnoreCase)) { * autoCommit = Database.DatabaseContext.AutoCommit(); * } else if (variable.Name.Equals(TransactionSettingKeys.ParameterStyle, StringComparison.OrdinalIgnoreCase)) { * // TODO: Get it from the configuration... * parameterStyle = null; * } * } * * private Variable MakeStringVariable(string name, string value) { * var variable = new Variable(new VariableInfo(name, PrimitiveTypes.String(), false)); * variable.SetValue(DataObject.String(value)); * return variable; * } * * private Variable MakeBooleanVariable(string name, bool value) { * var variable = new Variable(new VariableInfo(name, PrimitiveTypes.Boolean(), false)); * variable.SetValue(DataObject.Boolean(value)); * return variable; * } * * Variable IVariableScope.OnVariableGet(string name) { * if (name.Equals(TransactionSettingKeys.CurrentSchema, StringComparison.OrdinalIgnoreCase)) * return MakeStringVariable(TransactionSettingKeys.CurrentSchema, currentSchema); * if (name.Equals(TransactionSettingKeys.ReadOnly, StringComparison.OrdinalIgnoreCase)) * return MakeBooleanVariable(TransactionSettingKeys.ReadOnly, readOnly); * if (name.Equals(TransactionSettingKeys.IgnoreIdentifiersCase, StringComparison.OrdinalIgnoreCase)) * return MakeBooleanVariable(TransactionSettingKeys.IgnoreIdentifiersCase, ignoreCase); * if (name.Equals(TransactionSettingKeys.AutoCommit, StringComparison.OrdinalIgnoreCase)) * return MakeBooleanVariable(TransactionSettingKeys.AutoCommit, autoCommit); * if (name.Equals(TransactionSettingKeys.ParameterStyle, StringComparison.OrdinalIgnoreCase)) * return MakeStringVariable(TransactionSettingKeys.ParameterStyle, parameterStyle); * * return null; * } */ #endregion void ICallbackHandler.OnCallbackAttached(TableCommitCallback callback) { if (callbacks == null) { callbacks = new List <TableCommitCallback>(); } callbacks.Add(callback); }
void ICallbackHandler.OnCallbackDetached(TableCommitCallback callback) { if (callbacks == null) { return; } for (int i = callbacks.Count - 1; i >= 0; i--) { var other = callbacks[i]; if (other.TableName.Equals(callback.TableName)) { callbacks.RemoveAt(i); } } }
void ICallbackHandler.OnCallbackDetached(TableCommitCallback callback) { if (callbacks == null) return; for (int i = callbacks.Count - 1; i >= 0; i--) { var other = callbacks[i]; if (other.TableName.Equals(callback.TableName)) callbacks.RemoveAt(i); } }
void ICallbackHandler.OnCallbackAttached(TableCommitCallback callback) { if (callbacks == null) callbacks = new List<TableCommitCallback>(); callbacks.Add(callback); }