1 17 18 package org.pentaho.repository.usertypes; 19 20 import java.io.Serializable ; 21 import java.sql.PreparedStatement ; 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.sql.Types ; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.hibernate.Hibernate; 28 import org.hibernate.HibernateException; 29 import org.hibernate.usertype.UserType; 30 import org.hibernate.util.EqualsHelper; 31 import org.pentaho.core.system.PentahoSystem; 32 import org.pentaho.messages.Messages; 33 34 public class EmptyStringUserType implements UserType { 35 private static Log log = LogFactory.getLog(EmptyStringUserType.class); 36 37 private final static boolean debug = PentahoSystem.debug; 38 39 private static final String PENTAHOEMPTY = Messages.getString("EMPTYSTRTYPE.CODE_PENTAHO_EMPTY_STRING"); 41 private static final int[] SQLTYPE = { Types.VARCHAR }; 42 43 48 public int[] sqlTypes() { 49 return SQLTYPE; 50 } 51 52 57 public Class returnedClass() { 58 return String .class; 59 } 60 61 67 public boolean equals(Object arg0, Object arg1) throws HibernateException { 68 return EqualsHelper.equals(arg0, arg1); 69 } 70 71 76 public int hashCode(Object arg0) throws HibernateException { 77 return arg0.hashCode(); 78 } 79 80 86 public Object nullSafeGet(ResultSet arg0, String [] arg1, Object arg2) throws HibernateException, SQLException { 87 if (debug) 88 log.debug(Messages.getString("EMPTYSTRTYPE.DEBUG_NULL_SAFE_GET")); String colValue = (String ) Hibernate.STRING.nullSafeGet(arg0, arg1[0]); 90 return ((colValue != null) ? (colValue.equals(PENTAHOEMPTY) ? "" : colValue) : null); } 95 96 102 public void nullSafeSet(PreparedStatement arg0, Object arg1, int arg2) throws HibernateException, SQLException { 103 if (debug) 105 log.debug(Messages.getString("EMPTYSTRTYPE.DEBUG_NULL_SAFE_SET")); Hibernate.STRING.nullSafeSet(arg0, (arg1 != null) ? ((((String ) arg1).length() > 0) ? arg1 : PENTAHOEMPTY) : arg1, arg2); 107 } 108 109 114 public Object deepCopy(Object arg0) throws HibernateException { 115 return arg0; 116 } 117 118 123 public boolean isMutable() { 124 return false; 125 } 126 127 132 public Serializable disassemble(Object arg0) throws HibernateException { 133 return (Serializable ) arg0; 134 } 135 136 142 public Object assemble(Serializable arg0, Object arg1) throws HibernateException { 143 return arg0; 144 } 145 146 152 public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException { 153 return arg0; 154 } 155 156 } 157 | Popular Tags |