Ejemplo n.º 1
0
        public ClusterTransactionCommand(string databaseName, char identityPartsSeparator, DatabaseTopology topology,
                                         ArraySegment <BatchRequestParser.CommandData> commandParsedCommands,
                                         ClusterTransactionOptions options, string uniqueRequestId) : base(uniqueRequestId)
        {
            DatabaseName         = databaseName;
            DatabaseRecordId     = topology.DatabaseTopologyIdBase64 ?? Guid.NewGuid().ToBase64Unpadded();
            ClusterTransactionId = topology.ClusterTransactionIdBase64 ?? Guid.NewGuid().ToBase64Unpadded();
            Options = options;
            CommandCreationTicks = SystemTime.UtcNow.Ticks;

            foreach (var commandData in commandParsedCommands)
            {
                var command = ClusterTransactionDataCommand.FromCommandData(commandData);
                ClusterCommandValidation(command, identityPartsSeparator);
                switch (commandData.Type)
                {
                case CommandType.PUT:
                case CommandType.DELETE:
                    DatabaseCommands.Add(command);
                    break;

                case CommandType.CompareExchangePUT:
                case CommandType.CompareExchangeDELETE:
                    ClusterCommands.Add(command);
                    break;

                default:
                    throw new RachisApplyException($"The type '{commandData.Type}' is not supported in '{nameof(ClusterTransactionCommand)}.'");
                }
            }

            DatabaseCommandsCount = DatabaseCommands.Count;
        }
Ejemplo n.º 2
0
        public ClusterTransactionCommand(string databaseName, string recordId, ArraySegment <BatchRequestParser.CommandData> commandParsedCommands,
                                         ClusterTransactionOptions options)
        {
            DatabaseName     = databaseName;
            DatabaseRecordId = recordId ?? Guid.NewGuid().ToBase64Unpadded();
            Options          = options;

            foreach (var commandData in commandParsedCommands)
            {
                var command = ClusterTransactionDataCommand.FromCommandData(commandData);
                ClusterCommandValidation(command);
                switch (commandData.Type)
                {
                case CommandType.PUT:
                case CommandType.DELETE:
                    DatabaseCommands.Add(command);
                    break;

                case CommandType.CompareExchangePUT:
                case CommandType.CompareExchangeDELETE:
                    ClusterCommands.Add(command);
                    break;

                default:
                    throw new RachisApplyException($"The type '{commandData.Type}' is not supported in '{nameof(ClusterTransactionCommand)}.'");
                }
            }

            DatabaseCommandsCount = DatabaseCommands.Count;
        }
Ejemplo n.º 3
0
        public ClusterTransactionCommand(string database, ArraySegment <BatchRequestParser.CommandData> commandParsedCommands, ClusterTransactionOptions options)
        {
            Database = database;
            Options  = options;

            foreach (var commandData in commandParsedCommands)
            {
                var command = ClusterTransactionDataCommand.FromCommandData(commandData);
                ClusterCommandValidation(command);
                switch (commandData.Type)
                {
                case CommandType.PUT:
                case CommandType.DELETE:
                    DatabaseCommands.Add(command);
                    break;

                case CommandType.CompareExchangePUT:
                case CommandType.CompareExchangeDELETE:
                    ClusterCommands.Add(command);
                    break;

                default:
                    throw new ArgumentException($"The type '{commandData.Type}' is not supported in '{nameof(ClusterTransactionCommand)}.'");
                }
            }

            DatabaseCommandsCount = DatabaseCommands.Count;
        }
Ejemplo n.º 4
0
        private static void ClusterCommandValidation(ClusterTransactionDataCommand command, char identityPartsSeparator)
        {
            if (string.IsNullOrWhiteSpace(command.Id))
            {
                throw new RachisApplyException($"In {nameof(ClusterTransactionDataCommand)} document id cannot be null, empty or white spaces as part of cluster transaction. " +
                                               $"{nameof(command.Type)}:({command.Type}), {nameof(command.Index)}:({command.Index})");
            }

            var lastChar = command.Id[^ 1];
Ejemplo n.º 5
0
        private static void ClusterCommandValidation(ClusterTransactionDataCommand command)
        {
            var lastChar = command.Id[command.Id.Length - 1];

            if (lastChar == '/' || lastChar == '|')
            {
                throw new RachisApplyException($"Document id {command.Id} cannot end with '|' or '/' as part of cluster transaction");
            }
        }