zoukankan      html  css  js  c++  java
  • NHibernate ORM of Inherit Tree

    NHibernate ORM of Inherit Tree
     
    UML:
    public abstract class GenDocument
    public sealed class Document : GenDocument
    public sealed class NoticeDocument : GenDocument

     
    Mapping Define:
    <class name="GenDocument" table="GenDocs">
        <id name="ID" column="OBID">
            <generator class="uuid.hex" />
        </id>
        <timestamp name="LastUpdated" />
        <property name="DocumentName" column="DocumentName" />
        <property name="Revision" column="Revision" />
        <property name="Sequence" column="Sequence" />
        <property name="Workflow" column="Workflow" />
        <property name="OwnerName" column="OwnerName" />
        <property name="LcStatus" column="LcStatus" />
        <property name="CreatedBy" column="CreatedBy" />
        <property name="CreatedDate" column="CreatedDate" />
        <property name="UpdatedBy" column="UpdatedBy" />
    </class>
     
    <class name="Document" table="Documents">
        <id name="ID" column="OBID">
            <generator class="uuid.hex" />
        </id>
        <timestamp name="LastUpdated" />
        <property name="DocumentName" column="DocumentName" />
        <property name="Revision" column="Revision" />
        <property name="Sequence" column="Sequence" />
        <property name="Workflow" column="Workflow" />
        <property name="OwnerName" column="OwnerName" />
        <property name="LcStatus" column="LcStatus" />
        <property name="CreatedBy" column="CreatedBy" />
        <property name="CreatedDate" column="CreatedDate" />
        <property name="UpdatedBy" column="UpdatedBy" />
    </class>
     
    <class name="NoticeDocument" table="NoticeDocuments">
        <id name="ID" column="OBID">
            <generator class="uuid.hex" />
        </id>
        <timestamp name="LastUpdated" />
        <property name="DocumentName" column="DocumentName" />
        <property name="Revision" column="Revision" />
        <property name="Sequence" column="Sequence" />
        <property name="Workflow" column="Workflow" />
        <property name="OwnerName" column="OwnerName" />
        <property name="LcStatus" column="LcStatus" />
        <property name="Content" column="Content" />
        <property name="CreatedBy" column="CreatedBy" />
        <property name="CreatedDate" column="CreatedDate" />
        <property name="UpdatedBy" column="UpdatedBy" />
    </class>
     
    Code:
     
    IDaoFactory factory = GetDaoFactory();
     
    /* create an transient object of Document */
    Document document = new Document();
    document.DocumentName = "document #1";
    document.Revision = "A";
    document.Sequence = 1;
    document.OwnerName = "alan";
    document.CreatedBy = "alan";
     
    /* persist the Document object */
    IDocumentDao documentDao = factory.GetDocumentDao();
    documentDao.Save(document);
    documentDao.Commit();
    documentDao.Dispose();
     
    /* create an transient object of NoticeDocument */
    NoticeDocument noticeDocument = new NoticeDocument();
    noticeDocument.DocumentName = "notice #1";
    noticeDocument.Revision = "A";
    noticeDocument.Sequence = 1;
    noticeDocument.OwnerName = "alan";
    noticeDocument.CreatedBy = "alan";
    noticeDocument.Content = "notice body of notice #1";
     
    /* persist the NoticeDocument object */
    INoticeDocumentDao noticeDocumentDao = factory.GetNoticeDocumentDao();
    noticeDocumentDao.Save(noticeDocument);
    noticeDocumentDao.Commit();
    noticeDocumentDao.Dispose();
     
    /* Load All by GenDocument Data Access Object */
    IGenDocumentDao genDocumentDao = factory.GetGenDocumentDao();
    IList genDocs = genDocumentDao.GetAll();
    genDocs.Dispose();
    /*
     * GenDocument的数据访问函数应该在GetAll函数中返回所有
     * 它本身的对象以及其子类的对象
     */
    Assert.AreEqual(2, genDocs.Count);
     
    /* Load All by Document Data Access Object */
    documentDao = factory.GetDocumentDao();
    IList documents = documentDao.GetAll();
    documentDao.Dispose();
    /*
     * Document的数据访问函数应该在GetAll函数中返回所有
     * 它本身的对象,建议将Document class定义为sealed
     * 避免继承它
     */
    Assert.AreEqual(1, documents.Count);
    Assert.AreEqual("document #1", ((Document)documents[0]).DocumentName);
     
    /* Load All by NoticeDocument Data Access Object */
    noticeDocumentDao = factory.GetNoticeDocumentDao();
    IList noticeDocs = noticeDocumentDao.GetAll();
    noticeDocumentDao.Dispose();
    /*
     * NoticeDocument的数据访问函数应该在GetAll函数中返回所有
     * 它本身的对象,建议将NoticeDocument class定义为sealed
     * 避免继承它
     */
    Assert.AreEqual(1, noticeDocs.Count);
    Assert.AreEqual("notice body of notice #1", ((NoticeDocument)noticeDocs[0]).Content);
  • 相关阅读:
    git-将dev代码合并到test
    java中一句话取到用split()截后的最后一个值
    shiro重定向或会话失效后NginxURL地址无效,以及浏览器控制台Mixed Content: The page at ‘https://XXX’ was loaded over HTTPS, but requested an insecure错误
    Linux 查找Nginx配置文件位置命令
    Linux 常用命令(个人暂时用到的)
    代理模式
    【Vue自学笔记(四)】天气案例
    【Vue自学笔记(三)】网络请求的简单使用
    【Vue自学笔记】案例
    【Vue自学笔记(二)】Vue指令
  • 原文地址:https://www.cnblogs.com/hcfalan/p/439380.html
Copyright © 2011-2022 走看看