1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.sql.PreparedStatement ; 6 import java.sql.ResultSet ; 7 import java.sql.SQLException ; 8 import java.sql.Types ; 9 10 import org.hibernate.MappingException; 11 12 16 public class CharacterType extends PrimitiveType implements DiscriminatorType { 17 18 public Serializable getDefaultValue() { 19 throw new UnsupportedOperationException ("not a valid id type"); 20 } 21 22 public Object get(ResultSet rs, String name) throws SQLException { 23 String str = rs.getString(name); 24 if (str==null) { 25 return null; 26 } 27 else { 28 return new Character ( str.charAt(0) ); 29 } 30 } 31 32 public Class getPrimitiveClass() { 33 return char.class; 34 } 35 36 public Class getReturnedClass() { 37 return Character .class; 38 } 39 40 public void set(PreparedStatement st, Object value, int index) throws SQLException { 41 st.setString( index, (value).toString() ); 42 } 43 44 public int sqlType() { 45 return Types.CHAR; 46 } 47 public String getName() { return "character"; } 48 49 public String objectToSQLString(Object value) throws Exception { 50 return '\'' + value.toString() + '\''; 51 } 52 53 public Object stringToObject(String xml) throws Exception { 54 if ( xml.length() != 1 ) throw new MappingException("multiple or zero characters found parsing string"); 55 return new Character ( xml.charAt(0) ); 56 } 57 58 public Object fromStringValue(String xml) { 59 return new Character ( xml.charAt(0) ); 60 } 61 62 } 63 64 65 66 67 68 | Popular Tags |