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. POJ 2289 Jamie's Contact Groups 【二分】+【多重匹配】(模板题)

    <题目链接> 题目大意: 有n个人,每个人都有一个或者几个能够归属的分类,将这些人分类到他们能够归属的分类中后,使所含人数最多的分类值最小,求出该分类的所含人数值. 解题分析: 看到求最大 ...

  2. 用单向链表实现两数倒序相加(java实现)

    很久没做算法题了,准备重操旧业,于是刷了一波LeetCode,看到一个比较经典的链表算法题,分享出来. 题目 给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将 ...

  3. Mybatis之占位符与拼接符

    1.占位符 1.1  含义: 在持久化框架中,为了将约束条件中的可变参数从sql中分离出来,在原有的参数位置使用特殊的标记来标记该位置,后期通过代码给sql传递参数(即实现sql与代码分离开).这个特 ...

  4. python数据结构之插入排序

    插入排序(英语:Insertion Sort)是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.插入排序在实现上,在从后向前扫描 ...

  5. spring boot + jpa + bootstrap + thymeleaf 简单的增删改查Demo

    对springboot和bootstrap初学者来说是一个不错Demo 下载地址:点击进入下载Demo 首页(http://localhost:8081) 增加 编辑 搜索

  6. Java笔记(十四) 并发基础知识

    并发基础知识 一.线程的基本概念 线程表示一条单独的执行流,它有自己的程序计数器,有自己的栈. 1.创建线程 1)继承Thread Java中java.lang.Thread这个类表示线程,一个类可以 ...

  7. 关于腾讯云服务器不能用公网ip访问的解决方案

    最近在腾讯云服务器上部署Javaweb项目,开始外网ip是可以访问到云服务器上的项目的,我重启了一下Tomcat之后发现端口号8080无法使用,此时的公网ip还是可以使用的,然后我重启了一下云服务器之 ...

  8. LeetCode(509. 斐波那数)

    问题描述: 斐波那契数,通常用 F(n) 表示,形成的序列称为斐波那契数列.该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和.也就是: F(0) = 0, F(1) = 1 F(N) ...

  9. Python——lambda函数

    Lambda 函数又称匿名函数,匿名函数就是没有名字的函数,函数没有名字也行?当然可以啦.有些函数如果只是临时一用,而且它的业务逻辑也很简单时,就没必要非给它取个名字不可. 好比电影里面的群众演员,往 ...

  10. MVC微型框架---------学习

    1.单一入口机制 是指在web程序中 所有的请求都指向一个脚本文件 2.工厂模式的概念精髓:工厂类就是对类的封装,类是对方法的封装,方法是对实现过程的封装调用当前类的静态方法,规范的写法是使用 sel ...