/// <summary> /// Create a new ApplicationTransaction object. /// </summary> /// <param name="id">Initial value of ID.</param> public static ApplicationTransaction CreateApplicationTransaction(int id) { ApplicationTransaction applicationTransaction = new ApplicationTransaction(); applicationTransaction.ID = id; return(applicationTransaction); }
public void InitApplicationTransaction() { this.ApplicationTransactionInstance = new ApplicationTransaction(); using (HistoryContext ctx = HistoryContext.CreateInstance()) { ctx.AddToApplicationTransactionSet(this.ApplicationTransactionInstance); ctx.SaveChanges(); } }
public void EnsureApplicationTransactionTableVar(Schema.TableVar tableVar) { if (ApplicationTransactionID != Guid.Empty && tableVar.IsATObject) { ApplicationTransaction transaction = GetApplicationTransaction(); try { transaction.EnsureATTableVarMapped(_serverProcess, tableVar); } finally { Monitor.Exit(transaction); } } }
public void EnsureApplicationTransactionOperator(Schema.Operator operatorValue) { if (ApplicationTransactionID != Guid.Empty && operatorValue.IsATObject) { ApplicationTransaction transaction = GetApplicationTransaction(); try { transaction.EnsureATOperatorMapped(_serverProcess, operatorValue); } finally { Monitor.Exit(transaction); } } }
public override void DetermineDataType(Plan plan) { DetermineModifiers(plan); _dataType = new Schema.TableType(); _tableVar = new Schema.ResultTableVar(this); _tableVar.Owner = plan.User; _tableVar.InheritMetaData(SourceTableVar.MetaData); CopyTableVarColumns(SourceTableVar.Columns); int index = 0; _redefineColumnOffsets = new int[_expressions.Count]; ApplicationTransaction transaction = null; if (plan.ApplicationTransactionID != Guid.Empty) { transaction = plan.GetApplicationTransaction(); } try { if (transaction != null) { transaction.PushLookup(); } try { plan.PushCursorContext(new CursorContext(CursorType.Dynamic, CursorCapability.Navigable, CursorIsolation.None)); try { plan.EnterRowContext(); try { plan.Symbols.Push(new Symbol(String.Empty, SourceTableType.RowType)); try { // Add a column for each expression PlanNode planNode; Schema.TableVarColumn sourceColumn; Schema.TableVarColumn tempColumn; Schema.TableVarColumn newColumn; foreach (NamedColumnExpression column in _expressions) { int sourceColumnIndex = TableVar.Columns.IndexOf(column.ColumnAlias); if (sourceColumnIndex < 0) { throw new CompilerException(CompilerException.Codes.UnknownIdentifier, column, column.ColumnAlias); } sourceColumn = TableVar.Columns[sourceColumnIndex]; tempColumn = CopyTableVarColumn(sourceColumn); plan.PushCreationObject(tempColumn); try { planNode = Compiler.CompileExpression(plan, column.Expression); } finally { plan.PopCreationObject(); } newColumn = CopyTableVarColumn(sourceColumn); newColumn.Column.DataType = planNode.DataType; if (tempColumn.HasDependencies()) { newColumn.AddDependencies(tempColumn.Dependencies); } Schema.Object objectValue; if (newColumn.HasDependencies()) { for (int dependencyIndex = 0; index < newColumn.Dependencies.Count; index++) { objectValue = newColumn.Dependencies.ResolveObject(plan.CatalogDeviceSession, dependencyIndex); plan.AttachDependency(objectValue); newColumn.IsNilable = planNode.IsNilable; newColumn.IsChangeRemotable = newColumn.IsChangeRemotable && objectValue.IsRemotable; newColumn.IsDefaultRemotable = newColumn.IsDefaultRemotable && objectValue.IsRemotable; } } DataType.Columns[sourceColumnIndex] = newColumn.Column; TableVar.Columns[sourceColumnIndex] = newColumn; _redefineColumnOffsets[index] = sourceColumnIndex; Nodes.Add(planNode); index++; } DetermineRemotable(plan); } finally { plan.Symbols.Pop(); } } finally { plan.ExitRowContext(); } } finally { plan.PopCursorContext(); } } finally { if (transaction != null) { transaction.PopLookup(); } } } finally { if (transaction != null) { Monitor.Exit(transaction); } } foreach (Schema.Key key in SourceTableVar.Keys) { bool add = true; foreach (Schema.TableVarColumn column in key.Columns) { if (((IList)_redefineColumnOffsets).Contains(TableVar.Columns.IndexOfName(column.Name))) { add = false; break; } } if (add) { TableVar.Keys.Add(CopyKey(key)); } } _distinctRequired = TableVar.Keys.Count == 0; if (_distinctRequired) { Schema.Key newKey = new Schema.Key(); foreach (Schema.TableVarColumn column in TableVar.Columns) { newKey.Columns.Add(column); } newKey.IsInherited = true; TableVar.Keys.Add(newKey); } foreach (Schema.Order order in SourceTableVar.Orders) { bool add = true; for (int columnIndex = 0; columnIndex < order.Columns.Count; columnIndex++) { if (((IList)_redefineColumnOffsets).Contains(TableVar.Columns.IndexOfName(order.Columns[columnIndex].Column.Name))) { add = false; break; } } if (add) { TableVar.Orders.Add(CopyOrder(order)); } } DetermineOrder(plan); // TODO: Reference derivation on a redefine should exclude affected references #if UseReferenceDerivation #if UseElaborable if (plan.CursorContext.CursorCapabilities.HasFlag(CursorCapability.Elaborable)) #endif CopyReferences(plan, SourceTableVar); #endif }
public override void DetermineDataType(Plan plan) { DetermineModifiers(plan); _dataType = new Schema.TableType(); _tableVar = new Schema.ResultTableVar(this); _tableVar.Owner = plan.User; _tableVar.InheritMetaData(SourceTableVar.MetaData); CopyTableVarColumns(SourceTableVar.Columns); _extendColumnOffset = TableVar.Columns.Count; // This structure will track key columns as a set of sets, and any extended columns that are equivalent to them Dictionary <string, Schema.Key> keyColumns = new Dictionary <string, Schema.Key>(); foreach (Schema.TableVarColumn tableVarColumn in TableVar.Columns) { if (SourceTableVar.Keys.IsKeyColumnName(tableVarColumn.Name) && !keyColumns.ContainsKey(tableVarColumn.Name)) { keyColumns.Add(tableVarColumn.Name, new Schema.Key(new Schema.TableVarColumn[] { tableVarColumn })); } } ApplicationTransaction transaction = null; if (plan.ApplicationTransactionID != Guid.Empty) { transaction = plan.GetApplicationTransaction(); } try { if (transaction != null) { transaction.PushLookup(); } try { plan.PushCursorContext(new CursorContext(CursorType.Dynamic, CursorCapability.Navigable, CursorIsolation.None)); try { plan.EnterRowContext(); try { plan.Symbols.Push(new Symbol(String.Empty, SourceTableType.RowType)); try { // Add a column for each expression PlanNode planNode; Schema.TableVarColumn newColumn; foreach (NamedColumnExpression column in _expressions) { newColumn = new Schema.TableVarColumn(new Schema.Column(column.ColumnAlias, plan.DataTypes.SystemScalar)); plan.PushCreationObject(newColumn); try { planNode = Compiler.CompileExpression(plan, column.Expression); } finally { plan.PopCreationObject(); } bool isChangeRemotable = true; if (newColumn.HasDependencies()) { for (int index = 0; index < newColumn.Dependencies.Count; index++) { Schema.Object objectValue = newColumn.Dependencies.ResolveObject(plan.CatalogDeviceSession, index); isChangeRemotable = isChangeRemotable && objectValue.IsRemotable; plan.AttachDependency(objectValue); } } bool isUpdatable = planNode is TableNode || planNode is ExtractRowNode; newColumn = new Schema.TableVarColumn ( new Schema.Column(column.ColumnAlias, planNode.DataType), column.MetaData, isUpdatable ? Schema.TableVarColumnType.Stored : Schema.TableVarColumnType.Virtual ); newColumn.IsNilable = planNode.IsNilable; newColumn.IsChangeRemotable = isChangeRemotable; newColumn.IsDefaultRemotable = isChangeRemotable; DataType.Columns.Add(newColumn.Column); TableVar.Columns.Add(newColumn); string columnName = String.Empty; if (IsColumnReferencing(planNode, ref columnName)) { // TODO: In theory we could allow updatability through an IsColumnReferencing add column as well Schema.TableVarColumn referencedColumn = TableVar.Columns[columnName]; if (SourceTableVar.Keys.IsKeyColumnName(referencedColumn.Name)) { Schema.Key key; if (keyColumns.TryGetValue(referencedColumn.Name, out key)) { key.Columns.Add(newColumn); } else { keyColumns.Add(referencedColumn.Name, new Schema.Key(new Schema.TableVarColumn[] { newColumn })); } } } Nodes.Add(planNode); } DetermineRemotable(plan); } finally { plan.Symbols.Pop(); } } finally { plan.ExitRowContext(); } } finally { plan.PopCursorContext(); } } finally { if (transaction != null) { transaction.PopLookup(); } } } finally { if (transaction != null) { Monitor.Exit(transaction); } } foreach (Schema.Key key in SourceTableVar.Keys) { // Seed the result key set with the empty set Schema.Keys resultKeys = new Schema.Keys(); resultKeys.Add(new Schema.Key()); foreach (Schema.TableVarColumn column in key.Columns) { resultKeys = KeyProduct(resultKeys, keyColumns[column.Name]); } foreach (Schema.Key resultKey in resultKeys) { resultKey.IsSparse = key.IsSparse; resultKey.IsInherited = true; resultKey.MergeMetaData(key.MetaData); TableVar.Keys.Add(resultKey); } } CopyOrders(SourceTableVar.Orders); if (SourceNode.Order != null) { Order = CopyOrder(SourceNode.Order); } #if UseReferenceDerivation #if UseElaborable if (plan.CursorContext.CursorCapabilities.HasFlag(CursorCapability.Elaborable)) #endif CopyReferences(plan, SourceTableVar); #endif }
/// <summary> /// There are no comments for ApplicationTransactionSet in the schema. /// </summary> public void AddToApplicationTransactionSet(ApplicationTransaction applicationTransaction) { base.AddObject("ApplicationTransactionSet", applicationTransaction); }