⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binaryblobtype.java

📁 J2EE架构的权限系统
💻 JAVA
字号:
/*
 * 创建日期 2005-8-30
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package org.infosys.util;

/**
 * @author Administrator
 * oracle blob转为image类型
 */
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Types; 
import java.sql.Blob; 

import net.sf.hibernate.Hibernate; 
import net.sf.hibernate.HibernateException; 
import net.sf.hibernate.UserType; 

public class BinaryBlobType implements UserType { 
  public int[] sqlTypes(){ 
    return new int[] { Types.BLOB }; 
  }

  public Class returnedClass(){ 
    return byte[].class; 
  } 

  public boolean equals(Object x, Object y){ 
    return (x == y) 
      || (x != null 
        && y != null 
        && java.util.Arrays.equals((byte[]) x, (byte[]) y)); 
  } 

  public Object nullSafeGet(ResultSet rs, String[] names, Object owner) 
  throws HibernateException, SQLException { 
    Blob blob = rs.getBlob(names[0]); 
    return blob.getBytes(1, (int) blob.length()); 
  } 

  public void nullSafeSet(PreparedStatement st, Object value, int index) 
  throws HibernateException, SQLException { 
    st.setBlob(index, Hibernate.createBlob((byte[]) value)); 
  } 

  public Object deepCopy(Object value){ 
    if (value == null) return null; 

    byte[] bytes = (byte[]) value; 
    byte[] result = new byte[bytes.length]; 
    System.arraycopy(bytes, 0, result, 0, bytes.length); 

    return result; 
  } 

  public boolean isMutable(){ 
    return true; 
  } 

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -