1 17 package org.alfresco.repo.domain.hibernate; 18 19 import java.io.Serializable ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.Types ; 24 25 import org.alfresco.service.namespace.QName; 26 import org.alfresco.util.EqualsHelper; 27 import org.hibernate.HibernateException; 28 import org.hibernate.usertype.UserType; 29 30 36 public class QNameUserType implements UserType 37 { 38 private static int[] SQL_TYPES = new int[] {Types.VARCHAR}; 39 40 public Class returnedClass() 41 { 42 return QName.class; 43 } 44 45 48 public int[] sqlTypes() 49 { 50 return SQL_TYPES; 51 } 52 53 public boolean isMutable() 54 { 55 return false; 56 } 57 58 public boolean equals(Object x, Object y) throws HibernateException 59 { 60 return EqualsHelper.nullSafeEquals(x, y); 61 } 62 63 public int hashCode(Object x) throws HibernateException 64 { 65 return x.hashCode(); 66 } 67 68 public Object deepCopy(Object value) throws HibernateException 69 { 70 return value; 72 } 73 74 public Object nullSafeGet(ResultSet rs, String [] names, Object owner) throws HibernateException, SQLException 75 { 76 String qnameStr = rs.getString(names[0]); 77 if (qnameStr == null) 78 { 79 return null; 80 } 81 else 82 { 83 QName qname = QName.createQName(qnameStr); 84 return qname; 85 } 86 } 87 88 public void nullSafeSet(PreparedStatement stmt, Object value, int index) throws HibernateException, SQLException 89 { 90 stmt.setString(index, value.toString()); 92 } 93 94 public Object replace(Object original, Object target, Object owner) throws HibernateException 95 { 96 return original; 98 } 99 100 public Object assemble(Serializable cached, Object owner) throws HibernateException 101 { 102 return cached; 104 } 105 106 public Serializable disassemble(Object value) throws HibernateException 107 { 108 return (QName) value; 110 } 111 } 112 | Popular Tags |