<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 15,  comments - 8,  trackbacks - 0
    摘要:本文通過一個實例講述如何通過Spring2+Hibernate3來快捷操作數據庫中的Lob字段。
    環境:Oracle10g、Srping2、Hibernate3、JUint4

    一、創建實體并添加Xdoclet的Hibernate標簽

    /**
    * @author leizhimin
    * @hibernate.mapping default-lazy="false"
    * @hibernate.meta attribute="class-description" value="工作日志"
    * @hibernate.class table="rc_gzrz"
    */
    public class WorkNote {
      private Long id;             //標識
      private Date workDate;         //日期
      private String weather;         //天氣
      private String content;         //日志內容(Clob)
      private String state;           //日志狀態
      private Long orgId;           //機構id
      private Long userId;           //用戶id
      private Date createDate;         //創建日期
      private byte[] image;           //圖片

      public static final String WORKNOTE_BLANK = "00";       //未填寫
      public static final String WORKNOTE_FULL = "11";       //已填寫

      /**
      * @hibernate.id generator-class="sequence" column="BS"
      * @hibernate.meta attribute="field-description" value="標識"
      * @hibernate.generator-param name="sequence" value="SEQ_GW"
      */
      public Long getId() {
        return id;
      }

      public void setId(Long id) {
        this.id = id;
      }

      /**
      * @hibernate.property column="workDate" not-null="false" type="timestamp"
      * @hibernate.meta attribute="field-description" value="工作日期"
      */

      public Date getWorkDate() {
        return workDate;
      }

      public void setWorkDate(Date workDate) {
        this.workDate = workDate;
      }

      /**
      * @hibernate.property column="weather" not-null="false" length="24"
      * @hibernate.meta attribute="field-description" value="天氣"
      */
      public String getWeather() {
        return weather;
      }

      public void setWeather(String weather) {
        this.weather = weather;
      }

      /**
      * @hibernate.property column="content" not-null="false" type="text"
      * @hibernate.meta attribute="field-description" value="內容"
      */
      public String getContent() {
        return content;
      }

      public void setContent(String content) {
        this.content = content;
      }

      /**
      * @hibernate.property column="state" not-null="false" length="2"
      * @hibernate.meta attribute="field-description" value="狀態"
      */
      public String getState() {
        return state;
      }

      public void setState(String state) {
        this.state = state;
      }

      /**
      * @hibernate.property column="orgId" type="long"
      * @hibernate.meta attribute="field-description" value="機構id"
      */
      public Long getOrgId() {
        return orgId;
      }

      public void setOrgId(Long orgId) {
        this.orgId = orgId;
      }

      /**
      * @hibernate.property column="userId" type="long"
      * @hibernate.meta attribute="field-description" value="用戶id"
      */
      public Long getUserId() {
        return userId;
      }

      public void setUserId(Long userId) {
        this.userId = userId;
      }

      /**
      * @hibernate.property column="createDate" not-null="false" type="timestamp"
      * @hibernate.meta attribute="field-description" value="創建日期"
      */
      public Date getCreateDate() {
        return createDate;
      }

      public void setCreateDate(Date createDate) {
        this.createDate = createDate;
      }

      /**
      * @hibernate.property column="image" type="blob" not-null="false"
      * @hibernate.meta attribute="field-description" value="圖片"
      */
      public byte[] getImage() {
        return image;
      }

      public void setImage(byte[] image) {
        this.image = image;
      }
    }

    二、通過XDoclet生成Mapping,并修正lob映射的類型為Spring提供的類型

    <?xml version="1.0" encoding="gb2312"?>

    <!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping
        default-lazy="false"
    >
      <class
        name="com.topsoft.oa.routine.domain.office.entity.WorkNote"
        table="rc_gzrz"
      >
        <meta attribute="class-description">工作日志</meta>

        <id
            name="id"
            column="BS"
            type="java.lang.Long"
        >
            <meta attribute="field-description">標識</meta>
            <generator class="sequence">
              <param name="sequence">SEQ_GW</param>
            <!--
                To add non XDoclet generator parameters, create a file named
                hibernate-generator-params-WorkNote.xml
                containing the additional parameters and place it in your merge dir.
            -->
            </generator>
        </id>

        <property
            name="workDate"
            type="timestamp"
            update="true"
            insert="true"
            column="workDate"
            not-null="false"
        >
            <meta attribute="field-description">工作日期</meta>
        </property>

        <property
            name="weather"
            type="java.lang.String"
            update="true"
            insert="true"
            column="weather"
            length="24"
            not-null="false"
        >
            <meta attribute="field-description">天氣</meta>
        </property>

        <property
            name="content"
            type="org.springframework.orm.hibernate3.support.ClobStringType"
            update="true"
            insert="true"
            column="content"
            not-null="false"
        >
            <meta attribute="field-description">內容</meta>
        </property>

        <property
            name="state"
            type="java.lang.String"
            update="true"
            insert="true"
            column="state"
            length="2"
            not-null="false"
        >
            <meta attribute="field-description">狀態</meta>
        </property>

        <property
            name="orgId"
            type="long"
            update="true"
            insert="true"
            column="orgId"
        >
            <meta attribute="field-description">機構id</meta>
        </property>

        <property
            name="userId"
            type="long"
            update="true"
            insert="true"
            column="userId"
        >
            <meta attribute="field-description">用戶id</meta>
        </property>

        <property
            name="createDate"
            type="timestamp"
            update="true"
            insert="true"
            column="createDate"
            not-null="false"
        >
            <meta attribute="field-description">創建日期</meta>
        </property>

        <property
            name="image"
            type="org.springframework.orm.hibernate3.support.BlobByteArrayType"
            update="true"
            insert="true"
            column="image"
            not-null="false"
        >
            <meta attribute="field-description">圖片</meta>
        </property>

        <!--
            To add non XDoclet property mappings, create a file named
              hibernate-properties-WorkNote.xml
            containing the additional properties and place it in your merge dir.
        -->

      </class>

    </hibernate-mapping>



    三、通過Mapping 用XDoclet生成數據庫(Oracle)腳本,并建表

      drop table rc_gzrz cascade constraints;


      create table rc_gzrz (
        BS number(19,0) not null,
        workDate timestamp,
        weather varchar2(24 char),
        content clob,
        state varchar2(2 char),
        orgId number(19,0),
        userId number(19,0),
        createDate timestamp,
        image blob,
        primary key (BS)
      );

      comment on table rc_gzrz is
        '工作日志'

      comment on column rc_gzrz.BS is
        '標識'

      comment on column rc_gzrz.workDate is
        '工作日期'

      comment on column rc_gzrz.weather is
        '天氣'

      comment on column rc_gzrz.content is
        '內容'

      comment on column rc_gzrz.state is
        '狀態'

      comment on column rc_gzrz.orgId is
        '機構id'

      comment on column rc_gzrz.userId is
        '用戶id'

      comment on column rc_gzrz.createDate is
        '創建日期'

      comment on column rc_gzrz.image is
        '圖片'



    四、創建DAO層


    /**
    * Created by IntelliJ IDEA.
    * User: leizhimin
    * Date: 2007-11-16
    * Time: 10:55:50
    * To change this template use File | Settings | File Templates.
    */
    public interface WorkNoteDAO extends CommonDAO {
      /**
      * 根據日期查詢工作日志
      *
      * @param workDate 工作日期
      * @param userId   用戶id
      * @param orgId   機構id
      * @param sp     分頁對象
      * @return List
      */
      public List findWorkNoteByDate(Date workDate, Long userId, Long orgId, SplitPage sp);

      /**
      * 根據狀態查詢工作日志
      *
      * @param state   日志狀態
      * @param userId   用戶id
      * @param orgId   機構id
      * @param sp     分頁對象
      * @return List
      */
      public List findWorkNoteByState(String state, Long userId, Long orgId, SplitPage sp);
    }



    /**
    * Created by IntelliJ IDEA.
    * User: leizhimin
    * Date: 2007-11-16
    * Time: 10:56:00
    * To change this template use File | Settings | File Templates.
    */
    public class WorkNoteDAOImpl extends CommonDAOImpl implements WorkNoteDAO{
      public List findWorkNoteByDate(Date workDate, Long userId, Long orgId, SplitPage sp) {
        return null;
      }

      public List findWorkNoteByState(String state, Long userId, Long orgId, SplitPage sp) {
        return null;
      }
    }


    五、創建帶JTA事務控制的業務service層

    /**
    * Created by IntelliJ IDEA.
    * User: leizhimin
    * Date: 2007-11-16
    * Time: 16:43:57
    * To change this template use File | Settings | File Templates.
    */
    public interface OfficeService {

      public void saveWorkNote(WorkNote workNote);

      public void updateWorkNote(WorkNote workNote);
    }


    /**
    * Created by IntelliJ IDEA.
    * User: leizhimin
    * Date: 2007-11-16
    * Time: 16:45:54
    * To change this template use File | Settings | File Templates.
    */
    public class OfficeServiceImpl implements OfficeService{
      private WorkNoteDAO workNoteDAO;

      public WorkNoteDAO getWorkNoteDAO() {
        return workNoteDAO;
      }

      public void setWorkNoteDAO(WorkNoteDAO workNoteDAO) {
        this.workNoteDAO = workNoteDAO;
      }

      public void saveWorkNote(WorkNote workNote) {
        this.workNoteDAO.saveObject(workNote);
      }

      public void updateWorkNote(WorkNote workNote) {
        this.workNoteDAO.updateObject(workNote);
      }
    }


    六、書寫單元測試,并運行
    /**
    * Created by IntelliJ IDEA.
    * User: leizhimin
    * Date: 2007-11-16
    * Time: 16:49:17
    * To change this template use File | Settings | File Templates.
    */
    public class TestOffice extends TestCase {
      public void test_worknote_save(){
        OfficeService officeService = (OfficeService) ContextHelper.getContext().getBean("officeServiceProxy");
        WorkNote workNote=new WorkNote();
        workNote.setContent("http://lavasoft.blog.51cto.com/");
        workNote.setOrgId(Long.parseLong("999"));
        workNote.setCreateDate(new Date());
        byte[] b="lavasoft".getBytes();
        workNote.setImage(b);
        officeService.saveWorkNote(workNote);
      }
    }

    看看測試結果:



    posted on 2008-06-04 20:43 lvq810 閱讀(684) 評論(0)  編輯  收藏 所屬分類: Open Framekwork
    主站蜘蛛池模板: 亚洲精品乱码久久久久久不卡| 日韩av无码成人无码免费| 国产成人免费全部网站| 亚洲AV综合色区无码二区爱AV| 57pao一国产成视频永久免费| 久久精品国产亚洲AV无码偷窥| 日韩精品无码免费一区二区三区 | 国产亚洲精aa成人网站| 美女视频黄a视频全免费网站一区| 免费大片黄手机在线观看| 一边摸一边桶一边脱免费视频| 亚洲第一永久AV网站久久精品男人的天堂AV | 免费视频爱爱太爽了| 亚洲五月综合网色九月色| 国产精品成人免费视频网站京东| 亚洲熟妇自偷自拍另欧美| 四虎影视精品永久免费网站| 国产97视频人人做人人爱免费| 亚洲日韩欧洲无码av夜夜摸| 少妇人妻偷人精品免费视频| 亚洲国产成AV人天堂无码| 日本大片在线看黄a∨免费| 一级毛片免费一级直接观看| 亚洲an天堂an在线观看| 午夜神器成在线人成在线人免费| 日韩a毛片免费观看| 亚洲国产精品免费视频| 成年女人午夜毛片免费视频| 四虎影视久久久免费观看| 亚洲Aⅴ无码专区在线观看q| AV免费网址在线观看| 一本久久免费视频| 亚洲精品视频在线免费| 国产zzjjzzjj视频全免费| 日本黄色动图免费在线观看| 亚洲乱色熟女一区二区三区蜜臀| 国产亚洲人成A在线V网站| 美丽的姑娘免费观看在线播放| 亚洲a无码综合a国产av中文| 久久国产精品亚洲综合| 欧洲美熟女乱又伦免费视频|