ORM(一)OQL结构图

代码是基于:1.1
 
从上图我们可以看出接口IExpression是比较重要的接口,所有与SQL语句相关的接口都继承了此接口.
在这里我称IExpression接口为表达式接口.我理解SQL里所有的字段,条件,查询语句,更新语句,删除语句,排序,分组等最终都会转换成一个字符串加参数.所以IExpression接口只有一个方法: Function Expression(ByRef pars As ParameterCollection) As String对于参数集合我使用了传址的方式,函数返回值是字符串,可以是条件的,可以是具体的某一类语句.这样我个人觉得就抽象出了SQL语句里所有定义.

在SQL语句中,我们不外乎就是:select,update,delete,insert.对于insert语句来说比较简单我们就直接继承于接口ICommand.其中update,delete,select语句比较
类似.当然select语句有其特殊性.它们三个都继承于ICommand,IsearchCondition两个接口.其中ISearchCondition接口是对于有条件子句的sql语句.
我们来看看Icommand接口定义:
    Public Interface ICommand
        Inherits OQL.IExpression
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 命令文本.
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-10-21 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        ReadOnly Property CommandText() As String

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 返回命令的类型.
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-12-23 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        ReadOnly Property CommandType() As CommandType

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 命令中包含的参数集合.
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-10-21 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        ReadOnly Property Parameters() As OQL.ParameterCollection

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' 限制操作的表.
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [zqonline] 2006-10-21 Created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Property TableSourceList() As ITableSourceList

    End Interface
这里只需要对TableSourceList属性进行说明.它主要是用于指定了select,insert,updae,delete中from子句的内容.
下面是对ISearchCondition接口的定义
  Public Interface ISearchCondition
        Property SearchCondition() As OQL.IExpression
    End Interface
主要是用于得到select,update,delete中where子句的内容.insert没有,所以就不需要它了.

我们在来看看其它几个继承于ICommand接口的接口定义
 Public Interface IWhere
        Inherits ICommand
        ReadOnly Property WHERE(ByVal exxpression As OQL.IExpression) As IGroupby
        ReadOnly Property OrderBy(ByVal ParamArray sort() As OQL.IExpression) As ICommand
    End Interface
 Public Interface IOrderby
        Inherits ICommand
        ReadOnly Property OrderBy(ByVal ParamArray sort() As OQL.IExpression) As ICommand
    End Interface
   Public Interface IGroupby
        Inherits ICommand
        ReadOnly Property GroupBy(ByVal ParamArray expression() As OQL.IExpression) As IOrderby
        ReadOnly Property OrderBy(ByVal ParamArray sort() As OQL.IExpression) As ICommand
    End Interface
大家看看,我这几个接口的定义,是否可以满足了sql语句的结构.


好了今天就到这里了.

申明:此源码是个人构思,欢迎转载,但请注明出处http://www.cnblogs.com/zqonline
ORM是在1.1+sqlserver2000的基础上构建的,由于本人英文极差,所以其中的类名,方法名有可能会让你恶心.

posted on 2007-04-02 23:49  zqonline  阅读(3185)  评论(12编辑  收藏  举报

导航