Example #1
0
        protected void PerformFullTableCheck(IManageable model, string connectionToUse)
        {
            if (model.IsFullyValidated)
            {
                Logger.Info($"Table {model.Configuration.TableName} has already been validated with it's current state.");
                return;
            }

            Logger.Info($"Processing table {model.Configuration.TableName} using connection {connectionToUse}.");
            model.IsFullyValidated = true;
            string schema         = Manager.ConnectionType == ConnectionTypes.MSSQL ? model.Configuration.Schema : ConsolidationTools.GetInitialCatalog(connectionToUse, true);
            string initialCatalog = ConsolidationTools.GetInitialCatalog(connectionToUse);
            Dictionary <string, ConstraintDefinition> constraints = GetConstraints(initialCatalog, schema, model.Configuration.TableName, connectionToUse);

            if (DoTableExist(initialCatalog, schema, model.Configuration.TableName, connectionToUse))
            {
                ExecuteScalar(_creator.CreateQueryForTableAlteration(model, GetColumnDefinition(initialCatalog, model.Configuration.Schema, model.Configuration.TableName, connectionToUse), constraints), connectionToUse, false);
            }
            else
            {
                ExecuteScalar(_creator.CreateQueryForTableCreation(model), connectionToUse, false);
            }

            VerifyForeignTables(model, connectionToUse);
            string foreignKeyQuery = _creator.GetCreateForeignKeysQuery(model, constraints);

            if (!string.IsNullOrWhiteSpace(foreignKeyQuery))
            {
                ExecuteScalar(foreignKeyQuery, connectionToUse, false);
            }
        }
Example #2
0
        protected void PerformStoredProcedureValidation <T>(TransactionTypes transactionType, QueryOptions queryOptions) where T : Cope <T>, IManageable, new()
        {
            TransactionTypes singleTransactionType;

            switch (transactionType)
            {
            case TransactionTypes.InsertMassive:
                singleTransactionType = TransactionTypes.Insert;
                break;

            case TransactionTypes.UpdateMassive:
                singleTransactionType = TransactionTypes.Update;
                break;

            case TransactionTypes.DeleteMassive:
                singleTransactionType = TransactionTypes.Delete;
                break;

            default:
                throw new NotSupportedException($"El tipo de transaccion {transactionType.ToString()} no puede ser utilizado con esta funcion.");
            }

            string schema = Manager.ConnectionType == ConnectionTypes.MSSQL ? Cope <T> .ModelComposition.Schema : ConsolidationTools.GetInitialCatalog(queryOptions.ConnectionToUse, true);

            if (!DoStoredProcedureExist(ConsolidationTools.GetInitialCatalog(queryOptions.ConnectionToUse), schema, $"{Manager.StoredProcedurePrefix}massive_operation", queryOptions.ConnectionToUse))
            {
                ExecuteScalar(GetTransactionTextForProcedure <T>(transactionType, false), queryOptions.ConnectionToUse, false);
            }

            if (!DoStoredProcedureExist(ConsolidationTools.GetInitialCatalog(queryOptions.ConnectionToUse), schema, $"{Manager.StoredProcedurePrefix}{Cope<T>.ModelComposition.TableName}{GetFriendlyTransactionSuffix(singleTransactionType)}", queryOptions.ConnectionToUse))
            {
                ExecuteScalar(GetTransactionTextForProcedure <T>(singleTransactionType, false), queryOptions.ConnectionToUse, false);
            }
        }
Example #3
0
        private void VerifyForeignTables(IManageable model, string connectionToUse)
        {
            Logger.Info(string.Format("Verifying foreign tables for type {0} using connection {1}.", model.GetType().ToString(), connectionToUse));

            foreach (KeyValuePair <string, PropertyInfo> property in model.Configuration.ForeignKeyProperties)
            {
                IManageable foreignModel = (IManageable)Activator.CreateInstance(model.Configuration.ForeignKeyAttributes[property.Value.Name].Model);
                string      schema       = Manager.ConnectionType == ConnectionTypes.MSSQL ? foreignModel.Configuration.Schema : ConsolidationTools.GetInitialCatalog(connectionToUse, true);
                PerformFullTableCheck(foreignModel, connectionToUse);
            }
        }