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

Data Model for Message Receiver的更多相关文章

  1. EF,ADO.NET Entity Data Model简要的笔记

    1. 新建一个项目,添加一个ADO.NET Entity Data Model的文件,此文件会生成所有的数据对象模型,如果是用vs2012生的话,在.Designer.cs里会出现“// Defaul ...

  2. Create Entity Data Model

    http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx 官 ...

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

    Model代表应用程序管理的一些对象.例如,我们可能会为 我们想在系统中建模的现实世界中的一些物体像使用者.产品和汽车等定义一个Model.这些Model在 Ext.ModelManager中注册,被 ...

  4. [转]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-a ...

  5. Entity Framework Tutorial Basics(5):Create Entity Data Model

    Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...

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

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jaune161/article/details/37391399 1.Model的数据验证 这里借助 ...

  7. HBase 数据模型(Data Model)

    HBase Data Model--HBase 数据模型(翻译) 在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的 ...

  8. PowerDesigner从Physical Data Model转Excel

    参考资料:http://www.cnblogs.com/hggc/archive/2013/10/15/3369857.html 由于有把ER图转Excel的需求,幸运地找到一个可用脚本,稍做修改完成 ...

  9. ExtJS笔记 Ext.data.Model

    A Model represents some object that your application manages. For example, one might define a Model ...

随机推荐

  1. Shell学习之Bash变量详解(二)

    Shell学习之Bash变量详解 目录 Bash变量 Bash变量注意点 用户自定义变量 环境变量 位置参数变量 预定义变量 Bash变量 用户自定义变量:在Bash中由用户定义的变量. 环境变量:这 ...

  2. BZOJ.5286.[AHOI/HNOI2018]转盘(线段树)

    BZOJ LOJ 洛谷 如果从\(1\)开始,把每个时间\(t_i\)减去\(i\),答案取决于\(\max\{t_i-i\}\).记取得最大值的位置是\(p\),答案是\(t_p+1+n-1-p=\ ...

  3. Codeforces.449D.Jzzhu and Numbers(容斥 高维前缀和)

    题目链接 \(Description\) 给定\(n\)个正整数\(a_i\).求有多少个子序列\(a_{i_1},a_{i_2},...,a_{i_k}\),满足\(a_{i_1},a_{i_2}, ...

  4. 权限框架Apache Shiro 和 Spring Security

    Shiro 首先Shiro较之 Spring Security,Shiro在保持强大功能的同时,还在简单性和灵活性方面拥有巨大优势.Shiro是一个强大而灵活的开源安全框架,能够非常清晰的处理认证.授 ...

  5. [CTSC2017]吉夫特

    Description: 给定一个序列\(a_1,a_2,a_3...a_n\) 求有多少个不上升子序列: \(a_{b1},a_{b_2}...\) 满足 \(C_{a_{b1}}^{a_{b2}} ...

  6. 2018 完美搭建VS Code 的JAVA开发环境并解决print乱码问题

    出自微软的Visual Studio Code 并不是一个 IDE,它是个有理想,有前途的编辑器,通过相应语言的插件,可以将其包装成一个 轻量级的功能完善的IDE. 自从遇见了她,真的是对她一见钟情不 ...

  7. BZOJ4223 : Tourists

    将位置划分成$O(m)$段区间,每段最早被阻挡的时间可以用堆维护. 那么每段区间对询问的贡献独立,扫描线处理即可. 时间复杂度$O(m\log m)$. #include<cstdio> ...

  8. 2017.07.06【NOIP提高组】模拟赛B组

    Summary 今天比赛感觉题目很奇葩,都可以用许多简单方法来做,正确性都显然,当然也有点水,也就是说是考我们的数感和数学知识,而程序,只是代码的体现. 这次的时间安排感觉不错,因为很快就打完最后一道 ...

  9. 游戏UI规范

    在满足效果的前提下,尽量做到UI资源做到复用和最小化 1.  背景1和背景2分开切,可以组合成各种不同的面包背景图 2.  背景1和背景2在没有花纹的情况下,中间纯色的部分切4个像素做就公共个缩放就可 ...

  10. web中icon 图标问题

    每个页面都会引入 icon 小图标,下面说下它的用法 一.icon使用 icon的引入方式,与css外部引入方式类似,需要在头部引入, 即: <link rel="shortcut i ...