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

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

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

    vjame

    優化代碼是無止境的
    隨筆 - 65, 文章 - 9, 評論 - 26, 引用 - 0
    數據加載中……

    hibernate中對CLOB字段數據進行增刪修

     

    /*
     * Copyright: Jiang Xi Strong Co.. Ltd.
     * 
     * All right reserved.
     *  
     
    */
    package com.strongit.credit.manager.infomanager.dao.impl;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.Serializable;
    import java.io.Writer;
    import java.lang.reflect.Method;
    import java.sql.Clob;
    import java.util.List;

    import oracle.sql.CLOB;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    import org.hibernate.Hibernate;
    import org.hibernate.LockMode;
    import org.hibernate.SQLQuery;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.hibernate.lob.SerializableClob;

    import com.strongit.credit.common.dao.impl.CreditDAO;
    import com.strongit.credit.common.filter.ResultFilter;
    import com.strongit.credit.common.po.Info;
    import com.strongit.credit.common.po.Stat;
    import com.strongit.credit.common.po.Subject;
    import com.strongit.credit.manager.infomanager.dao.InfoDao;

    /*
     * Create Date:2008-9-22 上午09:54:46
     * 
     * Author:lanjh
     * 
     * Version: V1.0
     * 
     * Description:對進行修改的功能進行描述
     * 
     * 
     
    */

    public class InfoDaoImpl extends CreditDAO implements InfoDao {

        
    private Log log;

        
    public InfoDaoImpl() {
            log 
    = LogFactory.getLog(InfoDaoImpl.class);
        }

        
    public void addip(Stat stat) {
            
    this.getSession().save(stat);
        }

        
    public int count(ResultFilter resultfilter) {
            
    // TODO Auto-generated method stub
            return getResultCount(com.strongit.credit.common.po.InfoWrapper.class,
                    resultfilter);
        }

        
    public void delete(Info info) {
    //        this.getHibernateTemplate().delete(info);
            Transaction tx = this.getSession().beginTransaction();
            
    this.getSession().delete(info);
            tx.commit();
        }

        
    public Info findInfoById(Long long1) {
            
    return loadInfo(com.strongit.credit.common.po.InfoWrapper.class, long1);
        }

        
    public Subject findSubjectById(String s) {
            
    return (Subject) this.getSession().get(
                    com.strongit.credit.common.po.Subject.
    class, s);
        }

        
    public List getInfos(ResultFilter resultfilter) {
            
    return getResults(com.strongit.credit.common.po.InfoWrapper.class,
                    resultfilter);
        }

        
    public List getStat() {
            String hql 
    = "";
            hql 
    = "select sum(decode(t.comedate,null,0,1)) AS TOTAL, sum(decode(to_char(t.comedate,'yyyy-mm') ,to_char(ADD_MONTHS(SYSDATE,-1),'yyyy-mm'),1,0)) AS LASTMONTH, sum(decode(to_char(t.comedate,'yyyy-mm') ,to_char(ADD_MONTHS(SYSDATE,0),'yyyy-mm'),1,0)) AS THISMONTH, sum(decode(to_char(t.comedate,'yyyy-mm-dd') ,to_char(SYSDATE-1,'yyyy-mm-dd'),1,0)) AS YESTERDAY, sum(decode(to_char(t.comedate,'yyyy-mm-dd') ,to_char(SYSDATE,'yyyy-mm-dd'),1,0)) AS TODAY from STAT t ";
            SQLQuery query 
    = this.getSession().createSQLQuery(hql);
            
    return query.list();
        }

        
    public List getSubjects(ResultFilter resultfilter) {
            
    return getResults(com.strongit.credit.common.po.Subject.class,
                    resultfilter);
        }

        
    public void insert(Info info) {

            Session ssesion 
    = this.getSession();    
            Transaction ts 
    = ssesion.beginTransaction();    

            info.setContentClob(Hibernate.createClob(
    " "));    
            ssesion.save(info);
            ssesion.flush();
            ssesion.refresh(info,LockMode.UPGRADE);    
            SerializableClob clob
    =(SerializableClob)info.getContentClob();     
            java.sql.Clob wrapClob 
    = clob.getWrappedClob();     
            CLOB tmpClob
    =(CLOB)wrapClob;     
            Writer wt;
            
    try {
                wt 
    = tmpClob.getCharacterOutputStream();
                String content 
    = info.getContent();
                wt.write(content);

                wt.close();
                ts.commit();
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
        }

        
    public void update(Info info) {
    //        Session ssesion = this.getSession();    
    //        Transaction ts = ssesion.beginTransaction();
    //        info = (Info)ssesion.load(Info.class,info.getId(),LockMode.UPGRADE); 
    //
    //        info.setContent(info.getContent());
    //        info.setContentClob(Hibernate.createClob(" "));
    //        ssesion.update(info);
    //        ssesion.flush();
    //        ssesion.refresh(info,LockMode.UPGRADE);
    //        SerializableClob clob=(SerializableClob)info.getContentClob();
    //        java.sql.Clob wrapClob = clob.getWrappedClob();     
    //        CLOB tmpClob=(CLOB)wrapClob;
    //        Writer wt;
    //        try {
    //            wt = tmpClob.setCharacterStream(0);
    //            String content = info.getContent();
    //            wt.write(content);
    //            wt.close();
    //            ts.commit();
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //        }
            this.delete(info);
            
    this.insert(info);
        }
        
        
    public void saveOrUpdate(Info info)
        {
            Session s;
            BufferedWriter writer;
            s 
    = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
            writer 
    = null;
            
    try
            {
                Class clazz 
    = Info.class;
                Method m 
    = null;
                String clobValue 
    = null;
                clobValue 
    = info.getContent();
                m 
    = clazz.getDeclaredMethod("setContentClob"new Class[] {
                    java.sql.Clob.
    class
                });
                m.setAccessible(
    true);
                
    if(clobValue == null || clobValue.length() == 0)
                    m.invoke(info, 
    new Object[] {
                        Hibernate.createClob(
    "")
                    });
                
    else
                    m.invoke(info, 
    new Object[] {
                        Hibernate.createClob(
    " ")
                    });

                s.saveOrUpdate(info);
                
    if(clobValue != null && clobValue.length() > 0)
                {
                    s.flush();
                    s.refresh(info, LockMode.UPGRADE);
                    CLOB clob 
    = null;
                    m 
    = clazz.getDeclaredMethod("getContentClob"null);
                    m.setAccessible(
    true);
                    Object obj 
    = m.invoke(info, null);
                    
    if(obj instanceof SerializableClob)
                        clob 
    = (CLOB)((SerializableClob)obj).getWrappedClob();
                    
    if(clob != null)
                    {
                        writer 
    = new BufferedWriter(clob.getCharacterOutputStream());
                        writer.write(clobValue);
                    }
                }
            }
            
    catch(Exception e)
            {
                StringBuilder sb 
    = new StringBuilder();
                sb.append(
    "\u6301\u4E45\u5316POJO\u65F6\u51FA\u73B0\u9519\u8BEF\uFF0C\u7C7B ").append(info.getClass().getName()).append("\u3002").append(e.getMessage());
                log.error(sb.toString());
            }  
            
            
    if(writer != null)
                
    try
                {
                    writer.close();
                }
                
    catch(IOException e)
                {
                    log.error(e.getMessage());
                }
            
    return;
        }


        
    public Info loadInfo(Class clazz, Serializable id) {
            Object pojo;
            Info info;
            BufferedReader reader;
            pojo 
    = this.getSession().get(clazz, id);
            info 
    = (Info) pojo;
            
    if (pojo == null || !(pojo instanceof Info)) {
                
    this.getSession().refresh(pojo, LockMode.READ);
            }
            reader 
    = null;
            
    try {
                Class c 
    = com.strongit.credit.common.po.Info.class;
                Method m 
    = c.getDeclaredMethod("getContentClob"null);
                m.setAccessible(
    true);
                Object result 
    = m.invoke(pojo, null);
                
    if (result != null) {
                    reader 
    = new BufferedReader(((Clob) result)
                            .getCharacterStream());
                    StringBuilder sb 
    = new StringBuilder();
                    
    for (String line = null; (line = reader.readLine()) != null;)
                        sb.append(line);

                    
    if (sb.length() > 0)
                        info.setContent(sb.toString());
                }
            } 
    catch (Exception e) {
                StringBuilder sb 
    = new StringBuilder();
                sb
                        .append(
                                
    "\u52A0\u8F7DPOJO\u65F6\u51FA\u73B0\u9519\u8BEF\uFF0C\u7C7B ")
                        .append(clazz.getName()).append(
    "\u3002").append(
                                e.getMessage());
                log.error(sb.toString());
            }

            
    if (reader != null)
                
    try {
                    reader.close();
                } 
    catch (IOException e) {
                    log.error(e.getMessage());
                }
            
    return info;
        }

    }

    posted on 2008-09-25 08:41 lanjh 閱讀(964) 評論(0)  編輯  收藏 所屬分類: Java Web

    主站蜘蛛池模板: 久别的草原电视剧免费观看| 一级成人a做片免费| 久久国产高潮流白浆免费观看| 亚洲国产精品综合久久网络 | 久久久亚洲精品无码| 国产成人精品免费大全| 亚洲精品无码永久中文字幕| 爽爽爽爽爽爽爽成人免费观看| 中文字幕亚洲天堂| 野花香高清在线观看视频播放免费 | 亚洲日本一线产区和二线产区对比| 福利免费观看午夜体检区| 亚洲日韩中文字幕无码一区| 女人被弄到高潮的免费视频| 国产青草亚洲香蕉精品久久| 亚洲日本中文字幕一区二区三区| 成人A片产无码免费视频在线观看| 亚洲成熟xxxxx电影| 亚洲一级毛片免费看| 亚洲七久久之综合七久久| 免费**毛片在线播放直播| 国产精品偷伦视频免费观看了| 亚洲成人精品久久| 暖暖日本免费在线视频| 亚洲精品视频免费观看| 久久久久亚洲AV无码专区体验| 毛片免费在线视频| fc2免费人成为视频| 亚洲黄色免费电影| 永久免费毛片手机版在线看| 一本大道一卡二大卡三卡免费 | 免费可以看黄的视频s色| 国产精品亚洲色图| 亚洲国产二区三区久久| 全免费a级毛片免费看无码| 久久不见久久见免费影院www日本 久久WWW免费人成—看片 | 日韩va亚洲va欧洲va国产| 免费下载成人电影| 成全视成人免费观看在线看| 亚洲一级高清在线中文字幕| 亚洲精品和日本精品|