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);
  • 相关阅读:
    android studio你可能忽视的细节——启动白屏?drawable和mipmap出现的意义?这里都有!!!
    提升用户体验,你不得不知道的事儿——三种提醒框的微技巧
    【无私分享】修订版干货!!!一个炫酷的自定义日历控件,摆脱日历时间选择烦恼,纯福利~
    【无私分享】干货!!!一个炫酷的自定义日历控件,摆脱日历时间选择烦恼,纯福利~
    放弃安卓原生TimePicker,选择wheelView打造更漂亮的时间get,以及动态拉伸输入框布局,这些,这里都有!
    快速入手别人的安卓项目??你信我,不会想错过这个~~~
    打造android偷懒神器———RecyclerView的万能适配器
    打造android偷懒神器———ListView的万能适配器
    一个可随意定位置的带色Toast——开源代码Crouton的简单使用
    Python学习笔记3-文件的简单操作
  • 原文地址:https://www.cnblogs.com/hcfalan/p/439380.html
Copyright © 2011-2022 走看看