Beispiel #1
0
        /// <summary>ArchiveChildrens a Scheme 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="schemeId">The value for the SchemeId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int schemeId)
        {
            // Accessor for the Scheme Table.
            ServerDataModel.SchemeDataTable schemeTable = ServerDataModel.Scheme;
            // This record can be used to iterate through all the children.
            ServerDataModel.SchemeRow schemeRow = schemeTable.FindBySchemeId(schemeId);
            // Archive the child records.
            for (int index = 0; (index < schemeRow.GetAccountRows().Length); index = (index + 1))
            {
                ServerDataModel.AccountRow childAccountRow = schemeRow.GetAccountRows()[index];
                Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId);
            }
            for (int index = 0; (index < schemeRow.GetModelRows().Length); index = (index + 1))
            {
                ServerDataModel.ModelRow childModelRow = schemeRow.GetModelRows()[index];
                Model.ArchiveChildren(adoTransaction, sqlTransaction, childModelRow.RowVersion, childModelRow.ModelId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            schemeRow[schemeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(schemeRow);
            schemeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Scheme\" set \"IsArchived\" = 1 where \"SchemeId\"=@schemeId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@schemeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, schemeId));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #2
0
        /// <summary>Archives a ModelType 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="modelTypeCode">The value for the ModelTypeCode 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 modelTypeCode)
        {
            // Accessor for the ModelType Table.
            ServerDataModel.ModelTypeDataTable modelTypeTable = ServerDataModel.ModelType;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ModelTypeRow modelTypeRow = modelTypeTable.FindByModelTypeCode(modelTypeCode);
            if ((modelTypeRow == null))
            {
                throw new Exception(string.Format("The ModelType table does not have an element identified by {0}", modelTypeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((modelTypeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < modelTypeRow.GetModelRows().Length); index = (index + 1))
            {
                ServerDataModel.ModelRow childModelRow = modelTypeRow.GetModelRows()[index];
                Model.ArchiveChildren(adoTransaction, sqlTransaction, childModelRow.RowVersion, childModelRow.ModelId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            modelTypeRow[modelTypeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(modelTypeRow);
            modelTypeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"ModelType\" set \"IsArchived\" = 1 where \"ModelTypeCode\"=@modelTypeCode");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@modelTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelTypeCode));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #3
0
 /// <summary>Updates a Model record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Update(ParameterList parameters)
 {
     // Accessor for the Model Table.
     ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object description = parameters["description"].Value;
     object groupPermission = parameters["groupPermission"].Value;
     object hidden = parameters["hidden"].Value;
     object name = parameters["name"].Value;
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     string externalModelId = ((string)(parameters["modelId"]));
     object externalAlgorithmId = parameters["algorithmId"].Value;
     object externalSchemeId = parameters["schemeId"].Value;
     object externalTypeCode = parameters["typeCode"].Value;
     object externalModelTypeCode = parameters["modelTypeCode"].Value;
     object temporary = parameters["temporary"].Value;
     object securitySelf = parameters["securitySelf"].Value;
     object sectorSelf = parameters["sectorSelf"].Value;
     object equityRounding = parameters["equityRounding"].Value;
     object debtRounding = parameters["debtRounding"].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 modelId = Object.FindRequiredKey(configurationId, "modelId", externalModelId);
     object algorithmId = Algorithm.FindOptionalKey(configurationId, "algorithmId", externalAlgorithmId);
     object schemeId = Scheme.FindOptionalKey(configurationId, "schemeId", externalSchemeId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     object modelTypeCode = ModelType.FindOptionalKey(configurationId, "modelTypeCode", externalModelTypeCode);
     // This disables the concurrency checking logic by finding the current row version and passing it to the
     // internal method.
     ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId);
     rowVersion = ((long)(modelRow[modelTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.Model.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, modelId, algorithmId, schemeId, typeCode, modelTypeCode, temporary, securitySelf, sectorSelf, equityRounding, debtRounding);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Beispiel #4
0
        /// <summary>Archives a Model 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="modelId">The value for the ModelId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public new static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int modelId)
        {
            // Accessor for the Model Table.
            ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId);
            if ((modelRow == null))
            {
                throw new Exception(string.Format("The Model table does not have an element identified by {0}", modelId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((modelRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Delete the base class record.  Note that optimistic concurrency is only used
            // by the top level type in the hierarchy, it is bypassed after you pass the first test.
            long baseRowVersion = modelRow.ObjectRow.RowVersion;

            Object.Archive(adoTransaction, sqlTransaction, baseRowVersion, modelId);
        }
Beispiel #5
0
        /// <summary>Deletes a Algorithm 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="algorithmId">The value for the AlgorithmId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Delete(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int algorithmId)
        {
            // Accessor for the Algorithm Table.
            ServerDataModel.AlgorithmDataTable algorithmTable = ServerDataModel.Algorithm;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.AlgorithmRow algorithmRow = algorithmTable.FindByAlgorithmId(algorithmId);
            if ((algorithmRow == null))
            {
                throw new Exception(string.Format("The Algorithm table does not have an element identified by {0}", algorithmId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((algorithmRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Delete the child records.
            for (int index = 0; (index < algorithmRow.GetBlotterRows().Length); index = (index + 1))
            {
                ServerDataModel.BlotterRow childBlotterRow = algorithmRow.GetBlotterRows()[index];
                Blotter.DeleteChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId);
            }
            for (int index = 0; (index < algorithmRow.GetModelRows().Length); index = (index + 1))
            {
                ServerDataModel.ModelRow childModelRow = algorithmRow.GetModelRows()[index];
                Model.DeleteChildren(adoTransaction, sqlTransaction, childModelRow.RowVersion, childModelRow.ModelId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            algorithmRow[algorithmTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(algorithmRow);
            algorithmRow.Delete();
            // Delete the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Algorithm\" set \"IsDeleted\" = 1 where \"AlgorithmId\"=@algorithmId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@algorithmId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, algorithmId));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #6
0
 /// <summary>Archives a Model record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Archive(ParameterList parameters)
 {
     // Accessor for the Model Table.
     ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalModelId = parameters["modelId"];
     // 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;
     // Find the internal identifier using the primary key elements.
     // identifier is used to determine if a record exists with the same key.
     int modelId = Model.FindRequiredKey(configurationId, "modelId", externalModelId);
     // This disables the concurrency checking logic by finding the current row version and passing it to the
     // internal method.
     ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId);
     rowVersion = ((long)(modelRow[modelTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.Model.Archive(adoTransaction, sqlTransaction, rowVersion, modelId);
 }
Beispiel #7
0
        /// <summary>ArchiveChildrens a Model 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="modelId">The value for the ModelId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int modelId)
        {
            // Accessor for the Model Table.
            ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
            // This record can be used to iterate through all the children.
            ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId);
            // Archive the child records.
            for (int index = 0; (index < modelRow.GetAccountRows().Length); index = (index + 1))
            {
                ServerDataModel.AccountRow childAccountRow = modelRow.GetAccountRows()[index];
                Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId);
            }
            for (int index = 0; (index < modelRow.GetPositionTargetRows().Length); index = (index + 1))
            {
                ServerDataModel.PositionTargetRow childPositionTargetRow = modelRow.GetPositionTargetRows()[index];
                PositionTarget.Archive(adoTransaction, sqlTransaction, childPositionTargetRow.RowVersion, childPositionTargetRow.ModelId, childPositionTargetRow.SecurityId, childPositionTargetRow.PositionTypeCode);
            }
            for (int index = 0; (index < modelRow.GetSectorTargetRows().Length); index = (index + 1))
            {
                ServerDataModel.SectorTargetRow childSectorTargetRow = modelRow.GetSectorTargetRows()[index];
                SectorTarget.Archive(adoTransaction, sqlTransaction, childSectorTargetRow.RowVersion, childSectorTargetRow.ModelId, childSectorTargetRow.SectorId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            modelRow[modelTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(modelRow);
            modelRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Model\" set \"IsArchived\" = 1 where \"ModelId\"=@modelId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@modelId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelId));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #8
0
        /// <summary>Updates a Model 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="description">The value for the Description column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="externalId1">The value for the ExternalId1 column.</param>
        /// <param name="externalId2">The value for the ExternalId2 column.</param>
        /// <param name="externalId3">The value for the ExternalId3 column.</param>
        /// <param name="externalId4">The value for the ExternalId4 column.</param>
        /// <param name="externalId5">The value for the ExternalId5 column.</param>
        /// <param name="externalId6">The value for the ExternalId6 column.</param>
        /// <param name="externalId7">The value for the ExternalId7 column.</param>
        /// <param name="groupPermission">The value for the GroupPermission column.</param>
        /// <param name="hidden">The value for the Hidden column.</param>
        /// <param name="name">The value for the Name column.</param>
        /// <param name="owner">The value for the Owner column.</param>
        /// <param name="ownerPermission">The value for the OwnerPermission column.</param>
        /// <param name="readOnly">The value for the ReadOnly column.</param>
        /// <param name="worldPermission">The value for the WorldPermission column.</param>
        /// <param name="modelId">The value for the ModelId column.</param>
        /// <param name="algorithmId">The value for the AlgorithmId column.</param>
        /// <param name="schemeId">The value for the SchemeId column.</param>
        /// <param name="typeCode">The value for the TypeCode column.</param>
        /// <param name="modelTypeCode">The value for the ModelTypeCode column.</param>
        /// <param name="temporary">The value for the Temporary column.</param>
        /// <param name="securitySelf">The value for the SecuritySelf column.</param>
        /// <param name="sectorSelf">The value for the SectorSelf column.</param>
        /// <param name="equityRounding">The value for the EquityRounding column.</param>
        /// <param name="debtRounding">The value for the DebtRounding column.</param>
        public static void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object description,
            object externalId0,
            object externalId1,
            object externalId2,
            object externalId3,
            object externalId4,
            object externalId5,
            object externalId6,
            object externalId7,
            object groupPermission,
            object hidden,
            object name,
            object owner,
            object ownerPermission,
            object readOnly,
            object worldPermission,
            int modelId,
            object algorithmId,
            object schemeId,
            object typeCode,
            object modelTypeCode,
            object temporary,
            object securitySelf,
            object sectorSelf,
            object equityRounding,
            object debtRounding)
        {
            // Accessor for the Model Table.
            ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId);
            if ((modelRow == null))
            {
                throw new Exception(string.Format("The Model table does not have an element identified by {0}", modelId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((modelRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((algorithmId == null))
            {
                algorithmId = modelRow[modelTable.AlgorithmIdColumn];
            }
            if ((schemeId == null))
            {
                schemeId = modelRow[modelTable.SchemeIdColumn];
            }
            if ((modelTypeCode == null))
            {
                modelTypeCode = modelRow[modelTable.ModelTypeCodeColumn];
            }
            if ((temporary == null))
            {
                temporary = modelRow[modelTable.TemporaryColumn];
            }
            if ((securitySelf == null))
            {
                securitySelf = modelRow[modelTable.SecuritySelfColumn];
            }
            if ((sectorSelf == null))
            {
                sectorSelf = modelRow[modelTable.SectorSelfColumn];
            }
            if ((equityRounding == null))
            {
                equityRounding = modelRow[modelTable.EquityRoundingColumn];
            }
            if ((debtRounding == null))
            {
                debtRounding = modelRow[modelTable.DebtRoundingColumn];
            }
            // Insert the base members using the base class.  Note that optimistic concurrency is only used
            // by the top level type in the hierarchy, it is bypassed after you pass the first test.
            long baseRowVersion = modelRow.ObjectRow.RowVersion;

            Object.Update(adoTransaction, sqlTransaction, ref baseRowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, modelId, owner, ownerPermission, readOnly, typeCode, worldPermission);
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Update the record in the ADO database.
            modelRow[modelTable.RowVersionColumn]     = rowVersion;
            modelRow[modelTable.AlgorithmIdColumn]    = algorithmId;
            modelRow[modelTable.SchemeIdColumn]       = schemeId;
            modelRow[modelTable.ModelTypeCodeColumn]  = modelTypeCode;
            modelRow[modelTable.TemporaryColumn]      = temporary;
            modelRow[modelTable.SecuritySelfColumn]   = securitySelf;
            modelRow[modelTable.SectorSelfColumn]     = sectorSelf;
            modelRow[modelTable.EquityRoundingColumn] = equityRounding;
            modelRow[modelTable.DebtRoundingColumn]   = debtRounding;
            adoTransaction.DataRows.Add(modelRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""Model"" set ""RowVersion""=@rowVersion,""AlgorithmId""=@algorithmId,""SchemeId""=@schemeId,""ModelTypeCode""=@modelTypeCode,""Temporary""=@temporary,""SecuritySelf""=@securitySelf,""SectorSelf""=@sectorSelf,""EquityRounding""=@equityRounding,""DebtRounding""=@debtRounding where ""ModelId""=@modelId");

            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("@modelId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelId));
            sqlCommand.Parameters.Add(new SqlParameter("@algorithmId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, algorithmId));
            sqlCommand.Parameters.Add(new SqlParameter("@schemeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, schemeId));
            sqlCommand.Parameters.Add(new SqlParameter("@modelTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@temporary", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, temporary));
            sqlCommand.Parameters.Add(new SqlParameter("@securitySelf", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securitySelf));
            sqlCommand.Parameters.Add(new SqlParameter("@sectorSelf", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sectorSelf));
            sqlCommand.Parameters.Add(new SqlParameter("@equityRounding", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, equityRounding));
            sqlCommand.Parameters.Add(new SqlParameter("@debtRounding", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, debtRounding));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #9
0
        /// <summary>Inserts a Model 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="description">The value for the Description column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="externalId1">The value for the ExternalId1 column.</param>
        /// <param name="externalId2">The value for the ExternalId2 column.</param>
        /// <param name="externalId3">The value for the ExternalId3 column.</param>
        /// <param name="externalId4">The value for the ExternalId4 column.</param>
        /// <param name="externalId5">The value for the ExternalId5 column.</param>
        /// <param name="externalId6">The value for the ExternalId6 column.</param>
        /// <param name="externalId7">The value for the ExternalId7 column.</param>
        /// <param name="groupPermission">The value for the GroupPermission column.</param>
        /// <param name="hidden">The value for the Hidden column.</param>
        /// <param name="name">The value for the Name column.</param>
        /// <param name="owner">The value for the Owner column.</param>
        /// <param name="ownerPermission">The value for the OwnerPermission column.</param>
        /// <param name="readOnly">The value for the ReadOnly column.</param>
        /// <param name="worldPermission">The value for the WorldPermission column.</param>
        /// <param name="algorithmId">The value for the AlgorithmId column.</param>
        /// <param name="schemeId">The value for the SchemeId column.</param>
        /// <param name="typeCode">The value for the TypeCode column.</param>
        /// <param name="modelTypeCode">The value for the ModelTypeCode column.</param>
        /// <param name="temporary">The value for the Temporary column.</param>
        /// <param name="securitySelf">The value for the SecuritySelf column.</param>
        /// <param name="sectorSelf">The value for the SectorSelf column.</param>
        /// <param name="equityRounding">The value for the EquityRounding column.</param>
        /// <param name="debtRounding">The value for the DebtRounding column.</param>
        public static int Insert(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object description,
            object externalId0,
            object externalId1,
            object externalId2,
            object externalId3,
            object externalId4,
            object externalId5,
            object externalId6,
            object externalId7,
            object groupPermission,
            object hidden,
            string name,
            object owner,
            object ownerPermission,
            object readOnly,
            object worldPermission,
            int algorithmId,
            object schemeId,
            object typeCode,
            int modelTypeCode,
            object temporary,
            object securitySelf,
            object sectorSelf,
            object equityRounding,
            object debtRounding)
        {
            // Accessor for the Model Table.
            ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
            // Apply Defaults
            if ((schemeId == null))
            {
                schemeId = System.DBNull.Value;
            }
            if ((typeCode == null))
            {
                typeCode = "Model";
            }
            if ((temporary == null))
            {
                temporary = false;
            }
            if ((securitySelf == null))
            {
                securitySelf = false;
            }
            if ((sectorSelf == null))
            {
                sectorSelf = false;
            }
            if ((equityRounding == null))
            {
                equityRounding = 100m;
            }
            if ((debtRounding == null))
            {
                debtRounding = 1000m;
            }
            // Insert the base members using the base class.
            int modelId = Object.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, owner, ownerPermission, readOnly, typeCode, worldPermission);

            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerDataModel.ModelRow modelRow = modelTable.NewModelRow();
            modelRow[modelTable.RowVersionColumn]     = rowVersion;
            modelRow[modelTable.ModelIdColumn]        = modelId;
            modelRow[modelTable.AlgorithmIdColumn]    = algorithmId;
            modelRow[modelTable.SchemeIdColumn]       = schemeId;
            modelRow[modelTable.ModelTypeCodeColumn]  = modelTypeCode;
            modelRow[modelTable.TemporaryColumn]      = temporary;
            modelRow[modelTable.SecuritySelfColumn]   = securitySelf;
            modelRow[modelTable.SectorSelfColumn]     = sectorSelf;
            modelRow[modelTable.EquityRoundingColumn] = equityRounding;
            modelRow[modelTable.DebtRoundingColumn]   = debtRounding;
            modelTable.AddModelRow(modelRow);
            adoTransaction.DataRows.Add(modelRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"insert ""Model"" (""rowVersion"",ModelId,AlgorithmId,SchemeId,ModelTypeCode,Temporary,SecuritySelf,SectorSelf,EquityRounding,DebtRounding) values (@rowVersion,@modelId,@algorithmId,@schemeId,@modelTypeCode,@temporary,@securitySelf,@sectorSelf,@equityRounding,@debtRounding)");

            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("@modelId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelId));
            sqlCommand.Parameters.Add(new SqlParameter("@algorithmId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, algorithmId));
            sqlCommand.Parameters.Add(new SqlParameter("@schemeId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, schemeId));
            sqlCommand.Parameters.Add(new SqlParameter("@modelTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modelTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@temporary", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, temporary));
            sqlCommand.Parameters.Add(new SqlParameter("@securitySelf", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securitySelf));
            sqlCommand.Parameters.Add(new SqlParameter("@sectorSelf", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, sectorSelf));
            sqlCommand.Parameters.Add(new SqlParameter("@equityRounding", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, equityRounding));
            sqlCommand.Parameters.Add(new SqlParameter("@debtRounding", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, debtRounding));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(modelRow.ModelId);
        }
Beispiel #10
0
        /// <summary>Archives a Object 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="objectId">The value for the ObjectId 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 objectId)
        {
            // Accessor for the Object Table.
            ServerDataModel.ObjectDataTable objectTable = ServerDataModel.Object;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.ObjectRow objectRow = objectTable.FindByObjectId(objectId);
            if ((objectRow == null))
            {
                throw new Exception(string.Format("The Object table does not have an element identified by {0}", objectId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((objectRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < objectRow.GetFolderRows().Length); index = (index + 1))
            {
                ServerDataModel.FolderRow childFolderRow = objectRow.GetFolderRows()[index];
                Folder.ArchiveChildren(adoTransaction, sqlTransaction, childFolderRow.RowVersion, childFolderRow.FolderId);
            }
            for (int index = 0; (index < objectRow.GetAccountRows().Length); index = (index + 1))
            {
                ServerDataModel.AccountRow childAccountRow = objectRow.GetAccountRows()[index];
                Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId);
            }
            for (int index = 0; (index < objectRow.GetBlotterRows().Length); index = (index + 1))
            {
                ServerDataModel.BlotterRow childBlotterRow = objectRow.GetBlotterRows()[index];
                Blotter.ArchiveChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId);
            }
            for (int index = 0; (index < objectRow.GetBrokerRows().Length); index = (index + 1))
            {
                ServerDataModel.BrokerRow childBrokerRow = objectRow.GetBrokerRows()[index];
                Broker.ArchiveChildren(adoTransaction, sqlTransaction, childBrokerRow.RowVersion, childBrokerRow.BrokerId);
            }
            for (int index = 0; (index < objectRow.GetIssuerRows().Length); index = (index + 1))
            {
                ServerDataModel.IssuerRow childIssuerRow = objectRow.GetIssuerRows()[index];
                Issuer.ArchiveChildren(adoTransaction, sqlTransaction, childIssuerRow.RowVersion, childIssuerRow.IssuerId);
            }
            for (int index = 0; (index < objectRow.GetUserRows().Length); index = (index + 1))
            {
                ServerDataModel.UserRow childUserRow = objectRow.GetUserRows()[index];
                User.ArchiveChildren(adoTransaction, sqlTransaction, childUserRow.RowVersion, childUserRow.UserId);
            }
            for (int index = 0; (index < objectRow.GetModelRows().Length); index = (index + 1))
            {
                ServerDataModel.ModelRow childModelRow = objectRow.GetModelRows()[index];
                Model.ArchiveChildren(adoTransaction, sqlTransaction, childModelRow.RowVersion, childModelRow.ModelId);
            }
            for (int index = 0; (index < objectRow.GetObjectTreeRowsByFKObjectObjectTreeChildId().Length); index = (index + 1))
            {
                ServerDataModel.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByFKObjectObjectTreeChildId()[index];
                ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ParentId, childObjectTreeRow.ChildId);
            }
            for (int index = 0; (index < objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId().Length); index = (index + 1))
            {
                ServerDataModel.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId()[index];
                ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ParentId, childObjectTreeRow.ChildId);
            }
            for (int index = 0; (index < objectRow.GetSchemeRows().Length); index = (index + 1))
            {
                ServerDataModel.SchemeRow childSchemeRow = objectRow.GetSchemeRows()[index];
                Scheme.ArchiveChildren(adoTransaction, sqlTransaction, childSchemeRow.RowVersion, childSchemeRow.SchemeId);
            }
            for (int index = 0; (index < objectRow.GetSectorRows().Length); index = (index + 1))
            {
                ServerDataModel.SectorRow childSectorRow = objectRow.GetSectorRows()[index];
                Sector.ArchiveChildren(adoTransaction, sqlTransaction, childSectorRow.RowVersion, childSectorRow.SectorId);
            }
            for (int index = 0; (index < objectRow.GetSecurityRows().Length); index = (index + 1))
            {
                ServerDataModel.SecurityRow childSecurityRow = objectRow.GetSecurityRows()[index];
                Security.ArchiveChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            objectRow[objectTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(objectRow);
            objectRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Object\" set \"IsArchived\" = 1 where \"ObjectId\"=@objectId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@objectId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectId));
            sqlCommand.ExecuteNonQuery();
        }
Beispiel #11
0
 /// <summary>Loads a Model record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Load(ParameterList parameters)
 {
     // Accessor for the Model Table.
     ServerDataModel.ModelDataTable modelTable = ServerDataModel.Model;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object description = parameters["description"].Value;
     object groupPermission = parameters["groupPermission"].Value;
     object hidden = parameters["hidden"].Value;
     string name = parameters["name"];
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     string externalModelId = parameters["modelId"];
     string externalAlgorithmId = parameters["algorithmId"];
     object externalSchemeId = parameters["schemeId"].Value;
     object externalTypeCode = parameters["typeCode"].Value;
     string externalModelTypeCode = parameters["modelTypeCode"];
     object temporary = parameters["temporary"].Value;
     object securitySelf = parameters["securitySelf"].Value;
     object sectorSelf = parameters["sectorSelf"].Value;
     object equityRounding = parameters["equityRounding"].Value;
     object debtRounding = parameters["debtRounding"].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 modelId = Object.FindKey(configurationId, "modelId", externalModelId);
     int algorithmId = Algorithm.FindRequiredKey(configurationId, "algorithmId", externalAlgorithmId);
     object schemeId = Scheme.FindOptionalKey(configurationId, "schemeId", externalSchemeId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     int modelTypeCode = ModelType.FindRequiredKey(configurationId, "modelTypeCode", externalModelTypeCode);
     ServerDataModel.ModelRow modelRow = modelTable.FindByModelId(modelId);
     // 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 ((modelRow == null))
     {
         // 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 = Model.GetExternalKeyIndex(configurationId, "modelId");
         object[] externalIdArray = new object[8];
         externalIdArray[externalKeyIndex] = externalModelId;
         object externalId0 = externalIdArray[0];
         object externalId1 = externalIdArray[1];
         object externalId2 = externalIdArray[2];
         object externalId3 = externalIdArray[3];
         object externalId4 = externalIdArray[4];
         object externalId5 = externalIdArray[5];
         object externalId6 = externalIdArray[6];
         object externalId7 = externalIdArray[7];
         // Call the internal method to complete the operation.
         MarkThree.Quasar.Core.Model.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, algorithmId, schemeId, typeCode, modelTypeCode, temporary, securitySelf, sectorSelf, equityRounding, debtRounding);
     }
     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.
         rowVersion = ((long)(modelRow[modelTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Quasar.Core.Model.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, modelId, algorithmId, schemeId, typeCode, modelTypeCode, temporary, securitySelf, sectorSelf, equityRounding, debtRounding);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }