Пример #1
0
        private static void AddColumnAliasNodesToReplace(ICollection <TextSegment> segmentsToReplace, OracleQueryBlock queryBlock, StatementGrammarNode currentNode)
        {
            var column = queryBlock.Columns.SingleOrDefault(c => c.HasExplicitDefinition && c.IsDirectReference && c.RootNode.Terminals.Any(t => t == currentNode));

            if (column == null)
            {
                return;
            }

            foreach (var terminal in FindUsagesCommand.GetParentQueryBlockColumnUsages(column))
            {
                segmentsToReplace.Add
                    (new TextSegment
                {
                    IndextStart = terminal.SourcePosition.IndexStart,
                    Length      = terminal.SourcePosition.Length,
                    Text        = currentNode.PrecedingTerminal.Token.Value
                });
            }

            segmentsToReplace.Add(
                new TextSegment
            {
                IndextStart = currentNode.SourcePosition.IndexStart,
                Length      = currentNode.SourcePosition.Length,
                Text        = String.Empty
            });
        }
Пример #2
0
		private static void ExecutionHandlerImplementation(ActionExecutionContext executionContext)
		{
			var commandInstance = new FindUsagesCommand(executionContext);
			if (commandInstance.CanExecute())
			{
				commandInstance.ExecuteFindUsages();
			}
		}
Пример #3
0
        private static void ExecutionHandlerImplementation(ActionExecutionContext executionContext)
        {
            var commandInstance = new FindUsagesCommand(executionContext);

            if (commandInstance.CanExecute())
            {
                commandInstance.ExecuteFindUsages();
            }
        }
        public static ICollection <CommandExecutionHandler> ResolveCommandHandlers(OracleStatementSemanticModel semanticModel, StatementGrammarNode currentTerminal)
        {
            CheckParametersNotNull(semanticModel, currentTerminal);

            var commands = new List <CommandExecutionHandler>();

            if (!CanConvertCurrentTerminal(currentTerminal))
            {
                return(EmptyHandlerCollection);
            }

            var requiredPrecedingTerminalId = GetRequiredPrecedingTerminalId(currentTerminal);
            var literalTerminals            = FindUsagesCommand.GetEqualValueLiteralTerminals(semanticModel.Statement, currentTerminal)
                                              .Where(t => requiredPrecedingTerminalId == t.PrecedingTerminal.Id || (requiredPrecedingTerminalId == null && !t.PrecedingTerminal.Id.In(Terminals.Date, Terminals.Timestamp)))
                                              .ToArray();

            var singleOccurenceConvertAction =
                new CommandExecutionHandler
            {
                Name             = "Convert to bind variable",
                ExecutionHandler =
                    c => new LiteralBindVariableConversionCommand(c, new[] { currentTerminal }, requiredPrecedingTerminalId).Execute(),
                CanExecuteHandler = c => true
            };

            commands.Add(singleOccurenceConvertAction);

            if (literalTerminals.Length > 1)
            {
                var allOccurencesConvertAction =
                    new CommandExecutionHandler
                {
                    Name             = "Convert all occurences to bind variable",
                    ExecutionHandler =
                        c => new LiteralBindVariableConversionCommand(c, literalTerminals, requiredPrecedingTerminalId).Execute(),
                    CanExecuteHandler = c => true
                };

                commands.Add(allOccurencesConvertAction);
            }

            return(commands.AsReadOnly());
        }
        public static ICollection <CommandExecutionHandler> ResolveCommandHandlers(OracleStatementSemanticModel semanticModel, StatementGrammarNode currentTerminal)
        {
            CheckParametersNotNull(semanticModel, currentTerminal);

            if (!String.Equals(currentTerminal.Id, Terminals.BindVariableIdentifier))
            {
                return(EmptyHandlerCollection);
            }

            var bindVariable = FindUsagesCommand.GetBindVariable(semanticModel, currentTerminal.Token.Value);

            var singleOccurenceConvertAction =
                new CommandExecutionHandler
            {
                Name             = "Convert to literal",
                ExecutionHandler = c => new BindVariableLiteralConversionCommand(c, bindVariable, false)
                                   .Execute(),
                CanExecuteHandler = c => true
            };

            var commands = new List <CommandExecutionHandler> {
                singleOccurenceConvertAction
            };

            if (bindVariable.Nodes.Count > 1)
            {
                var allOccurencesConvertAction =
                    new CommandExecutionHandler
                {
                    Name             = "Convert all accurences to literal",
                    ExecutionHandler = c => new BindVariableLiteralConversionCommand(c, bindVariable, true)
                                       .Execute(),
                    CanExecuteHandler = c => true
                };

                commands.Add(allOccurencesConvertAction);
            }

            return(commands.AsReadOnly());
        }
Пример #6
0
        protected override void Execute()
        {
            var commandHelper = new AliasCommandHelper(ExecutionContext);

            foreach (var column in _unquotableColumns)
            {
                var unquotedColumnAlias = column.NormalizedName.Trim('"');
                if (column.HasExplicitAlias || String.Equals(column.NormalizedName.ToSimpleIdentifier(), unquotedColumnAlias))
                {
                    foreach (var terminal in FindUsagesCommand.GetParentQueryBlockColumnUsages(column))
                    {
                        ExecutionContext.SegmentsToReplace.Add(
                            new TextSegment
                        {
                            IndextStart = terminal.SourcePosition.IndexStart,
                            Length      = terminal.SourcePosition.Length,
                            Text        = unquotedColumnAlias
                        });
                    }

                    ExecutionContext.SegmentsToReplace.Add(
                        new TextSegment
                    {
                        IndextStart = column.AliasNode.SourcePosition.IndexStart,
                        Length      = column.AliasNode.SourcePosition.Length,
                        Text        = unquotedColumnAlias
                    });
                }
                else
                {
                    commandHelper.AddColumnAlias(column.RootNode, column.Owner, column.NormalizedName, unquotedColumnAlias);
                }
            }

            foreach (var unquotableObject in _unquotableObjects)
            {
                if (unquotableObject.AliasNode != null)
                {
                    var unquotedObjectAlias = unquotableObject.AliasNode.Token.Value.Trim('"');
                    ExecutionContext.SegmentsToReplace.Add(
                        new TextSegment
                    {
                        IndextStart = unquotableObject.AliasNode.SourcePosition.IndexStart,
                        Length      = unquotableObject.AliasNode.SourcePosition.Length,
                        Text        = unquotedObjectAlias
                    });

                    var columnReferences = unquotableObject.Owner == null
                                                ? unquotableObject.Container.ColumnReferences
                                                : unquotableObject.Owner.AllColumnReferences;

                    var referenceColumnObjectNodes = columnReferences
                                                     .Where(r => r.ObjectNode != null && r.ValidObjectReference == unquotableObject)
                                                     .Select(r => r.ObjectNode);

                    foreach (var objectNode in referenceColumnObjectNodes)
                    {
                        ExecutionContext.SegmentsToReplace.Add(
                            new TextSegment
                        {
                            IndextStart = objectNode.SourcePosition.IndexStart,
                            Length      = objectNode.SourcePosition.Length,
                            Text        = unquotedObjectAlias
                        });
                    }
                }
                else
                {
                    commandHelper.AddObjectAlias(unquotableObject, unquotableObject.ObjectNode.Token.Value.Trim('"'));
                }
            }
        }