/// <summary>Updates a Country record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Update(ParameterList parameters) { // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalCountryId = ((string)(parameters["countryId"])); object name = parameters["name"].Value; object abbreviation = parameters["abbreviation"].Value; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Resolve External Identifiers int countryId = Country.FindRequiredKey(configurationId, "countryId", externalCountryId); // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerDataModel.CountryRow countryRow = countryTable.FindByCountryId(countryId); rowVersion = ((long)(countryRow[countryTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Country.Update(adoTransaction, sqlTransaction, ref rowVersion, countryId, name, abbreviation, null, null); // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Updates a Country record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="rowVersion">The version number of the row</param> /// <param name="countryId">The value for the CountryId column.</param> /// <param name="name">The value for the Name column.</param> /// <param name="abbreviation">The value for the Abbreviation column.</param> /// <param name="externalId0">The value for the ExternalId0 column.</param> /// <param name="externalId1">The value for the ExternalId1 column.</param> public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int countryId, object name, object abbreviation, object externalId0, object externalId1) { // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Rule #1: Make sure the record exists before updating it. ServerDataModel.CountryRow countryRow = countryTable.FindByCountryId(countryId); if ((countryRow == null)) { throw new Exception(string.Format("The Country table does not have an element identified by {0}", countryId)); } // Rule #2: Optimistic Concurrency Check if ((countryRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((name == null)) { name = countryRow[countryTable.NameColumn]; } if ((abbreviation == null)) { abbreviation = countryRow[countryTable.AbbreviationColumn]; } if ((externalId0 == null)) { externalId0 = countryRow[countryTable.ExternalId0Column]; } if ((externalId1 == null)) { externalId1 = countryRow[countryTable.ExternalId1Column]; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Update the record in the ADO database. countryRow[countryTable.RowVersionColumn] = rowVersion; countryRow[countryTable.NameColumn] = name; countryRow[countryTable.AbbreviationColumn] = abbreviation; countryRow[countryTable.ExternalId0Column] = externalId0; countryRow[countryTable.ExternalId1Column] = externalId1; adoTransaction.DataRows.Add(countryRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Country\" set \"RowVersion\"=@rowVersion,\"Name\"=@name,\"Abbreviation\"=@abbrev" + "iation,\"ExternalId0\"=@externalId0,\"ExternalId1\"=@externalId1 where \"CountryId\"=@" + "countryId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@countryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, countryId)); sqlCommand.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, name)); sqlCommand.Parameters.Add(new SqlParameter("@abbreviation", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, abbreviation)); sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0)); sqlCommand.Parameters.Add(new SqlParameter("@externalId1", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId1)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }
/// <summary>Initializes the static elements of an Object.</summary> static Country() { // The table must be locked before the indices can be read into an accelerator array. ServerDataModel.CountryLock.AcquireReaderLock(System.Threading.Timeout.Infinite); // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // This does an indirect lookup operation using the views created for the ExternalId columns. Take the index of the user // identifier column calcualted above and use it to find a record containing the external identifier. Country.externalKeyArray = new DataView[] { countryTable.UKCountryExternalId0, countryTable.UKCountryExternalId1}; // The table must be released after the array is constructed. ServerDataModel.CountryLock.ReleaseReaderLock(); }
/// <summary>Archives a Country record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="RowVersion">The version number of this row.</param> /// <param name="countryId">The value for the CountryId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int countryId) { // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Rule #1: Make sure the record exists before updating it. ServerDataModel.CountryRow countryRow = countryTable.FindByCountryId(countryId); if ((countryRow == null)) { throw new Exception(string.Format("The Country table does not have an element identified by {0}", countryId)); } // Rule #2: Optimistic Concurrency Check if ((countryRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < countryRow.GetAccountRows().Length); index = (index + 1)) { ServerDataModel.AccountRow childAccountRow = countryRow.GetAccountRows()[index]; Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId); } for (int index = 0; (index < countryRow.GetSecurityRows().Length); index = (index + 1)) { ServerDataModel.SecurityRow childSecurityRow = countryRow.GetSecurityRows()[index]; Security.ArchiveChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId); } for (int index = 0; (index < countryRow.GetHolidayRows().Length); index = (index + 1)) { ServerDataModel.HolidayRow childHolidayRow = countryRow.GetHolidayRows()[index]; Holiday.Archive(adoTransaction, sqlTransaction, childHolidayRow.RowVersion, childHolidayRow.HolidayId); } for (int index = 0; (index < countryRow.GetProvinceRows().Length); index = (index + 1)) { ServerDataModel.ProvinceRow childProvinceRow = countryRow.GetProvinceRows()[index]; Province.Archive(adoTransaction, sqlTransaction, childProvinceRow.RowVersion, childProvinceRow.ProvinceId); } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Delete the record in the ADO database. countryRow[countryTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(countryRow); countryRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Country\" set \"IsArchived\" = 1 where \"CountryId\"=@countryId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@countryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, countryId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Loads a Country record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Load(ParameterList parameters) { // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; object externalCountryId = parameters["countryId"].Value; string name = parameters["name"]; string abbreviation = parameters["abbreviation"]; object externalId0 = parameters["externalId0"].Value; object externalId1 = parameters["externalId1"].Value; // The row versioning is largely disabled for external operations. The value is returned to the caller in the // event it's needed for operations within the batch. long rowVersion = long.MinValue; // Resolve External Identifiers int countryId = Country.FindKey(configurationId, "countryId", externalCountryId); // The load operation will create a record if it doesn't exist, or update an existing record. The external // identifier is used to determine if a record exists with the same key. if ((countryId == int.MinValue)) { // Populate the 'externalId' varaibles so that the external identifier can be used to find the row when an // external method is called with the same 'configurationId' parameter. int externalKeyIndex = Country.GetExternalKeyIndex(configurationId, "countryId"); object[] externalIdArray = new object[2]; externalIdArray[externalKeyIndex] = externalCountryId; externalId0 = externalIdArray[0]; externalId1 = externalIdArray[1]; // Call the internal method to complete the operation. MarkThree.Quasar.Core.Country.Insert(adoTransaction, sqlTransaction, ref rowVersion, name, abbreviation, externalId0, externalId1); } else { // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerDataModel.CountryRow countryRow = countryTable.FindByCountryId(countryId); rowVersion = ((long)(countryRow[countryTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Country.Update(adoTransaction, sqlTransaction, ref rowVersion, countryId, name, abbreviation, externalId0, externalId1); } // Return values. parameters["rowVersion"] = rowVersion; }
/// <summary>Inserts a Country record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="name">The value for the Name column.</param> /// <param name="abbreviation">The value for the Abbreviation column.</param> /// <param name="externalId0">The value for the ExternalId0 column.</param> /// <param name="externalId1">The value for the ExternalId1 column.</param> public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, string name, string abbreviation, object externalId0, object externalId1) { // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Apply Defaults if ((externalId0 == null)) { externalId0 = System.DBNull.Value; } if ((externalId1 == null)) { externalId1 = System.DBNull.Value; } // Increment the row version rowVersion = ServerDataModel.RowVersion.Increment(); // Insert the record into the ADO database. ServerDataModel.CountryRow countryRow = countryTable.NewCountryRow(); countryRow[countryTable.RowVersionColumn] = rowVersion; countryRow[countryTable.NameColumn] = name; countryRow[countryTable.AbbreviationColumn] = abbreviation; countryRow[countryTable.ExternalId0Column] = externalId0; countryRow[countryTable.ExternalId1Column] = externalId1; countryTable.AddCountryRow(countryRow); adoTransaction.DataRows.Add(countryRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand("insert \"Country\" (\"rowVersion\",\"CountryId\",\"Name\",\"Abbreviation\",\"ExternalId0\",\"E" + "xternalId1\") values (@rowVersion,@countryId,@name,@abbreviation,@externalId0,@ex" + "ternalId1)"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@countryId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, countryRow[countryTable.CountryIdColumn])); sqlCommand.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, name)); sqlCommand.Parameters.Add(new SqlParameter("@abbreviation", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, abbreviation)); sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0)); sqlCommand.Parameters.Add(new SqlParameter("@externalId1", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId1)); sqlCommand.ExecuteNonQuery(); // Return Statements return(countryRow.CountryId); }
/// <summary>Finds a a Country record using a configuration and an external identifier.</summary> /// <param name="configurationId">Specified which mappings (user id columns) to use when looking up external identifiers.</param> /// <param name="parameterId">The name of the parameter as specified in the configuration table.</param> /// <param name="externalId">The external (user supplied) identifier for the record.</param> public static int FindKey(object configurationId, string parameterId, object externalId) { // A missing key will never match a column. if ((externalId == null)) { return int.MinValue; } // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Look for the record using the external identifier. The configuration selected the key to use, which effectively // selected the external id column to use for the search. If a record is found in the view, a translation still needs // to be made back to the original table before an index to the record can be returned to the caller. int externalKeyIndex = Country.GetExternalKeyIndex(configurationId, parameterId); System.Data.DataView externalKeyView = Country.externalKeyArray[externalKeyIndex]; int recordIndex = externalKeyView.Find(new object[] { externalId}); if ((recordIndex == -1)) { return int.MinValue; } return ((int)(externalKeyView[recordIndex].Row[countryTable.CountryIdColumn])); }
/// <summary>Archives a Country record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Archive(ParameterList parameters) { // Accessor for the Country Table. ServerDataModel.CountryDataTable countryTable = ServerDataModel.Country; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalCountryId = parameters["countryId"]; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Find the internal identifier using the primar key elements. // identifier is used to determine if a record exists with the same key. int countryId = Country.FindRequiredKey(configurationId, "countryId", externalCountryId); // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerDataModel.CountryRow countryRow = countryTable.FindByCountryId(countryId); rowVersion = ((long)(countryRow[countryTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Quasar.Core.Country.Archive(adoTransaction, sqlTransaction, rowVersion, countryId); }