/// <summary> /// Create a representation of the creation of a data relation. /// </summary> /// <param name="relationSchema">The description of a relationship between two tables.</param> public CodeDataRelation(RelationSchema relationSchema) { // Collect the key fields in the parent table. List <CodeExpression> parentFieldList = new List <CodeExpression>(); foreach (ColumnSchema columnSchema in relationSchema.ParentColumns) { parentFieldList.Add(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(relationSchema.ParentTable.DataModel.Name), String.Format("table{0}", relationSchema.ParentTable.Name)), String.Format("{0}Column", columnSchema.Name))); } // Collect the referenced fields in the child table. List <CodeExpression> childFieldList = new List <CodeExpression>(); foreach (ColumnSchema columnSchema in relationSchema.ChildColumns) { childFieldList.Add(new CodePropertyReferenceExpression(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(relationSchema.ChildTable.DataModel.Name), String.Format("table{0}", relationSchema.ChildTable.Name)), String.Format("{0}Column", columnSchema.Name))); } // new System.Data.ForeignKeyConstraint("FK_Object_Department", new FluidTrade.Core.Column[] { // FluidTrade.UnitTest.Server.DataModel.tableObject.ObjectIdColumn}, new FluidTrade.Core.Column[] { // FluidTrade.UnitTest.Server.DataModel.tableDepartment.DepartmentIdColumn}); this.CreateType = new CodeGlobalTypeReference(typeof(System.Data.DataRelation)); this.Parameters.Add(new CodePrimitiveExpression(relationSchema.Name)); this.Parameters.Add(new CodeArrayCreateExpression(new CodeGlobalTypeReference(typeof(System.Data.DataColumn)), parentFieldList.ToArray())); this.Parameters.Add(new CodeArrayCreateExpression(new CodeGlobalTypeReference(typeof(System.Data.DataColumn)), childFieldList.ToArray())); this.Parameters.Add(new CodePrimitiveExpression(false)); }
/// <summary> /// Generates a property to get a parent row. /// </summary> /// <param name="foreignKeyConstraintSchema">The foreign key that references the parent table.</param> public ParentRelationProperty(RelationSchema relationSchema) { // /// <summary> // /// Gets the parent relation between the Department and Employee tables. // /// </summary> // public System.Data.DataRelation DepartmentEmployeeRelation // { // get // { // return this.relationDepartmentEmployee; // } // } this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Gets the parent relation between the {0} and {1} tables.", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Type = new CodeGlobalTypeReference(typeof(DataRelation)); this.Name = relationSchema.IsDistinctPathToParent ? String.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); this.GetStatements.Add(new CodeMethodReturnStatement(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), relationSchema.IsDistinctPathToParent ? String.Format("relation{0}{1}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("relation{0}{1}By{2}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name)))); }
/// <summary> /// Creates a relationship to a child table. /// </summary> /// <param name="relationSchema">A description of the relationship between two tables.</param> public ChildRelationField(RelationSchema relationSchema) { // // The Relation between the Employee and Engineer tables // private global::System.Data.DataRelation relationEmployeeEngineer; this.Type = new CodeGlobalTypeReference(typeof(DataRelation)); this.Name = relationSchema.IsDistinctPathToChild ? String.Format("relation{0}{1}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("relation{0}{1}By{2}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); }
/// <summary> /// Creates a field that holds the relationship between two tables. /// </summary> public RelationField(RelationSchema relationSchema) { // private static global::System.Data.DataRelation relationEmployeeProjectMember; this.Attributes = MemberAttributes.Assembly; this.Type = new CodeGlobalTypeReference(typeof(DataRelation)); this.Name = relationSchema.IsDistinctPathToParent ? String.Format("relation{0}{1}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("relation{0}{1}By{2}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); }
/// <summary> /// Creates a field that holds the relation to a parent table. /// </summary> /// <param name="relationSchema">The description of a relationship between two tables.</param> public ParentRelationField(RelationSchema relationSchema) { // // The Relation between the Department and Employee tables // private global::System.Data.DataRelation relationDepartmentEmployee; this.Type = new CodeGlobalTypeReference(typeof(DataRelation)); this.Name = relationSchema.IsDistinctPathToParent ? String.Format("relation{0}{1}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("relation{0}{1}By{2}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); }
/// <summary> /// Creates a property that gets the parent row. /// </summary> /// <param name="relationSchema">The foreign key that references the parent table.</param> public ParentRowProperty(RelationSchema relationSchema) { // These constructs are used several times to generate the property. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; String propertyName = String.Format("{0}Row", parentTable); String propertyTypeName = String.Format("{0}Row", parentTable); String tableFieldName = String.Format("table{0}", childTable.Name); String relationName = relationSchema.IsDistinctPathToParent ? String.Format("{0}{1}Relation", parentTable.Name, childTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); String relationFieldName = relationSchema.IsDistinctPathToParent ? String.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // /// <summary> // /// Gets the parent row in the Department table. // /// </summary> // [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Gets the parent row in the {0} table.", relationSchema.ParentTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(DebuggerNonUserCodeAttribute)))); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Type = new CodeTypeReference(propertyTypeName); this.Name = relationSchema.IsDistinctPathToParent ? propertyName : String.Format("{0}By{1}", propertyName, relationSchema.Name); // public DepartmentRow DepartmentRow { // get { // try { // return ((DepartmentRow)(this.GetParentRow(this.tableEmployee.DepartmentEmployeeRelation))); // } // finally { // } // } CodeTryCatchFinallyStatement getTryStatement = new CodeTryCatchFinallyStatement(); CodeExpression parentRelationExpression = new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationName); this.GetStatements.Add( new CodeMethodReturnStatement( new CodeCastExpression( propertyTypeName, new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetParentRow", new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationFieldName))))); // } }
/// <summary> /// Creates a property that gets the parent row. /// </summary> /// <param name="relationSchema">The foreign key that references the parent table.</param> public ParentRowProperty(RelationSchema relationSchema) { // These constructs are used several times to generate the property. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; string rowTypeName = string.Format("{0}Row", parentTable.Name); string tableFieldName = string.Format("table{0}", childTable.Name); string relationName = relationSchema.IsDistinctPathToParent ? string.Format("{0}{1}Relation", parentTable.Name, childTable.Name) : string.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); string relationFieldName = relationSchema.IsDistinctPathToParent ? string.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : string.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // /// <summary> // /// Gets the parent row in the Department table. // /// </summary> // [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Gets the parent row in the {0} table.", relationSchema.ParentTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); // HACK - Put this line back in for official releases // this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.Diagnostics.DebuggerNonUserCodeAttribute)))); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Type = new CodeTypeReference(rowTypeName); this.Name = relationSchema.IsDistinctPathToParent ? rowTypeName : string.Format("{0}By{1}", rowTypeName, relationSchema.Name); // public DepartmentRow DepartmentRow { // get { // try { // // The parent table must be locked to insure it doesn't change before attempting to access the parent row. // return ((DepartmentRow)(this.GetParentRow(this.tableEmployee.DepartmentEmployeeRelation))); // } // finally { // // The parent table can be released once the parent row is found. // } // } CodeTryCatchFinallyStatement getTryStatement = new CodeTryCatchFinallyStatement(); getTryStatement.TryStatements.Add(new CodeCommentStatement("The parent table must be locked to insure it doesn't change before attempting to access the parent row.")); CodeExpression parentRelationExpression = new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationName); getTryStatement.TryStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(rowTypeName, new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetParentRow", new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationFieldName))))); getTryStatement.FinallyStatements.Add(new CodeCommentStatement("The parent table can be released once the parent row is found.")); this.GetStatements.Add(getTryStatement); // } }
/// <summary> /// Generates a method to get a list of child rows. /// </summary> /// <param name="relationSchema">A description of the relation between two tables.</param> public GetChildRowsMethod(RelationSchema relationSchema) { // These variables are used to construct the method. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; string rowTypeName = string.Format("{0}Row", childTable.Name); string tableFieldName = string.Format("table{0}", parentTable.Name); string childRowTypeName = string.Format("{0}Row", relationSchema.ChildTable.Name); // /// <summary> // /// Gets the children rows in the Engineer table. // /// </summary> // public EngineerRow[] GetEngineerRows() { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Gets the children rows in the {0} table.", relationSchema.ChildTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.ReturnType = new CodeTypeReference(childRowTypeName, 1); this.Name = relationSchema.IsDistinctPathToChild ? string.Format("Get{0}s", childRowTypeName) : string.Format("Get{0}sBy{1}", childRowTypeName, relationSchema.Name); string relationName = relationSchema.IsDistinctPathToChild ? string.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : string.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // try { // // The child table must be locked to insure it doesn't change while the relation is used to create a list of // // all the child rows of this row. // return ((EngineerRow[])(this.GetChildRows(this.tableEmployee.EmployeeEngineerRelation))); // } // finally { // // The child table can be released once the list is built. // } CodeTryCatchFinallyStatement getTryStatement = new CodeTryCatchFinallyStatement(); getTryStatement.TryStatements.Add(new CodeCommentStatement("The child table must be locked to insure it doesn't change while the relation is used to create a list of")); getTryStatement.TryStatements.Add(new CodeCommentStatement("all the child rows of this row.")); getTryStatement.TryStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(new CodeTypeReference(childRowTypeName, 1), new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetChildRows", new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationName))))); getTryStatement.FinallyStatements.Add(new CodeCommentStatement("The child table can be released once the list is built.")); this.Statements.Add(getTryStatement); // } }
/// <summary> /// Generates a method to get a list of child rows. /// </summary> /// <param name="relationSchema">A description of the relation between two tables.</param> public GetChildRowsMethod(RelationSchema relationSchema) { // These variables are used to construct the method. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; String tableFieldName = String.Format("table{0}", parentTable.Name); String childRowName = String.Format("{0}Row", relationSchema.ChildTable.Name); String childRowTypeName = String.Format("{0}Row", relationSchema.ChildTable.Name); // /// <summary> // /// Gets the children rows in the Engineer table. // /// </summary> // public EngineerRow[] GetEngineerRows() { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Gets the children rows in the {0} table.", relationSchema.ChildTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.ReturnType = new CodeTypeReference(childRowTypeName, 1); this.Name = relationSchema.IsDistinctPathToChild ? String.Format("Get{0}s", childRowName) : String.Format("Get{0}sBy{1}", childRowName, relationSchema.Name); String relationName = relationSchema.IsDistinctPathToChild ? String.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // return ((EngineerRow[])(this.GetChildRows(this.tableEmployee.EmployeeEngineerRelation))); this.Statements.Add( new CodeMethodReturnStatement( new CodeCastExpression( new CodeTypeReference(childRowTypeName, 1), new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetChildRows", new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationName))))); // } }
/// <summary> /// Creates a property that joins a child table to its parent. /// </summary> /// <param name="relationSchema">A description of the relationship between two tables.</param> public ChildRelationProperty(RelationSchema relationSchema) { // /// <summary> // /// Gets the child relation between the Employee and Engineer tables. // /// </summary> // internal global::System.Data.DataRelation EmployeeEngineerRelation { // get { // return this.relationEmployeeEngineer; // } // } this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Gets the child relation between the {0} and {1} tables.", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Assembly | MemberAttributes.Final; this.Type = new CodeGlobalTypeReference(typeof(DataRelation)); this.Name = relationSchema.IsDistinctPathToChild ? String.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); string relationName = relationSchema.IsDistinctPathToChild ? String.Format("relation{0}{1}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("relation{0}{1}By{2}", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); this.GetStatements.Add(new CodeMethodReturnStatement(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), relationName))); }
public Query(IDatabase database, NpgsqlConnection connection, RelationSchema relationSchema) { _db = database; _connection = connection; _relationSchema = relationSchema; }
/// <summary> /// Generates a method to get a list of child rows. /// </summary> /// <param name="relationSchema">A description of the relation between two tables.</param> public GetChildRowsMethod(RelationSchema relationSchema) { // These variables are used to construct the method. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; string rowTypeName = String.Format("{0}Row", childTable.Name); string tableFieldName = String.Format("table{0}", parentTable.Name); string childRowTypeName = String.Format("{0}Row", relationSchema.ChildTable.Name); // /// <summary> // /// Gets the children rows in the AccountGroup table. // /// </summary> // public AccountGroupRow[] GetAccountGroupRows() // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Gets the children rows in the {0} table.", relationSchema.ChildTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.ReturnType = new CodeTypeReference(childRowTypeName, 1); this.Name = relationSchema.IsDistinctPathToChild ? String.Format("Get{0}s", childRowTypeName) : String.Format("Get{0}sBy{1}", childRowTypeName, relationSchema.Name); string relationName = relationSchema.IsDistinctPathToChild ? String.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // DataModelTransaction p7519 = DataModel.CurrentTransaction; CodeVariableReferenceExpression transactionExpression = new CodeRandomVariableReferenceExpression(); this.Statements.Add( new CodeVariableDeclarationStatement( new CodeTypeReference(String.Format("{0}Transaction", parentTable.DataModel.Name)), transactionExpression.VariableName, new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(parentTable.DataModel.Name), "CurrentTransaction"))); // if ((this.IsLockHeld(p7519.TransactionId) == false)) // { // throw new global::System.ServiceModel.FaultException<Teraque.SynchronizationLockFault>(new global::Teraque.SynchronizationLockFault("AccountBase")); // } this.Statements.AddRange(new CodeCheckReaderLockHeldStatements(new CodeThisReferenceExpression(), relationSchema.ParentTable, transactionExpression)); // try // { CodeTryCatchFinallyStatement tryCatchFinallyStatement = new CodeTryCatchFinallyStatement(); // ((TenantDataModel)(this.Table.DataSet)).dataLock.EnterReadLock(); tryCatchFinallyStatement.TryStatements.Add( new CodeMethodInvokeExpression( new CodeFieldReferenceExpression( new CodeCastExpression( new CodeTypeReference(String.Format("Tenant{0}", parentTable.DataModel.Name)), new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Table"), "DataSet")), "dataLock"), "EnterReadLock")); // return ((AccountGroupRow[])(this.GetChildRows(this.tableAccountBase.AccountBaseAccountGroupRelation))); tryCatchFinallyStatement.TryStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(new CodeTypeReference(childRowTypeName, 1), new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetChildRows", new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationName))))); // } // finally // { // ((TenantTarget)(this.Table.DataSet)).dataLock.ExitReadLock(); tryCatchFinallyStatement.FinallyStatements.Add( new CodeMethodInvokeExpression( new CodeFieldReferenceExpression( new CodeCastExpression( new CodeTypeReference(String.Format("Tenant{0}", parentTable.DataModelSchema.Name)), new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Table"), "DataSet")), "dataLock"), "ExitReadLock")); this.Statements.Add(tryCatchFinallyStatement); // } // } }
/// <summary> /// Creates a property that gets the parent row. /// </summary> /// <param name="relationSchema">The foreign key that references the parent table.</param> public ParentRowProperty(RelationSchema relationSchema) { // These constructs are used several times to generate the property. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; string rowTypeName = String.Format("{0}Row", parentTable.Name); string tableFieldName = String.Format("table{0}", childTable.Name); string relationName = relationSchema.IsDistinctPathToParent ? String.Format("{0}{1}Relation", parentTable.Name, childTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); string relationFieldName = relationSchema.IsDistinctPathToParent ? String.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : String.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // /// <summary> // /// Gets the parent row in the Currency table. // /// </summary> // public CurrencyRow CurrencyRow // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("Gets the parent row in the {0} table.", relationSchema.ParentTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(DebuggerNonUserCodeAttribute)))); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Type = new CodeTypeReference(rowTypeName); this.Name = relationSchema.IsDistinctPathToParent ? rowTypeName : String.Format("{0}By{1}", rowTypeName, relationSchema.Name); // get // { // DataModelTransaction k7494 = DataModel.CurrentTransaction; CodeVariableReferenceExpression transactionExpression = new CodeRandomVariableReferenceExpression(); this.GetStatements.Add( new CodeVariableDeclarationStatement( new CodeTypeReference(String.Format("{0}Transaction", parentTable.DataModel.Name)), transactionExpression.VariableName, new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(parentTable.DataModel.Name), "CurrentTransaction"))); // if ((this.IsLockHeld(k7494.TransactionId) == false)) // { // throw new global::System.ServiceModel.FaultException<Teraque.SynchronizationLockFault>(new global::Teraque.SynchronizationLockFault("AccountBase")); // } this.GetStatements.AddRange( new CodeCheckReaderLockHeldStatements(new CodeThisReferenceExpression(), relationSchema.ChildTable, transactionExpression)); // try // { // ((TenantDataModel)this.Table.DataSet).dataLock.EnterReadLock(); // return ((CurrencyRow)(this.GetParentRow(this.tableAccountBase.CurrencyAccountBaseRelation))); CodeTryCatchFinallyStatement tryCatchFinallyStatement = new CodeTryCatchFinallyStatement(); tryCatchFinallyStatement.TryStatements.Add( new CodeMethodInvokeExpression( new CodeFieldReferenceExpression( new CodeCastExpression( new CodeTypeReference(String.Format("Tenant{0}", parentTable.DataModelSchema.Name)), new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Table"), "DataSet")), "dataLock"), "EnterReadLock")); tryCatchFinallyStatement.TryStatements.Add( new CodeMethodReturnStatement( new CodeCastExpression( rowTypeName, new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetParentRow", new CodePropertyReferenceExpression( new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationFieldName))))); // } // finally // { // ((TenantDataModel)this.Table.DataSet).dataLock.ExitReadLock(); // } tryCatchFinallyStatement.FinallyStatements.Add( new CodeMethodInvokeExpression( new CodeFieldReferenceExpression( new CodeCastExpression( new CodeTypeReference(String.Format("Tenant{0}", parentTable.DataModelSchema.Name)), new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Table"), "DataSet")), "dataLock"), "ExitReadLock")); this.GetStatements.Add(tryCatchFinallyStatement); // } // } }
/// <summary> /// Creates a property that gets the parent row. /// </summary> /// <param name="relationSchema">The foreign key that references the parent table.</param> public ParentRowProperty(RelationSchema relationSchema) { // These constructs are used several times to generate the property. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; string rowTypeName = string.Format("{0}Row", parentTable.Name); string tableFieldName = string.Format("table{0}", childTable.Name); string relationName = relationSchema.IsDistinctPathToParent ? string.Format("{0}{1}Relation", parentTable.Name, childTable.Name) : string.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); string relationFieldName = relationSchema.IsDistinctPathToParent ? string.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : string.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // /// <summary> // /// Gets the parent row in the AccountBase table. // /// </summary> // [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] // public AccountBaseRow AccountBaseRow // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Gets the parent row in the {0} table.", relationSchema.ParentTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); // HACK - Put this line back in for official releases //this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.Diagnostics.DebuggerNonUserCodeAttribute)))); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Type = new CodeTypeReference(rowTypeName); this.Name = relationSchema.IsDistinctPathToParent ? rowTypeName : string.Format("{0}By{1}", rowTypeName, relationSchema.Name); // get // { // DataModelTransaction dataModelTransaction = DataModelTransaction.Current; CodeVariableReferenceExpression transactionExpression = new CodeVariableReferenceExpression( string.Format("{0}Transaction", CommonConversion.ToCamelCase(parentTable.DataModel.Name))); this.GetStatements.Add( new CodeVariableDeclarationStatement( new CodeTypeReference(string.Format("{0}Transaction", parentTable.DataModel.Name)), transactionExpression.VariableName, new CodePropertyReferenceExpression( new CodeTypeReferenceExpression(string.Format("{0}Transaction", parentTable.DataModel.Name)), "Current"))); // if ((this.IsLockHeld(dataModelTransaction.TransactionId) == false)) // { // throw new global::System.ServiceModel.FaultException<SynchronizationLockFault>(new global::FluidTrade.Core.SynchronizationLockFault("Account")); // } this.GetStatements.AddRange( new CodeCheckReaderLockHeldStatements(new CodeThisReferenceExpression(), relationSchema.ChildTable, transactionExpression)); // try // { CodeTryCatchFinallyStatement getTryStatement = new CodeTryCatchFinallyStatement(); // DataModel.dataLock.EnterReadLock(); getTryStatement.TryStatements.Add( new CodeMethodInvokeExpression( new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(parentTable.DataModel.Name), "DataLock"), "EnterReadLock")); // return ((AccountBaseRow)(this.GetParentRow(this.tableAccount.AccountBaseAccountRelation))); // } getTryStatement.TryStatements.Add( new CodeMethodReturnStatement( new CodeCastExpression( rowTypeName, new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetParentRow", new CodePropertyReferenceExpression( new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationFieldName))))); // finally // { // DataModel.dataLock.ExitReadLock(); // } getTryStatement.FinallyStatements.Add( new CodeMethodInvokeExpression( new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(parentTable.DataModel.Name), "DataLock"), "ExitReadLock")); // } this.GetStatements.Add(getTryStatement); // } }
/// <summary> /// Generates a method to get a list of child rows. /// </summary> /// <param name="relationSchema">A description of the relation between two tables.</param> public GetChildRowsMethod(RelationSchema relationSchema) { // These variables are used to construct the method. TableSchema childTable = relationSchema.ChildTable; TableSchema parentTable = relationSchema.ParentTable; string rowTypeName = string.Format("{0}Row", childTable.Name); string tableFieldName = string.Format("table{0}", parentTable.Name); string childRowTypeName = string.Format("{0}Row", relationSchema.ChildTable.Name); // /// <summary> // /// Gets the children rows in the Allocation table. // /// </summary> // public AllocationRow[] GetAllocationRows() // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Gets the children rows in the {0} table.", relationSchema.ChildTable.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.ReturnType = new CodeTypeReference(childRowTypeName, 1); this.Name = relationSchema.IsDistinctPathToChild ? string.Format("Get{0}s", childRowTypeName) : string.Format("Get{0}sBy{1}", childRowTypeName, relationSchema.Name); string relationName = relationSchema.IsDistinctPathToChild ? string.Format("{0}{1}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name) : string.Format("{0}{1}By{2}Relation", relationSchema.ParentTable.Name, relationSchema.ChildTable.Name, relationSchema.Name); // DataModelTransaction dataModelTransaction = DataModelTransaction.Current; CodeVariableReferenceExpression transactionExpression = new CodeVariableReferenceExpression( string.Format("{0}Transaction", CommonConversion.ToCamelCase(parentTable.DataModel.Name))); this.Statements.Add( new CodeVariableDeclarationStatement( new CodeTypeReference(string.Format("{0}Transaction", parentTable.DataModel.Name)), transactionExpression.VariableName, new CodePropertyReferenceExpression( new CodeTypeReferenceExpression(string.Format("{0}Transaction", parentTable.DataModel.Name)), "Current"))); // if ((this.IsLockHeld(dataModelTransaction.transactionId) == false)) // { // throw new global::System.ServiceModel.FaultException<SynchronizationLockFault>(new global::FluidTrade.Core.SynchronizationLockFault("Account")); // } this.Statements.AddRange(new CodeCheckReaderLockHeldStatements(new CodeThisReferenceExpression(), relationSchema.ParentTable, transactionExpression)); // try // { CodeTryCatchFinallyStatement getTryStatement = new CodeTryCatchFinallyStatement(); // DataModel.dataLock.EnterReadLock(); getTryStatement.TryStatements.Add( new CodeMethodInvokeExpression( new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(relationSchema.ParentTable.DataModel.Name), "DataLock"), "EnterReadLock")); // return ((AllocationRow[])(this.GetChildRows(this.tableAccount.AccountAllocationRelation))); // } getTryStatement.TryStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(new CodeTypeReference(childRowTypeName, 1), new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetChildRows", new CodePropertyReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), tableFieldName), relationName))))); // finally // { // DataModel.dataLock.ExitReadLock(); // } getTryStatement.FinallyStatements.Add( new CodeMethodInvokeExpression( new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(relationSchema.ParentTable.DataModel.Name), "DataLock"), "ExitReadLock")); this.Statements.Add(getTryStatement); // } }