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);
  • 相关阅读:
    你绝对想不到R文件找不到(cannot resolve symbol R)的原因
    你绝对想不到R文件找不到(cannot resolve symbol R)的原因
    如何安装gulp
    简单实现IE9及以下对placeholder的兼容性
    vue 新闻列表滚动效果
    2018数据技术嘉年华-金融峰会·重庆站即将起航!
    高手过招:用SQL解决环环相扣的刑侦推理问题(罗海雄版本)
    实战课堂:为什么更换存储之后一切正常但RAC集群启动不了?
    MySql避免重复插入记录方法(ignore,Replace,ON DUPLICATE KEY UPDATE)
    Druid数据库连接池和Druid内置监控系统简单介绍
  • 原文地址:https://www.cnblogs.com/hcfalan/p/439380.html
Copyright © 2011-2022 走看看