Represents a constraint
示例#1
0
 public void Set_PrimaryKey()
 {
     var c = new Constraint("ix_testing", ContraintType.PrimaryKey, "testing");
     var test = new Table("test");
     test.Constraints.Add(c);
     Assert.Equal(c, test.PrimaryKey);
 }
示例#2
0
 public void No_PrimaryKey()
 {
     var c = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("test");
     test.Constraints.Add(c);
     Assert.Null(test.PrimaryKey);
 }
 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);
 }
示例#4
0
 public void Create_Script()
 {
     var c = new Column("testing", ColumnTypes.Bigint, true);
     var cc = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("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("test", test.Script());
 }
 /// <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> [enable route].</param>
 /// <returns></returns>
 /// <exception cref="NotImplementedException"></exception>
 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));
         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();
 }
 public void Script()
 {
     var test = new Constraint("test", ContraintType.PrimaryKey, new List<string>());
     Assert.Contains("test", test.Script());
 }
 public void GetSet_ContraintType()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>());
     Assert.Equal(ContraintType.Constraint, test.Type);
 }
 public void GetSet_Name()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>()) {Name = "test1"};
     Assert.Equal("test1", test.Name);
 }
 public void GetSet_Columns()
 {
     var columns = new List<string> {"test"};
     var test = new Constraint("test", ContraintType.Constraint, columns);
     Assert.Equal(columns, test.Columns);
 }
示例#10
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)
     {
         Unique = Unique
     };
     return rc;
 }
        /// <summary>
        /// Creates the meta data table schema.
        /// </summary>
        /// <returns></returns>
        private Table CreateMetaDataTable()
        {
            //--Meta Data Table --
            var meta = new Table(_tableNameHelper.MetaDataName);
            var mainPrimaryKey = new Column("QueueID", ColumnTypes.Bigint, false);
            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.Integer, false));
            }

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

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

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

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

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

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

            switch (_options.Value.QueueType)
            {
                case QueueTypes.RpcReceive:
                    meta.Columns.Add(new Column("SourceQueueID", ColumnTypes.Bigint, false));
                    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");
            }

            if (clusterIndex.Count > 0)
            {
                var cluster = new Constraint($"IX_DeQueue{_tableNameHelper.MetaDataName}", ContraintType.Index, clusterIndex)
                {
                    Unique = true
                };
                meta.Constraints.Add(cluster);
            }

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

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

            return meta;
        }