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);
  • 相关阅读:
    [背包问题][二进制优化] Jzoj P4224 食物
    [并查集][排序] Jzoj P4223 旅游
    [哈夫曼树][优先队列] Bzoj P4198 荷马史诗
    [hash][差分][虚树] Jzoj P6011 天天爱跑步
    [dp] Jzoj P6012 荷马史诗
    [dp][递归] Jzoj P4211 送你一棵圣诞树
    [数学] Jzoj P3912 超氧化钾
    堆学习笔记(未完待续)(洛谷p1090合并果子)
    [AC自动机]luogu P2444 病毒
    [概率期望][DP]luogu P3830 随机树
  • 原文地址:https://www.cnblogs.com/hcfalan/p/439380.html
Copyright © 2011-2022 走看看