コード例 #1
0
        /// <summary>
        /// Get the command from provider, check connection is opened, affect connection and transaction
        /// Prepare the command parameters and add scope parameters
        /// </summary>
        public async Task <(DbCommand Command, bool IsBatch)> GetCommandAsync(DbCommandType commandType, DbConnection connection, DbTransaction transaction, SyncFilter filter = null)
        {
            // Create the key
            var commandKey = $"{connection.DataSource}-{connection.Database}-{this.TableDescription.GetFullName()}-{commandType}";

            var(command, isBatch) = GetCommand(commandType, filter);

            if (command == null)
            {
                return(null, false);
            }

            // Add Parameters
            await this.AddCommandParametersAsync(commandType, command, connection, transaction, filter).ConfigureAwait(false);

            if (command == null)
            {
                throw new MissingCommandException(commandType.ToString());
            }

            if (connection == null)
            {
                throw new MissingConnectionException();
            }

            if (connection.State != ConnectionState.Open)
            {
                throw new ConnectionClosedException(connection);
            }

            command.Connection  = connection;
            command.Transaction = transaction;

            // Get a lazy command instance
            var lazyCommand = commands.GetOrAdd(commandKey, k => new Lazy <SyncCommand>(() =>
            {
                var syncCommand = new SyncCommand(commandKey);
                return(syncCommand);
            }));

            // lazyCommand.Metadata is a boolean indicating if the command is already prepared on the server
            if (lazyCommand.Value.IsPrepared == true)
            {
                return(command, isBatch);
            }

            // Testing The Prepare() performance increase
            command.Prepare();

            // Adding this command as prepared
            lazyCommand.Value.IsPrepared = true;

            commands.AddOrUpdate(commandKey, lazyCommand, (key, lc) => new Lazy <SyncCommand>(() => lc.Value));

            return(command, isBatch);
        }
コード例 #2
0
        public string GetCommandName(DbCommandType objectType, IEnumerable <string> adds = null)
        {
            if (!_names.ContainsKey(objectType))
            {
                throw new NotSupportedException(
                          $"MySql provider does not support the command type {objectType.ToString()}");
            }

            return(_names[objectType]);
        }
コード例 #3
0
ファイル: SyncAdapter.cs プロジェクト: vanbinh85/Dotmim.Sync
        /// <summary>
        /// Get the command from provider, check connection is opened, affect connection and transaction
        /// Prepare the command parameters and add scope parameters
        /// </summary>
        internal async Task <DbCommand> PrepareCommandAsync(DbCommandType commandType, DbConnection connection, DbTransaction transaction, SyncFilter filter = null)
        {
            // Create the key
            var commandKey = $"{connection.DataSource}-{connection.Database}-{this.TableDescription.GetFullName()}-{commandType}";

            // Get a lazy command instance
            var lazyCommand = commands.GetOrAdd(commandKey, k => new Lazy <DbCommand>(() => GetCommand(commandType, filter)));

            // Get the concrete instance
            var command = lazyCommand.Value;

            if (command == null)
            {
                throw new MissingCommandException(commandType.ToString());
            }

            if (connection == null)
            {
                throw new MissingConnectionException();
            }

            if (connection.State != ConnectionState.Open)
            {
                throw new ConnectionClosedException(connection);
            }

            command.Connection = connection;

            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            // Add Parameters
            await this.AddCommandParametersAsync(commandType, command, connection, transaction, filter).ConfigureAwait(false);

            // Testing The Prepare() performance increase
            command.Prepare();

            return(command);
        }
コード例 #4
0
        public string GetCommandName(DbCommandType objectType, SyncFilter filter = null)
        {
            if (!names.ContainsKey(objectType))
            {
                throw new NotSupportedException($"Sqlite provider does not support the command type {objectType.ToString()}");
            }

            var commandName = names[objectType];

            // concat filter name
            //if (filter != null)
            //    commandName = string.Format(commandName, filter.GetFilterName());

            return(commandName);
        }
コード例 #5
0
        public string GetCommandName(DbCommandType objectType, IEnumerable <FilterClause> filters = null)
        {
            if (!names.ContainsKey(objectType))
            {
                throw new NotSupportedException($"Sqlite provider does not support the command type {objectType.ToString()}");
            }

            var commandName = names[objectType];

            if (filters != null)
            {
                string name = "";
                string sep  = "";
                foreach (var c in filters)
                {
                    var columnName = ParserName.Parse(c.ColumnName).Unquoted().Normalized().ToString();
                    name += $"{columnName}{sep}";
                    sep   = "_";
                }

                commandName = string.Format(commandName, name);
            }

            return(commandName);
        }