1 17 18 26 package org.pentaho.repository.usertypes; 27 28 import java.io.Serializable ; 29 import java.io.StringReader ; 30 import java.sql.PreparedStatement ; 31 import java.sql.ResultSet ; 32 import java.sql.SQLException ; 33 import java.sql.Types ; 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 import org.hibernate.HibernateException; 37 import org.hibernate.usertype.UserType; 38 import org.pentaho.core.system.PentahoSystem; 39 import org.pentaho.messages.Messages; 40 41 public class LongStringUserType implements UserType { 42 private static Log log = LogFactory.getLog(LongStringUserType.class); 43 44 private final static boolean debug = PentahoSystem.debug; 45 46 private static final int[] SQLTYPE = { Types.CLOB }; 48 53 public int[] sqlTypes() { 54 return SQLTYPE; 55 } 56 57 62 public Class returnedClass() { 63 return StringBuffer .class; 64 } 65 66 72 public boolean equals(Object x, Object y) throws HibernateException { 73 if (x == y) { 74 return true; 75 } 76 if ((x == null) || (y == null) || (!(x instanceof StringBuffer )) || (!(y instanceof StringBuffer ))) { 77 return false; 78 } 79 return x.toString().equals(y.toString()); 80 } 81 82 87 public int hashCode(Object x) throws HibernateException { 88 return x.hashCode(); 89 } 90 91 97 public Object nullSafeGet(ResultSet rs, String [] names, Object owner) throws HibernateException, SQLException { 98 if (debug) 99 log.debug(Messages.getString("LONGSTRTYPE.DEBUG_NULL_SAFE_GET")); String longStr = rs.getString(names[0]); 101 return (longStr != null) ? new StringBuffer (longStr) : null; 102 } 103 104 110 public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { 111 if (debug) 112 log.debug(Messages.getString("LONGSTRTYPE.DEBUG_NULL_SAFE_SET")); if (value != null) { 114 StringReader rdr = new StringReader (value.toString()); 115 int sLen = ((StringBuffer ) value).length(); 116 st.setCharacterStream(index, rdr, sLen); 117 } else { 118 st.setNull(index, SQLTYPE[0]); 119 } 120 } 121 122 127 public Object deepCopy(Object value) throws HibernateException { 128 return new StringBuffer (value.toString()); 129 } 130 131 136 public boolean isMutable() { 137 return false; 138 } 139 140 145 public Serializable disassemble(Object value) throws HibernateException { 146 return (Serializable ) value; 147 } 148 149 155 public Object assemble(Serializable cached, Object owner) throws HibernateException { 156 return cached; 157 } 158 159 165 public Object replace(Object original, Object target, Object owner) throws HibernateException { 166 return original; 167 } 168 } 169 | Popular Tags |