Esempio n. 1
0
        public IAddedIndex AddIndex(string indexName)
        {
            var command = new AddIndexCommand(_command, indexName);

            _command.Add(command);
            return(new AddedIndex(command));
        }
Esempio n. 2
0
        public string[] CreateStatements(AddIndexCommand command)
        {
            var session = _transactionManager.GetSession();

            using (var sqlCommand = session.Connection.CreateCommand()) {
                var columnNames = String.Join(", ", command.ColumnNames.Select(c => string.Format("'{0}'", c)));
                var tableName   = PrefixTableName(command.TableName);
                // check whether the index contains big nvarchar columns or text fields
                string sql = @"SELECT  COLUMN_NAME  FROM INFORMATION_SCHEMA.COLUMNS 
                               WHERE table_name = '{1}' AND COLUMN_NAME in  ({0}) AND TABLE_SCHEMA = '{2}' AND
                                     ((Data_type = 'varchar' and CHARACTER_MAXIMUM_LENGTH > 767) OR data_type= 'text');";

                sql = string.Format(sql, columnNames, tableName, session.Connection.Database);
                sqlCommand.CommandText = sql;

                var columnList = command.ColumnNames.ToList();
                using (var reader = sqlCommand.ExecuteReader()) {
                    // Provide prefix for string columns with length longer than 767
                    while (reader.Read())
                    {
                        var columnName = reader.GetString(0);
                        columnList[columnList.IndexOf(columnName)] = string.Format("{0}(767)", columnName);
                    }
                }

                return(new[] { string.Format("create index {1} on {0} ({2}) ",
                                             _dialectLazy.Value.QuoteForTableName(tableName),
                                             _dialectLazy.Value.QuoteForTableName(PrefixTableName(command.IndexName)),
                                             String.Join(", ", columnList)) });
            }
        }
Esempio n. 3
0
 public virtual void Run(StringBuilder builder, AddIndexCommand command)
 {
     builder.AppendFormat("create index {1} on {0} ({2}) ",
                          _dialect.QuoteForTableName(command.TableName),
                          _dialect.QuoteForColumnName(command.IndexName),
                          String.Join(", ", command.ColumnNames.Select(x => _dialect.QuoteForColumnName(x)).ToArray()));
 }
 public string[] CreateStatements(AddIndexCommand command)
 {
     return(new [] {
         string.Format(" create index {1} on {0}({2}) ",
                       _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
                       _dialect.QuoteForColumnName(command.IndexName),
                       String.Join(", ", command.ColumnNames)
                       )
     });
 }
Esempio n. 5
0
        private CreateIndexNode CreateIndexNodeFromAddColumnCommand(AddIndexCommand command, string fullTableName)
        {
            var ret = new CreateIndexNode
            {
                TableName          = fullTableName,
                IndexName          = command.IndexName,
                IndexedColumnNodes = command.ColumnNames.Select(i => new IndexedColumnNode {
                    Id = i
                })
            };

            return(ret);
        }
        public void Visit(StringBuilder builder, AddIndexCommand command)
        {
            if (ExecuteCustomInterpreter(command))
            {
                return;
            }

            builder.AppendFormat("create index {1} on {0} ({2}) ",
                                 _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
                                 _dialect.QuoteForColumnName(PrefixTableName(command.IndexName)),
                                 String.Join(", ", command.ColumnNames));

            _sqlStatements.Add(builder.ToString());
        }
Esempio n. 7
0
        private void ParseCommand(string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                return;
            }
            //NOTE: Parse in ascending length order!
            if (line.Substring(0, 1).Equals("#"))
            {
                return;
            }
            if (line.Length < 4)
            {
                Warn("invalid command: {0}", line);
                return;
            }

            if (line.Substring(0, 4).ToLower().Equals("quit") || line.Substring(0, 4).ToLower().Equals("exit"))
            {
                return;
            }

            var    idx = line.IndexOf(' ');
            string cmd;

            if (idx < 0)
            {
                idx = 0;
                cmd = line;
            }
            else
            {
                cmd = line.Substring(0, idx).ToLower();
            }

            var args = idx == 0 ? string.Empty : line.Substring(idx + 1).Trim();

            if (CR.abort.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new AbortCommand();
                c.Execute(context);
                StopTimer(CR.abort + " " + args);
                return;
            }
            if (CR.addalias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new AddAliasCommand();
                c.Execute(context, args);
                StopTimer(CR.addalias + " " + args);
                return;
            }
            if (CR.addindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new AddIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.addindex + " " + args);
                return;
            }
            if (CR.close.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CloseCommand();
                c.Execute(context, args);
                StopTimer(CR.close + " " + args);
                return;
            }
            if (CR.commit.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CommitCommand();
                c.Execute(context, args);
                StopTimer(CR.commit + " " + args);
                return;
            }
            if (CR.compactcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CompactContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.compactcontainer + " " + args);
                return;
            }
            if (CR.contextquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new ContextQueryCommand();
                c.Execute(context, args);
                StopTimer(CR.contextquery + " " + args);
                return;
            }
            if (CR.cquery.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CQueryCommand();
                c.Execute(context, args);
                StopTimer(CR.cquery + " " + args);
                return;
            }
            if (CR.createcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new CreateContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.createcontainer + " " + args);
                return;
            }
            if (CR.delindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new DeleteIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.delindex + " " + args);
                return;
            }
            if (CR.echo.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                Msg(args);
                return;
            }
            if (CR.getdocuments.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new GetDocumentsCommand();
                c.Execute(context, args);
                StopTimer(CR.getdocuments + " " + args);
                return;
            }
            if (CR.getmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new GetMetadataCommand();
                c.Execute(context, args);
                StopTimer(CR.getmetadata + " " + args);
                return;
            }
            if (CR.help.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                var c = new HelpCommand();
                c.Execute(args);
                return;
            }
            if (CR.info.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new InfoCommand();
                c.Execute(context, args);
                StopTimer(CR.info + " " + args);
                return;
            }
            if (CR.listindexes.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new ListIndexesCommand();
                c.Execute(context, args);
                StopTimer(CR.listindexes + " " + args);
                return;
            }
            if (CR.lookupedgeindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new LookupEdgeIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.lookupedgeindex + " " + args);
                return;
            }
            if (CR.lookupindex.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new LookupIndexCommand();
                c.Execute(context, args);
                StopTimer(CR.lookupindex + " " + args);
                return;
            }
            if (CR.lookupstats.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new LookupStatisticsCommand();
                c.Execute(context, args);
                StopTimer(CR.lookupstats + " " + args);
                return;
            }
            if (CR.opencontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new OpenContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.opencontainer + " " + args);
                return;
            }
            if (CR.preload.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new PreloadCommand();
                c.Execute(context, args);
                StopTimer(CR.preload + " " + args);
                return;
            }
            if (CR.prepare.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new PrepareCommand();
                c.Execute(context, args);
                StopTimer(CR.prepare + " " + args);
                return;
            }
            if (CR.print.IndexOf(cmd, 0, StringComparison.Ordinal) == 0 || cmd.ToLower().Equals("printnames"))
            {
                StartTimer();
                var c = new PrintCommand();
                c.Execute(context, cmd.Equals("printnames") ? "printnames " + args : args);
                StopTimer(cmd.Equals("printnames") ? "printNames" : CR.print);
                return;
            }
            if (CR.putdocuments.Equals(cmd))
            {
                StartTimer();
                var c = new PutDocumentsCommand();
                c.Execute(context, args);
                StopTimer(CR.putdocuments + " " + args);
                return;
            }
            if (CR.putdocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new PutDocumentCommand();
                c.Execute(context, args);
                StopTimer(CR.putdocument + " " + args);
                return;
            }
            if (CR.query.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new QueryCommand();
                c.Execute(context, args);
                StopTimer(CR.query + " " + args);
                return;
            }
            if (CR.queryplan.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new QueryPlanCommand();
                c.Execute(context, args);
                StopTimer(CR.queryplan + " " + args);
                return;
            }
            if (CR.reindexcontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new ReindexContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.reindexcontainer + " " + args);
                return;
            }
            if (CR.removealias.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new RemoveAliasCommand();
                c.Execute(context, args);
                StopTimer(CR.removealias + " " + args);
                return;
            }
            if (CR.removecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new RemoveContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.removecontainer + " " + args);
                return;
            }
            if (CR.removedocument.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new RemoveDocumentCommand();
                c.Execute(context, args);
                StopTimer(CR.removedocument + " " + args);
                return;
            }
            if (CR.run.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                var c = new RunCommand();
                c.Execute(context, args);
                var l2 = new List <string>(originalArgs)
                {
                    "-s", c.Script
                };
                StartTimer();
                Main(l2.ToArray());
                StopTimer(CR.run + " " + args);
                return;
            }
            if (CR.setautoindexing.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetAutoIndexingCommand();
                c.Execute(context, args);
                StopTimer(CR.setautoindexing + " " + args);
                return;
            }
            if (CR.setbaseuri.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetBaseUriCommand();
                c.Execute(context, args);
                StopTimer(CR.setbaseuri + " " + args);
                return;
            }
            if (CR.setignore.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                var c = new SetIgnoreCommand();
                c.Execute(context, args);
                ignoreErrors = c.Ignore;
                return;
            }
            if (CR.setlazy.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetLazyCommand();
                c.Execute(context, args);
                StopTimer(CR.setlazy + " " + args);
                return;
            }
            if (CR.setmetadata.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetMetadataCommand();
                c.Execute(context, args);
                StopTimer(CR.setmetadata + " " + args);
                return;
            }
            if (CR.setnamespace.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetNamespaceCommand();
                c.Execute(context, args);
                StopTimer(CR.setnamespace + " " + args);
                return;
            }
            if (CR.setprojection.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetProjectionCommand();
                c.Execute(context, args);
                StopTimer(CR.setprojection + " " + args);
                return;
            }
            if (CR.setquerytimeout.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetQueryTimeoutCommand();
                c.Execute(context, args);
                StopTimer(CR.setquerytimeout + " " + args);
                return;
            }
            if (CR.setvariable.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetVariableCommand();
                c.Execute(context, args);
                StopTimer(CR.setvariable + " " + args);
                return;
            }
            if (CR.setverbose.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new SetVerboseCommand();
                c.Execute(context, args);
                StopTimer(CR.setverbose + " " + args);
                return;
            }
            if (CR.sync.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                context.Sync();
                StopTimer(CR.sync + " " + args);
                return;
            }
            if (CR.time.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                time = true;
                ParseCommand(args);
                return;
            }
            if (CR.transaction.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new TransactionCommand();
                c.Execute(context, args);
                StopTimer(CR.transaction + " " + args);
                return;
            }
            if (CR.upgradecontainer.IndexOf(cmd, 0, StringComparison.Ordinal) == 0)
            {
                StartTimer();
                var c = new UpgradeContainerCommand();
                c.Execute(context, args);
                StopTimer(CR.upgradecontainer + " " + args);
                return;
            }

            Warn("Command not recognized: {0}", cmd);
        }
 public string[] CreateStatements(AddIndexCommand command)
 {
     return(new string[0]);
 }
Esempio n. 9
0
 private void SetCommands()
 {
     AddIndex = new AddIndexCommand(new AddIndexGPW());
 }
Esempio n. 10
0
 public AddedIndex(AddIndexCommand command)
 {
     _command = command;
 }