Esempio n. 1
0
        public string BuildCreateContainerSql(CreateContainerModel model)
        {
            var builder = new StringBuilder();

            builder.AppendLine($"CREATE TABLE {Sanitize(model.Name)} (");

            var index = 0;
            var count = model.DataTypes.Count;

            foreach (var type in model.DataTypes)
            {
                builder.AppendLine($"{Sanitize(type.Name)} {GetDbType(type.Type)} NULL{(index < count - 1 ? "," : "")}");

                index++;
            }

            builder.AppendLine(");");

            var sql = builder.ToString();

            return(sql);
        }
Esempio n. 2
0
        public override async Task CreateContainer(ExecutionContext executionContext, Guid providerDefinitionId, CreateContainerModel model)
        {
            var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId);

            async Task CreateTable(string name, IEnumerable <ConnectionDataType> columns, string context)
            {
                var sql = BuildCreateContainerSql(name, columns);

                _logger.LogDebug("Sql Server Connector - Create Container[{Context}] - Generated query: {sql}", context, sql);

                try
                {
                    await _client.ExecuteCommandAsync(config, sql);
                }
                catch (Exception e)
                {
                    var message = $"Could not create Container {name} for Connector {providerDefinitionId}";
                    _logger.LogError(e, message);
                    throw new CreateContainerException(message);
                }
            }

            var tasks = new List <Task> {
                CreateTable(model.Name, model.DataTypes, "Data")
            };

            if (model.CreateEdgeTable)
            {
                tasks.Add(CreateTable(EdgeContainerHelper.GetName(model.Name), new List <ConnectionDataType>
                {
                    new ConnectionDataType {
                        Name = Sanitize("OriginEntityCode"), Type = VocabularyKeyDataType.Text
                    },
                    new ConnectionDataType {
                        Name = Sanitize("Code"), Type = VocabularyKeyDataType.Text
                    },
                }, "Edges"));
            }

            await Task.WhenAll(tasks);
        }
Esempio n. 3
0
        public override async Task CreateContainer(ExecutionContext executionContext, Guid providerDefinitionId,
                                                   CreateContainerModel model)
        {
            try
            {
                var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId);

                await CheckDbSchemaAsync(config.Authentication);

                async Task createTable(string tableName, IEnumerable <ConnectionDataType> columns,
                                       IEnumerable <string> keys, string context)
                {
                    try
                    {
                        var commands = _features.GetFeature <IBuildCreateContainerFeature>()
                                       .BuildCreateContainerSql(tableName, columns, keys, context, StreamMode, _logger);

                        // Do not create IDX on PrimaryTable if we are in SyncMode. It has a PK
                        if (context != "Data" || context == "Data" && StreamMode == StreamMode.EventStream)
                        {
                            var indexCommands = _features.GetFeature <IBuildCreateIndexFeature>()
                                                .BuildCreateIndexSql(tableName, _defaultKeyFields, _logger);

                            commands = commands.Union(indexCommands);
                        }

                        foreach (var command in commands)
                        {
                            _logger.LogDebug(
                                "Sql Server Connector - Create Container[{Context}] - Generated query: {sql}", context,
                                command.Text);

                            await _client.ExecuteCommandAsync(config, command.Text, command.Parameters);
                        }
                    }
                    catch (Exception e)
                    {
                        var message = $"Could not create Container {tableName} for Connector {providerDefinitionId}";
                        _logger.LogError(e, message);
                        throw new CreateContainerException(message);
                    }
                }

                var container  = new Container(model.Name, StreamMode);
                var codesTable = container.Tables["Codes"];

                var connectionDataTypes = model.DataTypes;

                if (StreamMode == StreamMode.EventStream)
                {
                    connectionDataTypes.Add(new ConnectionDataType
                    {
                        Name = TimestampFieldName,
                        Type = VocabularyKeyDataType.DateTime
                    });
                    connectionDataTypes.Add(new ConnectionDataType
                    {
                        Name = ChangeTypeFieldName,
                        Type = VocabularyKeyDataType.Text
                    });
                    connectionDataTypes.Add(new ConnectionDataType
                    {
                        Name = CorrelationIdFieldName,
                        Type = VocabularyKeyDataType.Text
                    });
                }
                else
                {
                    connectionDataTypes.Add(new ConnectionDataType
                    {
                        Name = TimestampFieldName,
                        Type = VocabularyKeyDataType.DateTime
                    });
                }

                var tasks = new List <Task>
                {
                    // Primary table
                    createTable(container.PrimaryTable, connectionDataTypes, _defaultKeyFields, "Data"),

                    // Codes table
                    createTable(codesTable.Name, codesTable.Columns, codesTable.Keys, "Codes")
                };

                // We optionally build an edges table
                if (model.CreateEdgeTable)
                {
                    var edgesTable = container.Tables["Edges"];
                    tasks.Add(createTable(edgesTable.Name, edgesTable.Columns, edgesTable.Keys, "Edges"));
                }

                await Task.WhenAll(tasks);
            }
            catch (Exception e)
            {
                var message = $"Could not create Container {model.Name} for Connector {providerDefinitionId}";
                _logger.LogError(e, message);
                throw new CreateContainerException(message);
            }
        }
Esempio n. 4
0
        public override async Task CreateContainer(ExecutionContext executionContext, Guid providerDefinitionId, CreateContainerModel model)
        {
            try
            {
                var config = await base.GetAuthenticationDetails(executionContext, providerDefinitionId);

                var sql = BuildCreateContainerSql(model);

                _logger.LogDebug($"Snowflake Connector - Create Container - Generated query: {sql}");

                await _client.ExecuteCommandAsync(config, sql);
            }
            catch (Exception e)
            {
                var message = $"Could not create Container {model.Name} for Connector {providerDefinitionId}";
                _logger.LogError(e, message);
                //throw new CreateContainerException(message);
            }
        }