public ISchemaBuilder CreateMapIndexTable(Type indexType, Action <ICreateTableCommand> table, string collection) { try { var indexName = indexType.Name; var indexTable = TableNameConvention.GetIndexTable(indexType, collection); var createTable = new CreateTableCommand(Prefix(indexTable)); var documentTable = TableNameConvention.GetDocumentTable(collection); // NB: Identity() implies PrimaryKey() createTable .Column <int>("Id", column => column.Identity().NotNull()) .Column <int>("DocumentId") ; table(createTable); Execute(_commandInterpreter.CreateSql(createTable)); CreateForeignKey("FK_" + (collection ?? "") + indexName, indexTable, new[] { "DocumentId" }, documentTable, new[] { "Id" }); AlterTable(indexTable, table => table.CreateIndex($"IDX_FK_{indexTable}", "DocumentId") ); } catch { if (ThrowOnError) { throw; } } return(this); }
private int CreateTable(RemoteTcpServer serverEntity) { var cmd = new CreateTableCommand() { Params = new TableParams() { //Blind = BlindTypeEnum.Blinds, Options = new GameTypeOptionsStandard(), //GameSize = 10, //Limit = LimitTypeEnum.NoLimit, Lobby = new LobbyOptionsQuickMode() { //StartingAmount = 1500 }, MaxPlayers = 10, MinPlayersToStart = 2, TableName = "Table One", Variant = GameSubTypeEnum.Standard, WaitingTimes = new ConfigurableWaitingTimes() { //AfterBoardDealed = 0, AfterPlayerAction = 0, //AfterPotWon = 0 } } }; serverEntity.Send(cmd); var response = serverEntity.WaitForNextCommand <CreateTableResponse>(); Assert.AreNotEqual(response.IdTable, -1); return(response.IdTable); }
public ISchemaBuilder CreateMapIndexTable(string name, Action <ICreateTableCommand> table) { try { var createTable = new CreateTableCommand(Prefix(name)); var collection = CollectionHelper.Current; var documentTable = collection.GetPrefixedName(Store.DocumentTable); createTable .Column <int>("Id", column => column.PrimaryKey().Identity().NotNull()) .Column <int>("DocumentId"); table(createTable); Execute(_builder.CreateSql(createTable)); CreateForeignKey("FK_" + name, name, new[] { "DocumentId" }, documentTable, new[] { "Id" }); } catch { if (ThrowOnError) { throw; } } return(this); }
public override void VisitCreateTable(CreateTableCommand cmd) { this.Append("CREATE TABLE " + cmd.Name + "("); this.AppendNewLine(); TableColumnCommand pk = null; List<TableColumnCommand> uks = new List<TableColumnCommand>(); foreach (var item in cmd.ColumnCommands) { TableColumnCommand ccc = item as TableColumnCommand; if (ccc.IsPrimaryKey.HasValue && ccc.IsPrimaryKey.Value) pk = ccc; if (ccc.IsUnique.HasValue && ccc.IsUnique.Value) uks.Add(ccc); this.VisitTableColumn(ccc); this.Append(","); this.AppendNewLine(); } if (pk != null) { this.AppendFormat("PRIMARY KEY ({0}),", pk.Name); this.AppendNewLine(); } foreach (var item in uks) { this.AppendFormat("UNIQUE INDEX {0} ({0}),", pk.Name); this.AppendNewLine(); } this.RemoveLastChar(); this.Append(")"); this.ExecuteCommandText(cmd.ConnectionString, builder.ToString()); }
public ICreatedTable CreateTable(string tableName, string primaryKeyConstraintName) { var createTableCommand = new CreateTableCommand(_root, tableName, primaryKeyConstraintName); _root.Add(createTableCommand); return(new CreatedTable(createTableCommand)); }
public SchemaBuilder CreateTable(string name, Action<CreateTableCommand> table) { var createTable = new CreateTableCommand(String.Concat(_formatPrefix(_featurePrefix), name)); table(createTable); Run(createTable); return this; }
public SchemaBuilder CreateReduceIndexTable(string name, Action <CreateTableCommand> table) { try { var createTable = new CreateTableCommand(Prefix(name)); var collection = CollectionHelper.Current; var documentTable = collection.GetPrefixedName(Store.DocumentTable); createTable .Column <int>("Id", column => column.Identity().NotNull()) ; table(createTable); Execute(_builder.CreateSql(createTable)); var bridgeTableName = name + "_" + documentTable; CreateTable(bridgeTableName, bridge => bridge .Column <int>(name + "Id", column => column.NotNull()) .Column <int>("DocumentId", column => column.NotNull()) ); CreateForeignKey("FK_" + bridgeTableName + "_Id", bridgeTableName, new[] { name + "Id" }, name, new[] { "Id" }); CreateForeignKey("FK_" + bridgeTableName + "_DocumentId", bridgeTableName, new[] { "DocumentId" }, documentTable, new[] { "Id" }); } catch { if (ThrowOnError) { throw; } } return(this); }
public CreateTableContext( IDynamicAssemblyBuilder dynamicAssemblyBuilder, CreateTableCommand tableCommand) { _dynamicAssemblyBuilder = dynamicAssemblyBuilder; _tableCommand = tableCommand; }
public SchemaBuilder CreateTable(string name, Action <CreateTableCommand> table) { var createTable = new CreateTableCommand(String.Concat(_formatPrefix(_featurePrefix), name)); table(createTable); Run(createTable); return(this); }
public SchemaBuilder CreateTable(string name, Action <CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); table(createTable); Execute(_builder.CreateSql(createTable)); return(this); }
public static CreateTableCommand SocialPluginWithHeightPartRecord(this CreateTableCommand table) { table .SocialPluginPartRecord() .Column <int>("Height"); return(table); }
public static CreateTableCommand SocialPluginPartRecord(this CreateTableCommand table) { table .ContentPartRecord() .Column <int>("Width") .Column <string>("ColorScheme"); return(table); }
/// <summary> /// Create table into current database /// </summary> /// <param name="query">SQL-query</param> /// <returns></returns> public string CreateTable(string query) { var cmd = new CreateTableCommand(query); var table = new Table(_path, cmd.DatabaseName ?? Name, cmd.TableName); var start = _stopwatch.Elapsed; table.Create(cmd); var executeTime = _stopwatch.Elapsed - start; return($"Table [{cmd.TableName}] was created. Execution time: {executeTime}"); }
public override void Visit(CreateTableCommand command) { if (ExecuteCustomInterpreter(command)) { return; } var builder = new StringBuilder(); builder.Append(_dialectLazy.Value.CreateMultisetTableString) .Append(' ') .Append(_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.Name))) .Append(_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.Name))) .Append(" ("); var appendComma = false; foreach (var createColumn in command.TableCommands.OfType <CreateColumnCommand>()) { if (appendComma) { builder.Append(", "); } appendComma = true; Visit(builder, createColumn); } var primaryKeys = command.TableCommands.OfType <CreateColumnCommand>().Where(ccc => ccc.IsPrimaryKey).Select(ccc => ccc.ColumnName).ToArray(); if (primaryKeys.Any()) { if (appendComma) { builder.Append(", "); } var primaryKeysQuoted = new List <string>(primaryKeys.Length); foreach (string pk in primaryKeys) { primaryKeysQuoted.Add(_dialectLazy.Value.QuoteForColumnName(pk)); } builder.Append(_dialectLazy.Value.PrimaryKeyString) .Append(" ( ") .Append(String.Join(", ", primaryKeysQuoted.ToArray())) .Append(" )"); } builder.Append(" )"); _sqlStatements.Add(builder.ToString()); RunPendingStatements(); }
public static CreateTableCommand Column <TModel, TProperty>( this CreateTableCommand command, Expression <Func <TModel, TProperty> > propertySelector, Action <CreateColumnCommand> column = null, bool isPrefixWithModelType = false) { var columnName = GetColumnName(propertySelector, isPrefixWithModelType); var propertyType = GetPropertyType <TProperty>(); var dbType = SchemaUtils.ToDbType(propertyType); return(command.Column(columnName, dbType, column)); }
public void ParseAndExecuteCreateTableCommand() { CreateTableCommand cmd = (CreateTableCommand)GetCommand("create table Customers(Name, Address)"); cmd.Execute(this.database); Table table = this.database.GetTable("Customers"); Assert.IsNotNull(table); Assert.AreEqual(2, table.ColumnCount); Assert.IsNotNull(table.GetColumn("Name")); Assert.IsNotNull(table.GetColumn("Address")); }
public SchemaBuilder CreateMapIndexTable(string name, Action <CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); createTable .Column <int>("Id", column => column.PrimaryKey().Identity().NotNull()) .Column <int>("DocumentId"); table(createTable); Execute(_builder.CreateSql(createTable)); CreateForeignKey("FK_" + name, name, new[] { "DocumentId" }, "Document", new[] { "Id" }); return(this); }
public async Task DeleteReservation_NewReservation_SuccessfullyMissing() { IServiceCollection services = new ServiceCollection(); services.AddHostingDomain() .AddHostingApplication() .AddHostingInfrastructure("Server=.;Database=RestaurantManagementSystem;Trusted_Connection=True;MultipleActiveResultSets=true", "S0M3 M4G1C UN1C0RNS G3N3R4T3D TH1S S3CR3T"); var serviceProviderFactory = new DefaultServiceProviderFactory(); IServiceProvider serviceProvider = serviceProviderFactory.CreateServiceProvider(services); IMediator Mediator = serviceProvider.GetService <IMediator>(); var createTableCommand = new CreateTableCommand(); createTableCommand.Indoor = true; createTableCommand.Location = "Do Prozoreca"; createTableCommand.Name = "Bestest Table EVER"; createTableCommand.NumberOfSeats = 6; createTableCommand.SmokingAllowed = true; createTableCommand.RestaurantName = "Best Restaurant EVER"; var createTableOutputModel = await Mediator.Send(createTableCommand); var tommorow = DateTime.UtcNow.AddDays(1); var addReservationCommand = new AddReservationCommand(); addReservationCommand.TableId = createTableOutputModel.TableId; addReservationCommand.Start = new DateTime(tommorow.Year, tommorow.Month, tommorow.Day, 13, 30, 0); addReservationCommand.Guest = new Guest("Goshko", "Loshkov", "0900tainamaina"); var addReservationOutput = await Mediator.Send(addReservationCommand); var deleteReservationCommand = new DeleteReservationCommand(); deleteReservationCommand.ReservationId = addReservationOutput.ReservationId; await Mediator.Send(deleteReservationCommand); var getTablesQuery = new GetTablesQuery(); var getTablesOutput = await Mediator.Send(getTablesQuery); var dbTable = getTablesOutput.Tables.FirstOrDefault(table => table.Id == createTableOutputModel.TableId); var targetSchedule = dbTable.GetScheduleForDateTime(addReservationCommand.Start); await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => { var targetRes = targetSchedule.Reservations.First(res => res.Id == addReservationOutput.ReservationId); return(Task.CompletedTask); }); }
public int CreateTable(CreateTableCommand c) { ListTables(); m_LastUsedId++; while (m_Games.ContainsKey(m_LastUsedId)) m_LastUsedId++; var game = new PokerGame(new PokerTable(c.Params)); m_Games.Add(m_LastUsedId, game); game.Start(); return m_LastUsedId; }
protected void CreateTable() { lock (this._globalLock) { using (this.Connection.OpenWrapper()) { CreateTableCommand command = new CreateTableCommand( this.Connection, this.TableDefinition ); command.Execute(100); } } }
public void ExecuteCreateTableCommand() { CreateTableCommand cmd = new CreateTableCommand("Customers"); cmd.AddColumn(new Column("Name")); cmd.AddColumn(new Column("Address")); cmd.Execute(this.database); Table table = this.database.GetTable("Customers"); Assert.IsNotNull(table); Assert.AreEqual(2, table.ColumnCount); Assert.IsNotNull(table.GetColumn("Name")); Assert.IsNotNull(table.GetColumn("Address")); }
public void CompileCreateTable() { ICommand cmd = Compile("create table Customers(name,address)"); Assert.IsNotNull(cmd); Assert.IsInstanceOfType(cmd, typeof(CreateTableCommand)); CreateTableCommand create = (CreateTableCommand)cmd; Assert.AreEqual("Customers", create.Name); ICollection <Column> columns = create.Columns; Assert.IsNotNull(columns); Assert.AreEqual(2, columns.Count); Assert.AreEqual("name", columns.ElementAt(0).Name); Assert.AreEqual("address", columns.ElementAt(1).Name); }
public SchemaBuilder CreateTable(string name, Action <CreateTableCommand> table) { try { var createTable = new CreateTableCommand(Prefix(name)); table(createTable); Execute(_builder.CreateSql(createTable)); } catch { if (ThrowOnError) { throw; } } return(this); }
public virtual IEnumerable <string> Run(CreateTableCommand command) { // TODO: Support CreateForeignKeyCommand in a CREATE TABLE (in sqlite they can only be created with the table) var builder = new StringBuilder(); builder.Append(_dialect.CreateTableString) .Append(' ') .Append(_dialect.QuoteForTableName(command.Name)) .Append(" ("); var appendComma = false; foreach (var createColumn in command.TableCommands.OfType <CreateColumnCommand>()) { if (appendComma) { builder.Append(", "); } appendComma = true; Run(builder, createColumn); } var primaryKeys = command.TableCommands.OfType <CreateColumnCommand>().Where(ccc => ccc.IsPrimaryKey && !ccc.IsIdentity).Select(ccc => _dialect.QuoteForColumnName(ccc.ColumnName)).ToArray(); if (primaryKeys.Any()) { if (appendComma) { builder.Append(", "); } builder.Append(_dialect.PrimaryKeyString) .Append(" ( ") .Append(String.Join(", ", primaryKeys.ToArray())) .Append(" )"); } builder.Append(" )"); yield return(builder.ToString()); }
public async Task AddOverlappingReservation_NewReservation_ThrowsError() { IServiceCollection services = new ServiceCollection(); services.AddHostingDomain() .AddHostingApplication() .AddHostingInfrastructure("Server=.;Database=RestaurantManagementSystem;Trusted_Connection=True;MultipleActiveResultSets=true", "S0M3 M4G1C UN1C0RNS G3N3R4T3D TH1S S3CR3T"); var serviceProviderFactory = new DefaultServiceProviderFactory(); IServiceProvider serviceProvider = serviceProviderFactory.CreateServiceProvider(services); IMediator Mediator = serviceProvider.GetService <IMediator>(); var createTableCommand = new CreateTableCommand(); createTableCommand.Indoor = true; createTableCommand.Location = "Do Prozoreca"; createTableCommand.Name = "Bestest Table EVER"; createTableCommand.NumberOfSeats = 6; createTableCommand.SmokingAllowed = true; createTableCommand.RestaurantName = "Best Restaurant EVER"; var createTableOutputModel = await Mediator.Send(createTableCommand); var tommorow = DateTime.UtcNow.AddDays(1); var addReservationCommand = new AddReservationCommand(); addReservationCommand.TableId = createTableOutputModel.TableId; addReservationCommand.Start = new DateTime(tommorow.Year, tommorow.Month, tommorow.Day, 13, 30, 0); addReservationCommand.Guest = new Guest("Goshko", "Loshkov", "0900tainamaina"); var addReservationOutput = await Mediator.Send(addReservationCommand); addReservationCommand = new AddReservationCommand(); addReservationCommand.TableId = createTableOutputModel.TableId; addReservationCommand.Start = new DateTime(tommorow.Year, tommorow.Month, tommorow.Day, 13, 30, 0); addReservationCommand.Guest = new Guest("Goshko", "Loshkov", "0900tainamaina"); await Assert.ThrowsExceptionAsync <ReservationConflictException>(() => { return(Mediator.Send(addReservationCommand)); }); }
public override IASTNode VisitCreateTable(SqlServerCommandParser.CreateTableContext context) { CreateTableCommand result = new CreateTableCommand((SimpleTableSegment)Visit(context.tableName())); if (null != context.createDefinitionClause()) { CollectionValue <ICreateDefinitionSegment> createDefinitions = (CollectionValue <ICreateDefinitionSegment>)Visit(context.createDefinitionClause()); foreach (var createDefinitionSegment in createDefinitions.GetValue()) { if (createDefinitionSegment is ColumnDefinitionSegment columnDefinitionSegment) { result.ColumnDefinitions.Add(columnDefinitionSegment); } else if (createDefinitionSegment is ConstraintDefinitionSegment constraintDefinitionSegment) { result.ConstraintDefinitions.Add(constraintDefinitionSegment); } } } return(result); }
public virtual IEnumerable<string> Run(CreateTableCommand command) { // TODO: Support CreateForeignKeyCommand in a CREATE TABLE (in sqlite they can only be created with the table) var builder = new StringBuilder(); builder.Append(_dialect.CreateTableString) .Append(' ') .Append(_dialect.QuoteForTableName(command.Name)) .Append(" ("); var appendComma = false; foreach (var createColumn in command.TableCommands.OfType<CreateColumnCommand>()) { if (appendComma) { builder.Append(", "); } appendComma = true; Run(builder, createColumn); } var primaryKeys = command.TableCommands.OfType<CreateColumnCommand>().Where(ccc => ccc.IsPrimaryKey && !ccc.IsIdentity).Select(ccc => ccc.ColumnName).ToArray(); if (primaryKeys.Any()) { if (appendComma) { builder.Append(", "); } builder.Append(_dialect.PrimaryKeyString) .Append(" ( ") .Append(String.Join(", ", primaryKeys.ToArray())) .Append(" )"); } builder.Append(" )"); yield return builder.ToString(); }
public SchemaBuilder CreateReduceIndexTable(string name, Action <CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); createTable .Column <int>("Id", column => column.Identity().NotNull()) ; table(createTable); Execute(_builder.CreateSql(createTable)); var bridgeTableName = name + "_Document"; CreateTable(bridgeTableName, bridge => bridge .Column <int>(name + "Id", column => column.NotNull()) .Column <int>("DocumentId", column => column.NotNull()) ); CreateForeignKey("FK_" + bridgeTableName + "_Id", bridgeTableName, new[] { name + "Id" }, name, new[] { "Id" }); CreateForeignKey("FK_" + bridgeTableName + "DocumentId", bridgeTableName, new[] { "DocumentId" }, "Document", new[] { "Id" }); return(this); }
public int CreateTable(CreateTableCommand c) { ListTables(); m_LastUsedId++; while (m_Games.ContainsKey(m_LastUsedId)) { m_LastUsedId++; } var game = new PokerGame(new PokerTable(c.Params)); m_Games.Add(m_LastUsedId, game); var p = game.Table.Params; Logger.LogTableCreated(m_LastUsedId, p); Logger.LogGameCreated(m_LastUsedId); game.Start(); return(m_LastUsedId); }
public async Task CreateTable_NewTable_SuccessfulRead() { IServiceCollection services = new ServiceCollection(); services.AddHostingDomain() .AddHostingApplication() .AddHostingInfrastructure("Server=.;Database=RestaurantManagementSystem;Trusted_Connection=True;MultipleActiveResultSets=true", "S0M3 M4G1C UN1C0RNS G3N3R4T3D TH1S S3CR3T"); var serviceProviderFactory = new DefaultServiceProviderFactory(); IServiceProvider serviceProvider = serviceProviderFactory.CreateServiceProvider(services); IMediator Mediator = serviceProvider.GetService <IMediator>(); var createTableCommand = new CreateTableCommand(); createTableCommand.Indoor = true; createTableCommand.Location = "Do Prozoreca"; createTableCommand.Name = "Best Table EVER"; createTableCommand.NumberOfSeats = 4; createTableCommand.SmokingAllowed = true; createTableCommand.RestaurantName = "Best Restaurant EVER"; var createTableOutputModel = await Mediator.Send(createTableCommand); var getTablesQuery = new GetTablesQuery(); var tommorow = DateTime.UtcNow.AddDays(1); getTablesQuery.FreeTablesTargetTime = new DateTime(tommorow.Year, tommorow.Month, tommorow.Day, 13, 0, 0); var getTablesOutput = await Mediator.Send(getTablesQuery); var dbTable = getTablesOutput.Tables.FirstOrDefault(table => table.Id == createTableOutputModel.TableId); Assert.AreEqual(dbTable.NumberOfSeats, createTableCommand.NumberOfSeats); Assert.AreEqual(dbTable.Name, createTableCommand.Name); Assert.AreEqual(dbTable.Description.IsIndoor, createTableCommand.Indoor); Assert.AreEqual(dbTable.Description.Location, createTableCommand.Location); Assert.AreEqual(dbTable.Description.AreSmokersAllowed, createTableCommand.SmokingAllowed); }
public ISchemaBuilder CreateReduceIndexTable(Type indexType, Action <ICreateTableCommand> table, string collection = null) { try { var indexName = indexType.Name; var indexTable = TableNameConvention.GetIndexTable(indexType, collection); var createTable = new CreateTableCommand(Prefix(indexTable)); var documentTable = TableNameConvention.GetDocumentTable(collection); createTable .Column <int>("Id", column => column.Identity().NotNull()) ; table(createTable); Execute(_commandInterpreter.CreateSql(createTable)); var bridgeTableName = indexTable + "_" + documentTable; CreateTable(bridgeTableName, bridge => bridge .Column <int>(indexName + "Id", column => column.NotNull()) .Column <int>("DocumentId", column => column.NotNull()) ); CreateForeignKey("FK_" + bridgeTableName + "_Id", bridgeTableName, new[] { indexName + "Id" }, indexTable, new[] { "Id" }); CreateForeignKey("FK_" + bridgeTableName + "_DocumentId", bridgeTableName, new[] { "DocumentId" }, documentTable, new[] { "Id" }); } catch { if (ThrowOnError) { throw; } } return(this); }
private int CreateTable(RemoteTcpServer serverEntity) { var cmd = new CreateTableCommand() { Params = new TableParams() { Blind = new BlindOptionsBlinds() { MoneyUnit = 10 }, GameType = GameTypeEnum.Holdem, MoneyUnit = 10, Limit = new LimitOptionsNoLimit(), Lobby = new LobbyOptionsQuickMode() { StartingAmount = 1500 }, MaxPlayers = 10, MinPlayersToStart = 2, TableName = "Table One", Variant = "Wtf Is this field", WaitingTimes = new ConfigurableWaitingTimes() { AfterBoardDealed = 0, AfterPlayerAction = 0, AfterPotWon = 0 } } }; serverEntity.Send(cmd); var response = serverEntity.WaitForNextCommand<CreateTableResponse>(); Assert.AreNotEqual(response.IdTable,-1); return response.IdTable; }
private int CreateTable(RemoteTcpServer serverEntity) { var cmd = new CreateTableCommand() { Params = new TableParams() { Blind = BlindTypeEnum.Blinds, Options = new GameTypeOptionsCommunity(), GameSize = 10, Limit = LimitTypeEnum.NoLimit, Lobby = new LobbyOptionsQuickMode() { StartingAmount = 1500 }, MaxPlayers = 10, MinPlayersToStart = 2, TableName = "Table One", Variant = GameSubTypeEnum.TexasHoldem, WaitingTimes = new ConfigurableWaitingTimes() { AfterBoardDealed = 0, AfterPlayerAction = 0, AfterPotWon = 0 } } }; serverEntity.Send(cmd); var response = serverEntity.WaitForNextCommand<CreateTableResponse>(); Assert.AreNotEqual(response.IdTable,-1); return response.IdTable; }
public override void Visit(CreateTableCommand command) { _output.WriteLine("Creating table {0}", command.Name); }
public SchemaBuilder CreateTable(string name, Action<CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); table(createTable); Execute(_builder.CreateSql(createTable)); return this; }
public SchemaBuilder CreateMapIndexTable(string name, Action<CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); createTable .Column<int>("Id", column => column.PrimaryKey().Identity().NotNull()) .Column<int>("DocumentId"); table(createTable); Execute(_builder.CreateSql(createTable)); CreateForeignKey("FK_" + name, name, new[] { "DocumentId" }, "Document", new[] { "Id" }); return this; }
public override void Visit(CreateTableCommand command) { _output.WriteLine("\t\t\t// Creating table {0}", command.Name); _output.WriteLine("\t\t\tSchemaBuilder.CreateTable(\"{0}\", table => table", command.Name); var matchContentPartRecord = command.TableCommands.OfType<CreateColumnCommand>().Any( c => c.IsPrimaryKey && c.ColumnName == "Id" && !c.IsIdentity && c.DbType == DbType.Int32); var matchContentPartVersionRecord = matchContentPartRecord && command.TableCommands.OfType<CreateColumnCommand>().Any( c => c.ColumnName == "ContentItemRecord_id" && c.DbType == DbType.Int32); if ( matchContentPartVersionRecord ) { _output.WriteLine("\t\t\t\t.ContentPartVersionRecord()"); } else if ( matchContentPartRecord ) { _output.WriteLine("\t\t\t\t.ContentPartRecord()"); } foreach ( var createColumn in command.TableCommands.OfType<CreateColumnCommand>() ) { if(createColumn.ColumnName == "Id" && matchContentPartRecord) { continue; } if(createColumn.ColumnName == "ContentItemRecord_id" && matchContentPartVersionRecord) { continue; } var type = createColumn.DbType.ToString(); var field = createColumn.ColumnName; var options = new List<string>(); if ( createColumn.IsPrimaryKey ) { options.Add("PrimaryKey()"); } if ( createColumn.IsIdentity ) { options.Add("Identity()"); } if ( createColumn.IsUnique ) { options.Add("Unique()"); } if ( createColumn.IsNotNull ) { options.Add("NotNull()"); } if ( createColumn.Length.HasValue ) { if ( createColumn.Length == 10000 ) { options.Add("Unlimited()"); } else { options.Add(string.Format("WithLength({0})", createColumn.Length)); } } if ( createColumn.Precision > 0 ) { options.Add(string.Format("WithPrecision({0})", createColumn.Precision)); options.Add(string.Format("WithScale({0})", createColumn.Scale)); } _output.WriteLine("\t\t\t\t.Column(\"{0}\", DbType.{1}{2})", field, type, options.Any() ? ", column => column." + string.Join(".", options) : string.Empty); } _output.WriteLine("\t\t\t);"); }
/// <summary> /// Generates SchemaCommand instances in order to create the schema for a specific feature /// </summary> public IEnumerable <SchemaCommand> GetCreateFeatureCommands(string feature, bool drop) { var dependencies = _extensionManager.AvailableFeatures() .Where(f => String.Equals(f.Id, feature, StringComparison.OrdinalIgnoreCase)) .Where(f => f.Dependencies != null) .SelectMany(f => f.Dependencies) .ToList(); var shellDescriptor = new ShellDescriptor { Features = dependencies.Select(id => new ShellFeature { Name = id }).Union(new[] { new ShellFeature { Name = feature }, new ShellFeature { Name = "Orchard.Framework" } }) }; var shellBlueprint = _compositionStrategy.Compose(_shellSettings, shellDescriptor); if (!shellBlueprint.Records.Any()) { yield break; } //var features = dependencies.Select(name => new ShellFeature {Name = name}).Union(new[] {new ShellFeature {Name = feature}, new ShellFeature {Name = "Orchard.Framework"}}); var parameters = _sessionFactoryHolder.GetSessionFactoryParameters(); parameters.RecordDescriptors = shellBlueprint.Records; var configuration = _dataServicesProviderFactory .CreateProvider(parameters) .BuildConfiguration(parameters); Dialect.GetDialect(configuration.Properties); var mapping = configuration.BuildMapping(); // get the table mappings using reflection var tablesField = typeof(Configuration).GetField("tables", BindingFlags.Instance | BindingFlags.NonPublic); var tables = ((IDictionary <string, Table>)tablesField.GetValue(configuration)).Values; string prefix = feature.Replace(".", "_") + "_"; foreach (var table in tables.Where(t => parameters.RecordDescriptors.Any(rd => rd.Feature.Descriptor.Id == feature && rd.TableName == t.Name))) { string tableName = table.Name; var recordType = parameters.RecordDescriptors.First(rd => rd.Feature.Descriptor.Id == feature && rd.TableName == tableName).Type; var isContentPart = typeof(ContentPartRecord).IsAssignableFrom(recordType); if (tableName.StartsWith(prefix)) { tableName = tableName.Substring(prefix.Length); } if (drop) { yield return(new DropTableCommand(tableName)); } var command = new CreateTableCommand(tableName); foreach (var column in table.ColumnIterator) { // create copies for local variables to be evaluated at the time the loop is called, and not lately when the la;bda is executed var tableCopy = table; var columnCopy = column; var sqlType = columnCopy.GetSqlTypeCode(mapping); command.Column(column.Name, sqlType.DbType, action => { if (tableCopy.PrimaryKey.Columns.Any(c => c.Name == columnCopy.Name)) { action.PrimaryKey(); if (!isContentPart) { action.Identity(); } } if (columnCopy.IsLengthDefined() && new[] { DbType.StringFixedLength, DbType.String, DbType.AnsiString, DbType.AnsiStringFixedLength }.Contains(sqlType.DbType) && columnCopy.Length != Column.DefaultLength) { action.WithLength(columnCopy.Length); } if (columnCopy.IsPrecisionDefined()) { action.WithPrecision((byte)columnCopy.Precision); action.WithScale((byte)columnCopy.Scale); } if (columnCopy.IsNullable) { action.Nullable(); } if (columnCopy.IsUnique) { action.Unique(); } if (columnCopy.DefaultValue != null) { action.WithDefault(columnCopy.DefaultValue); } }); } yield return(command); } }
private static void CompareCreateTableCommand(CreateTableCommand c, CreateTableCommand dc) { CompareTableParams.Compare(c.Params, dc.Params); }
public abstract void Visit(CreateTableCommand command);
public override void VisitCreateTable(CreateTableCommand cmd) { this.Append("CREATE TABLE " + cmd.Name + " ("); this.AppendNewLine(); TableColumnCommand pk = null; TableColumnCommand incr = null; List<TableColumnCommand> uks = new List<TableColumnCommand>(); foreach (var item in cmd.ColumnCommands) { TableColumnCommand ccc = item as TableColumnCommand; if (ccc.IsPrimaryKey.HasValue && ccc.IsPrimaryKey.Value) pk = ccc; if (ccc.IsIdentity.HasValue && ccc.IsIdentity.Value) incr = ccc; if (ccc.IsUnique.HasValue && ccc.IsUnique.Value) uks.Add(ccc); this.VisitTableColumn(ccc); this.Append(","); this.AppendNewLine(); } if (pk != null) { this.AppendFormat("PRIMARY KEY ({1}),", cmd.Name, pk.Name); this.AppendNewLine(); } foreach (var item in uks) { this.AppendFormat("UNIQUE INDEX {0} ({0}),", pk.Name); this.AppendNewLine(); } this.RemoveLastChar(); this.Append(")"); try { this.ExecuteCommandText(cmd.ConnectionString, builder.ToString()); } catch { } builder.Clear(); if (incr != null) { this.AppendFormat("DROP SEQUENCE {0}_TB_SEQ", cmd.Name); try { this.ExecuteCommandText(cmd.ConnectionString, builder.ToString()); } catch { } builder.Clear(); this.AppendFormat("CREATE SEQUENCE {0}_TB_SEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE NOCACHE", cmd.Name); try { this.ExecuteCommandText(cmd.ConnectionString, builder.ToString()); } catch { } builder.Clear(); //this.AppendFormat("CREATE OR REPLACE TRIGGER {0}_TB_TRIGGER", cmd.Name); //this.AppendNewLine(); //this.AppendFormat("BEFORE INSERT ON {0} ", cmd.Name); //this.AppendNewLine(); //this.Append("FOR EACH ROW"); //this.AppendNewLine(); //this.Append("BEGIN"); //this.AppendNewLine(); //this.AppendFormat("SELECT {0}_TB_SEQ.NEXTVAL INTO:New.{1} FROM SYS.DUAL;", cmd.Name, incr.Name); //this.AppendNewLine(); //this.Append("END;"); //try //{ // this.ExecuteCommandText(cmd.ConnectionString, builder.ToString()); //} //catch { } //builder.Clear(); } }
public SchemaBuilder CreateMapIndexTable(string name, Action<CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); var collection = CollectionHelper.Current; var documentTable = collection.GetPrefixedName(Store.DocumentTable); createTable .Column<int>("Id", column => column.PrimaryKey().Identity().NotNull()) .Column<int>("DocumentId"); table(createTable); Execute(_builder.CreateSql(createTable)); CreateForeignKey("FK_" + name, name, new[] { "DocumentId" }, documentTable, new[] { "Id" }); return this; }
public SchemaBuilder CreateReduceIndexTable(string name, Action<CreateTableCommand> table) { var createTable = new CreateTableCommand(FormatTable(name)); createTable .Column<int>("Id", column => column.Identity().NotNull()) ; table(createTable); Execute(_builder.CreateSql(createTable)); var bridgeTableName = name + "_Document"; CreateTable(bridgeTableName, bridge => bridge .Column<int>(name + "Id", column => column.NotNull()) .Column<int>("DocumentId", column => column.NotNull()) ); CreateForeignKey("FK_" + bridgeTableName + "_Id", bridgeTableName, new[] { name + "Id" }, name, new[] { "Id" }); CreateForeignKey("FK_" + bridgeTableName + "DocumentId" , bridgeTableName, new[] { "DocumentId" }, "Document", new[] { "Id" }); return this; }
public void Visit(CreateTableCommand command) { }
/// <summary> /// Generates SchemaCommand instances in order to create the schema for a specific feature /// </summary> public IEnumerable<SchemaCommand> GetCreateFeatureCommands(string feature, bool drop) { var dependencies = _extensionManager.AvailableFeatures() .Where(f => String.Equals(f.Id, feature, StringComparison.OrdinalIgnoreCase)) .Where(f => f.Dependencies != null) .SelectMany(f => f.Dependencies) .ToList(); var shellDescriptor = new ShellDescriptor { Features = dependencies.Select(id => new ShellFeature { Name = id }).Union(new[] { new ShellFeature { Name = feature }, new ShellFeature { Name = "Coevery.Framework" } }) }; var shellBlueprint = _compositionStrategy.Compose(_shellSettings, shellDescriptor); if ( !shellBlueprint.Records.Any() ) { yield break; } //var features = dependencies.Select(name => new ShellFeature {Name = name}).Union(new[] {new ShellFeature {Name = feature}, new ShellFeature {Name = "Coevery.Framework"}}); var parameters = _sessionFactoryHolder.GetSessionFactoryParameters(); parameters.RecordDescriptors = shellBlueprint.Records.ToList(); var configuration = _dataServicesProviderFactory .CreateProvider(parameters) .BuildConfiguration(parameters); Dialect.GetDialect(configuration.Properties); var mapping = configuration.BuildMapping(); // get the table mappings using reflection var tablesField = typeof(Configuration).GetField("tables", BindingFlags.Instance | BindingFlags.NonPublic); var tables = ((IDictionary<string, Table>) tablesField.GetValue(configuration)).Values; string prefix = feature.Replace(".", "_") + "_"; foreach(var table in tables.Where(t => parameters.RecordDescriptors.Any(rd => rd.Feature.Descriptor.Id == feature && rd.TableName == t.Name))) { string tableName = table.Name; var recordType = parameters.RecordDescriptors.First(rd => rd.Feature.Descriptor.Id == feature && rd.TableName == tableName).Type; var isContentPart = typeof(ContentPartRecord).IsAssignableFrom(recordType); if ( tableName.StartsWith(prefix) ) { tableName = tableName.Substring(prefix.Length); } if(drop) { yield return new DropTableCommand(tableName); } var command = new CreateTableCommand(tableName); foreach (var column in table.ColumnIterator) { // create copies for local variables to be evaluated at the time the loop is called, and not lately when the la;bda is executed var tableCopy = table; var columnCopy = column; var sqlType = columnCopy.GetSqlTypeCode(mapping); command.Column(column.Name, sqlType.DbType, action => { if (tableCopy.PrimaryKey.Columns.Any(c => c.Name == columnCopy.Name)) { action.PrimaryKey(); if ( !isContentPart ) { action.Identity(); } } if ( columnCopy.IsLengthDefined() && new[] { DbType.StringFixedLength, DbType.String, DbType.AnsiString, DbType.AnsiStringFixedLength }.Contains(sqlType.DbType) && columnCopy.Length != Column.DefaultLength) { action.WithLength(columnCopy.Length); } if (columnCopy.IsPrecisionDefined()) { action.WithPrecision((byte) columnCopy.Precision); action.WithScale((byte) columnCopy.Scale); } if (columnCopy.IsNullable) { action.Nullable(); } if ( columnCopy.IsUnique ) { action.Unique(); } if(columnCopy.DefaultValue != null) { action.WithDefault(columnCopy.DefaultValue); } }); } yield return command; } }
public int CreateTable(CreateTableCommand c) { return 42; }