Пример #1
0
 public void No_PrimaryKey()
 {
     var c = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("dbo", "test");
     test.Constraints.Add(c);
     Assert.Null(test.PrimaryKey);
 }
Пример #2
0
 public void GetSet_Unique()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>());
     var c = test.Unique;
     test.Unique = !c;
     Assert.Equal(!c, test.Unique);
 }
Пример #3
0
 public void Set_PrimaryKey()
 {
     var c = new Constraint("ix_testing", ContraintType.PrimaryKey, "testing");
     var test = new Table("dbo", "test");
     test.Constraints.Add(c);
     Assert.Equal(c, test.PrimaryKey);
 }
Пример #4
0
 public void GetSet_Clustered()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>());
     var c = test.Clustered;
     test.Clustered = !c;
     Assert.Equal(!c, test.Clustered);
 }
 /// <summary>
 /// Tells the transport to setup and create a queue for handling re-occurring jobs.
 /// </summary>
 /// <param name="registerService">The additional registrations.</param>
 /// <param name="queue">The queue.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="enableRoute">if set to <c>true</c> route support will be enabled.</param>
 /// <returns></returns>
 public QueueCreationResult CreateJobSchedulerQueue(Action<IContainer> registerService, string queue, string connection, bool enableRoute = false)
 {
     if (_queueCreation.Options.AdditionalColumns.Count == 0)
     {
         _queueCreation.Options.AdditionalColumns.Add(new Column("JobName", ColumnTypes.Varchar, 255, false, null));
         var constraint = new Constraint($"IX_{queue}JobName", ContraintType.Constraint,
             "JobName") {Unique = true};
         _queueCreation.Options.AdditionalConstraints.Add(constraint);
     }
     if(enableRoute)
     {
         _queueCreation.Options.EnableRoute = true;
     }
     return _queueCreation.CreateQueue();
 }
Пример #6
0
 public void Create_Script()
 {
     var c = new Column("testing", ColumnTypes.Bigint, true, null);
     var cc = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("dbo", "test");
     test.Constraints.Add(cc);
     test.Columns.Add(c);
     //set the table reference
     foreach (var ccc in test.Constraints)
     {
         ccc.Table = test.Info;
     }
     Assert.Contains("dbo", test.Script());
     Assert.Contains("test", test.Script());
 }
        /// <summary>
        /// Creates the meta data table schema.
        /// </summary>
        /// <returns></returns>
        private Table CreateMetaDataTable()
        {
            //--Meta Data Table --
            var meta = new Table(GetOwner(), _tableNameHelper.MetaDataName);
            var mainPrimaryKey = new Column("QueueID", ColumnTypes.Bigint, false, null);
            meta.Columns.Add(mainPrimaryKey);

            //add primary key constraint
            meta.Constraints.Add(new Constraint("PK_" + _tableNameHelper.MetaDataName, ContraintType.PrimaryKey, "QueueID"));
            meta.PrimaryKey.Unique = true;

            if (_options.Value.EnablePriority)
            {
                meta.Columns.Add(new Column("Priority", ColumnTypes.Tinyint, false, null));
            }

            meta.Columns.Add(new Column("QueuedDateTime", ColumnTypes.Datetime, false, null));

            if (_options.Value.EnableStatus)
            {
                meta.Columns.Add(new Column("Status", ColumnTypes.Int, false, null));
            }
            if (_options.Value.EnableDelayedProcessing)
            {
                meta.Columns.Add(new Column("QueueProcessTime", ColumnTypes.Datetime, false, null));
            }

            meta.Columns.Add(new Column("CorrelationID", ColumnTypes.Uniqueidentifier, false, null));

            if (_options.Value.EnableHeartBeat)
            {
                meta.Columns.Add(new Column("HeartBeat", ColumnTypes.Datetime, true, null));
            }

            if (_options.Value.EnableMessageExpiration || _options.Value.QueueType == QueueTypes.RpcReceive || _options.Value.QueueType == QueueTypes.RpcSend)
            {
                meta.Columns.Add(new Column("ExpirationTime", ColumnTypes.Datetime, false, null));
            }

            if (_options.Value.EnableRoute)
            {
                meta.Columns.Add(new Column("Route", ColumnTypes.Varchar, 255, true, null));
            }

            switch (_options.Value.QueueType)
            {
                case QueueTypes.RpcReceive:
                    meta.Columns.Add(new Column("SourceQueueID", ColumnTypes.Bigint, false, null));
                    break;
            }

            var clusterIndex = new List<string>();
            if (_options.Value.EnableStatus)
            {
                clusterIndex.Add("Status");
            }
            if (_options.Value.EnablePriority)
            {
                clusterIndex.Add("Priority");
            }
            if (_options.Value.EnableDelayedProcessing)
            {
                clusterIndex.Add("QueueProcessTime");
            }
            if (_options.Value.EnableRoute)
            {
                clusterIndex.Add("Route");
            }
                //add index on expiration time if needed
            if (_options.Value.EnableMessageExpiration || _options.Value.QueueType == QueueTypes.RpcReceive || _options.Value.QueueType == QueueTypes.RpcSend)
            {
                clusterIndex.Add("ExpirationTime");
            }

            switch (_options.Value.QueueType)
            {
                case QueueTypes.RpcReceive:
                    clusterIndex.Add("SourceQueueID");
                    break;
            }

            if (clusterIndex.Count > 0)
            {
                clusterIndex.Add("QueueID");
                var cluster = new Constraint("IX_DeQueue", ContraintType.Index, clusterIndex)
                {
                    Clustered = true,
                    Unique = true
                };
                meta.Constraints.Add(cluster);
            }
            else //this is a FIFO queue, just cluster on the primary key
            {
                meta.PrimaryKey.Clustered = true;
            }

            //add index on heartbeat column if enabled
            if (_options.Value.EnableHeartBeat)
            {
                meta.Constraints.Add(new Constraint("IX_HeartBeat", ContraintType.Index, "HeartBeat"));
            }

            //set the table reference
            foreach (var c in meta.Constraints)
            {
                c.Table = meta.Info;
            }

            return meta;
        }
Пример #8
0
 /// <summary>
 /// Clones this instance.
 /// </summary>
 /// <returns></returns>
 public Constraint Clone()
 {
     var temp = new List<string>();
     temp.AddRange(Columns);
     var rc = new Constraint(Name, Type, temp)
     {
         Clustered = Clustered,
         Unique = Unique
     };
     return rc;
 }
Пример #9
0
 public void Script()
 {
     var test = new Constraint("test", ContraintType.PrimaryKey, new List<string>());
     Assert.Contains("test", test.Script());
 }
Пример #10
0
 public void GetSet_ContraintType()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>());
     Assert.Equal(ContraintType.Constraint, test.Type);
 }
Пример #11
0
 public void GetSet_Name()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>()) {Name = "test1"};
     Assert.Equal("test1", test.Name);
 }
Пример #12
0
 public void GetSet_Columns()
 {
     var columns = new List<string> {"test"};
     var test = new Constraint("test", ContraintType.Constraint, columns);
     Assert.Equal(columns, test.Columns);
 }