Represents a table in SQLite
 public void Create_Column()
 {
     var c = new Column("testing", ColumnTypes.Integer, true, null);
     var test = new Table("test");
     test.Columns.Add(c);
     Assert.True(test.Columns.Items.Any(item => item.Name == "testing"));
 }
 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 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);
 }
        /// <summary>
        /// Creates the main table schema
        /// </summary>
        /// <returns></returns>
        private Table CreateMainTable()
        {
            //--main data table--
            var main = new Table(_tableNameHelper.QueueName);
            var mainPrimaryKey = new Column("QueueID", ColumnTypes.Integer, false, null) {Identity = new Identity()};

            main.Columns.Add(mainPrimaryKey);
            main.Columns.Add(new Column("Body", ColumnTypes.Blob, -1, false, null));
            main.Columns.Add(new Column("Headers", ColumnTypes.Blob, -1, false, null));

            return main;
        }
        /// <summary>
        /// Creates the main table schema
        /// </summary>
        /// <returns></returns>
        private Table CreateMainTable()
        {
            //--main table--
            var main = new Table(_tableNameHelper.JobTableName);
            main.Columns.Add(new Column("JobEventTime", ColumnTypes.Text, 35, false, null));
            main.Columns.Add(new Column("JobScheduledTime", ColumnTypes.Text, 35, false, null));
            main.Columns.Add(new Column("JobName", ColumnTypes.Text, 255, false, null));

            //add primary key constraint
            main.Constraints.Add(new Constraint("PK_" + _tableNameHelper.JobTableName, ContraintType.PrimaryKey, "JobName"));
            main.PrimaryKey.Unique = true;
            return main;
        }
 public void Create_Script()
 {
     var c = new Column("testing", ColumnTypes.Integer, true, null);
     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>
        /// Creates the configuration table schema.
        /// </summary>
        /// <returns></returns>
        private Table CreateConfigurationTable()
        {
            var table = new Table(_tableNameHelper.ConfigurationName);
            var mainPrimaryKey = new Column("ID", ColumnTypes.Integer, false, null) {Identity = new Identity()};
            table.Columns.Add(mainPrimaryKey);
            table.Columns.Add(new Column("Configuration", ColumnTypes.Blob, -1, false, null));

            return table;
        }
        /// <summary>
        /// Creates the error table schema. This is a copy of the meta table, but with an exception column added. 
        /// </summary>
        /// <param name="meta">The meta.</param>
        /// <returns></returns>
        private Table CreateErrorTable(Table meta)
        {
            var metaErrors = new Table(_tableNameHelper.MetaDataErrorsName);
            var primaryKey = new Column("ID", ColumnTypes.Integer, false, null) {Identity = new Identity()};
            metaErrors.Columns.Add(primaryKey);
            foreach (var c in meta.Columns.Items)
            {
                metaErrors.Columns.Add(c.Clone());
            }
            metaErrors.Columns.Add(new Column("LastException", ColumnTypes.Text, -1, true, null));
            metaErrors.Columns.Add(new Column("LastExceptionDate", ColumnTypes.Integer, true, null));

            //add primary key constraint
            //metaErrors.Constraints.Add(new Constraint("PK_" + _tableNameHelper.MetaDataErrorsName, ContraintType.PrimaryKey, "ID"));
            //metaErrors.PrimaryKey.Unique = true;

            //NOTE no indexes are copied from the meta table
            foreach (var c in metaErrors.Constraints)
            {
                c.Table = metaErrors.Info;
            }

            return metaErrors;
        }
        /// <summary>
        /// Creates the error tracking table schema.
        /// </summary>
        /// <returns></returns>
        private Table CreateErrorTrackingTable()
        {
            //--Error tracking table--
            var errorTracking = new Table(_tableNameHelper.ErrorTrackingName);
            var errorTrackingPrimaryKey = new Column("ErrorTrackingID", ColumnTypes.Integer, false, null)
            {
                Identity = new Identity()
            };
            errorTracking.Columns.Add(errorTrackingPrimaryKey);

            errorTracking.Columns.Add(new Column("QueueID", ColumnTypes.Integer, false, null));
            errorTracking.Columns.Add(new Column("ExceptionType", ColumnTypes.Text, 500, false, null));
            errorTracking.Columns.Add(new Column("RetryCount", ColumnTypes.Integer, false, null));

            //add primary key constraint
            //errorTracking.Constraints.Add(new Constraint("PK_" + _tableNameHelper.ErrorTrackingName, ContraintType.PrimaryKey, "ErrorTrackingID"));
            //errorTracking.PrimaryKey.Unique = true;

            errorTracking.Constraints.Add(new Constraint("IX_QueueID", ContraintType.Index, "QueueID"));

            foreach (var c in errorTracking.Constraints)
            {
                c.Table = errorTracking.Info;
            }

            return errorTracking;
        }
        /// <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.Integer, 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.Integer, false, null));
            }

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

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

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

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

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

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

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

            if (clusterIndex.Count > 0)
            {
                var cluster = new Constraint("IX_DeQueue", 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", ContraintType.Index, "HeartBeat"));
            }

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

            return meta;
        }
        private Table CreateStatusTable()
        {
            //--Meta Data Table --
            var status = new Table(_tableNameHelper.StatusName);
            var mainPrimaryKey = new Column("QueueID", ColumnTypes.Integer, false, null);
            status.Columns.Add(mainPrimaryKey);

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

            status.Columns.Add(new Column("Status", ColumnTypes.Integer, false, null));
            status.Columns.Add(new Column("CorrelationID", ColumnTypes.Text, 38, false, null));

            //add extra user columns
            foreach (var c in _options.Value.AdditionalColumns.Values)
            {
                status.Columns.Add(c);
            }

            //add extra user constrains
            foreach (var c in _options.Value.AdditionalConstraints.Values)
            {
                status.Constraints.Add(c);
            }

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

            return status;
        }
Exemple #12
0
 public void GetSet_Name()
 {
     var test = new Table("test") {Name = "test1"};
     Assert.Equal("test1", test.Name);
 }
Exemple #13
0
 public void No_PrimaryKey2()
 {
     var test = new Table("test");
     Assert.Null(test.PrimaryKey);
 }
Exemple #14
0
 public void Default()
 {
     var test = new Table("test");
     Assert.Equal("test", test.Name);
 }