<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 閱讀(965) 評論(0)  編輯  收藏 所屬分類: Java Web

    主站蜘蛛池模板: 亚洲熟妇AV一区二区三区宅男| 亚洲AV无码久久寂寞少妇| 亚洲成a人片在线观看中文app| 国产色无码精品视频免费| 久久精品国产亚洲Aⅴ香蕉| 免费一级全黄少妇性色生活片| 四虎永久免费地址在线观看| 亚洲av日韩专区在线观看| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 国产A在亚洲线播放| 三级黄色免费观看| 亚洲av无码精品网站| 亚洲一区二区在线免费观看| 91亚洲国产成人久久精品网站| 久久精品国产免费观看三人同眠| 亚洲视频一区在线观看| 99无码人妻一区二区三区免费 | 免费萌白酱国产一区二区三区| 亚洲精品狼友在线播放| 久久免费视频精品| 亚洲va成无码人在线观看| 最近免费中文字幕大全视频 | 国产又大又黑又粗免费视频 | yy6080久久亚洲精品| 亚洲黄色在线视频| 天天干在线免费视频| 一区二区免费国产在线观看| 亚洲日韩精品一区二区三区 | 精品成人一区二区三区免费视频| 久久久久噜噜噜亚洲熟女综合| 毛片免费在线观看| 久久久久久亚洲精品影院| 国产精品va无码免费麻豆| 中文字幕免费播放| 国产精品久久亚洲不卡动漫| 国产jizzjizz免费看jizz| 成人免费ā片在线观看| 亚洲AV无码乱码麻豆精品国产| 国产a级特黄的片子视频免费| 久久aa毛片免费播放嗯啊| 亚洲成aⅴ人片久青草影院按摩|