Data Model for Message Receiver

1. Physical Data Model

2. SQL Statements

drop database MessageReceiver
go

/*==============================================================*/
/* Database: MessageReceiver                                    */
/*==============================================================*/
create database MessageReceiver
go

use MessageReceiver
go

/*==============================================================*/
/* Table: ReceiveMessage                                        */
/*==============================================================*/
create table ReceiveMessage (
   ID                   int                  identity,
   MessageType          nvarchar(200)        not null,
   Operation            smallint             not null,
   Content              nvarchar(max)        not null,
   IsCompleted          bit                  not null,
   TraceID              uniqueidentifier     not null default newid(),
   constraint PK_RECEIVEMESSAGE primary key (ID)
)
go

/*==============================================================*/
/* Table: ReceiveMessageLog                                     */
/*==============================================================*/
create table ReceiveMessageLog (
   ID                   int                  identity,
   ReceiveMessageID     int                  not null,
   LogTime              datetime             not null default getdate(),
   Remark               nvarchar(100)        null,
   constraint PK_RECEIVEMESSAGELOG primary key (ID)
)
go

/*==============================================================*/
/* Index: ix_ReceiveMessageLog_MsgID                            */
/*==============================================================*/
create index ix_ReceiveMessageLog_MsgID on ReceiveMessageLog (
ReceiveMessageID ASC
)
go

/*==============================================================*/
/* Table: SendMessage                                           */
/*==============================================================*/
create table SendMessage (
   ID                   int                  identity,
   MessageType          nvarchar(200)        not null,
   Operation            smallint             not null,
   Content              nvarchar(max)        not null,
   IsArrived            bit                  not null,
   TraceID              uniqueidentifier     not null default newid(),
   constraint PK_SENDMESSAGE primary key (ID)
)
go

/*==============================================================*/
/* Table: SendMessageLog                                        */
/*==============================================================*/
create table SendMessageLog (
   ID                   int                  identity,
   SendMessageID        int                  not null,
   LogTime              datetime             not null default getdate(),
   Remark               nvarchar(100)        null,
   constraint PK_SENDMESSAGELOG primary key (ID)
)
go

/*==============================================================*/
/* Index: ix_SendMessageLog_MsgID                               */
/*==============================================================*/
create index ix_SendMessageLog_MsgID on SendMessageLog (
SendMessageID ASC
)
go

alter table ReceiveMessageLog
   add constraint fk_ReceiveMessage_ReceiveMessageID foreign key (ReceiveMessageID)
      references ReceiveMessage (ID)
go

alter table SendMessageLog
   add constraint fk_SendMessageLog_SendMessageID foreign key (SendMessageID)
      references SendMessage (ID)
go

create procedure up_SendMessageToRemoteServer
as
declare @SendMessageID int,@MessageType nvarchar(200),@Operation smallint,@Content nvarchar(max),@TraceID uniqueidentifier
while(1=1)
begin
    set @SendMessageID=null
    select top(1)    @SendMessageID=ID,
                    @MessageType=MessageType,
                    @Operation=Operation,
                    @Content=Content,
                    @TraceID=TraceID
        from SendMessage a
        where a.IsArrived = 0
        order by a.ID
    if (@SendMessageID is null) break

    exec Server001.MessageReceiver.dbo.up_cReceiveMessageForRemoteServer
            @MessageType =@MessageType,
            @Operation = @Operation,
            @Content = @Content,
            @TraceID=@TraceID

    if (@@error <> 0) break
    exec up_cSendMessageLog
        @SendMessageID = @SendMessageID,
        @Remark = N‘发送‘,
        @IsArrived = 1
end
go

create procedure up_cReceiveMessage
(
    @MessageType nvarchar(200),
    @Operation smallint,
    @Content nvarchar(max)
)
as
begin try
    begin transaction
        declare @ReceiveMessageID int  

        insert into ReceiveMessage ( MessageType, Operation, Content,IsCompleted)
            values(@MessageType,@Operation,@Content,0)

        set @ReceiveMessageID=scope_identity()

        insert into ReceiveMessageLog ( ReceiveMessageID, Remark )
            values(@ReceiveMessageID,N‘接收.‘)

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go

create procedure up_cReceiveMessageForRemoteServer
(
    @MessageType nvarchar(200),
    @Operation smallint,
    @Content nvarchar(max),
    @TraceID uniqueidentifier
)
as
begin try
    begin transaction
        declare @ReceiveMessageID int  

        insert into ReceiveMessage ( MessageType, Operation, Content,IsCompleted,TraceID)
            values(@MessageType,@Operation,@Content,0,@TraceID)

        set @ReceiveMessageID=scope_identity()

        insert into ReceiveMessageLog ( ReceiveMessageID, Remark )
            values(@ReceiveMessageID,N‘接收.‘)

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go

create procedure up_cReceiveMessageLog
(
    @ReceiveMessageID int,
    @Remark nvarchar(100),
    @IsCompleted bit
)
as
begin try
    begin transaction        

        insert into ReceiveMessageLog ( ReceiveMessageID, Remark )
            values(@ReceiveMessageID,@Remark)

        update ReceiveMessage set IsCompleted=@IsCompleted where ID=@ReceiveMessageID

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go

create procedure up_cSendMessage
(
    @MessageType nvarchar(200),
    @Operation smallint,
    @Content nvarchar(max)
)
as
begin try
    begin transaction
        declare @SendMessageID int  

        insert into SendMessage ( MessageType, Operation, Content,IsArrived)
            values(@MessageType,@Operation,@Content,0)

        set @SendMessageID=scope_identity()

        insert into SendMessageLog ( SendMessageID, Remark )
            values(@SendMessageID,N‘接收.‘)

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go

create procedure up_cSendMessageLog
(
    @SendMessageID int,
    @Remark nvarchar(100),
    @IsArrived bit
)
as
begin try
    begin transaction        

        insert into SendMessageLog ( SendMessageID, Remark )
            values(@SendMessageID,@Remark)

        update SendMessage set IsArrived=@IsArrived where ID=@SendMessageID

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go

create procedure up_dReceiveMessageWithCompleted
as
set nocount on
begin try
    begin transaction
        declare @tb_del table(ID int)
        insert into @tb_del(ID) select ID from ReceiveMessage where IsCompleted=1

        delete a from ReceiveMessageLog a where exists(select 1 from @tb_del x where x.ID=a.ReceiveMessageID)

        delete a from ReceiveMessage a where exists(select 1 from @tb_del x where x.ID=a.ID)

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go

create procedure up_dSendMessageWithArrived
as
begin try
    begin transaction

        declare @tb_del table(ID int)
        insert into @tb_del(ID) select ID from SendMessage where IsArrived=1

        delete a from SendMessageLog a where exists(select 1 from @tb_del x where x.ID=a.SendMessageID)

        delete a from SendMessage a where exists(select 1 from @tb_del x where x.ID=a.ID)

    commit transaction
end try
begin catch
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go
时间: 2024-10-11 16:31:07

Data Model for Message Receiver的相关文章

[ExtJs] ExtJs4.2 数据模型Ext.data.Model学习

Model代表应用程序管理的一些对象.例如,我们可能会为 我们想在系统中建模的现实世界中的一些物体像使用者.产品和汽车等定义一个Model.这些Model在 Ext.ModelManager中注册,被Ext.data.Store使用, 而这些Ext.data.Store又被许多 Ext中许多与数据绑定的组件使用. 直接上代码: <%-- Created by IntelliJ IDEA. User: Administrator Date: 2015/12/13 0013 Time: 08:51

[转]Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)

本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10) By      

extjs4新特性Ext.data.model

在发布的ExtJS4版本中,在data包中新增加了一个类Model(模型类).这个类有点类似于ExtJS3.x中的record,但是新添加的Model的功能要比record类的功能强大的多,下面我们就是一起讨论一下.Model类的功能: (一).首先我们介绍一下Model类中比较常用的几个属性,如果我们想构建一个Model类,最主要的属性就是(Fields)属性,这个属性接受一个数组.用来设置Model中所包含的字段.定义的格式如下: Ext.regModel("Student",{

ExtJS教程(5)---Ext.data.Model之高级应用

1.Model的数据验证 这里借助官方的一个例子来说Model数据验证的基本用法 Ext.define('User', { extend: 'Ext.data.Model', fields: [ { name: 'name', type: 'string' }, { name: 'age', type: 'int' }, { name: 'phone', type: 'string' }, { name: 'gender', type: 'string' }, { name: 'username

Entity Framework的核心 – EDM(Entity Data Model) 一

这次开发项目,我依然做的是.Net,前几个月的项目底层设计使用的的是 ORM 思想,技术选用的是NHibernate,这次也不例外,开发.Net项目,依然使用的是ORM的思想,不同的是这次开发技术选用的是EF(EntityFrameWork).这个框架可是让我费眼不少,我了解它,从它的XML开始的.开始说说有关EF中xml的解读. 一.EnityFramework EnityFramework的全程是ADO.NET Entity Framework .和Nhibernate一样,EF 同样是遵守

Create Entity Data Model

http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx Here, we are going to create an Entity Data Model (EDM) for SchoolDB database and understand the basic building blocks. Entity Data Model is a model th

Extjs的form表单自动装载数据(通过Ext.data.Model的代理加载数据)

在做项目的时候遇到一个问题,以前双击grid页面一行数据的时候,会吧双击这一行的数据自动加载到双击的页面(Ext的弹出框),可以通过this.down(''form).getForm().loadRecord(record)来自动加载,可是现在有一个需求就是双击grid一行弹出一个新的浏览器页面(不是ext的弹出框,通过window.open()实现),只能把双击的id传到页面,再重新查数据手动赋值,如果一个页面字段很多,一个一个赋值是很辛苦的,所以就想能不能自动装载数据 通过长时间研究发现,t

Changes in Microsoft Dynamics AX 2012 InventTrans data model

The purpose of this post is to give an overview about the changes been made in the Dynamics AX 2012 data model related to inventory transactions. Before AX2012, the only table used for recording all the inventory transactions was InventTrans.  In AX2

ExtJS笔记 Ext.data.Model

A Model represents some object that your application manages. For example, one might define a Model for Users, Products, Cars, or any other real-world object that we want to model in the system. Models are registered via the model manager, and are us