1 10 11 package com.triactive.jdo.store; 12 13 import com.triactive.jdo.PersistenceManager; 14 import java.sql.PreparedStatement ; 15 import java.sql.ResultSet ; 16 import java.sql.SQLException ; 17 import java.sql.Types ; 18 import javax.jdo.JDODataStoreException; 19 20 21 public class CharacterMapping extends ColumnMapping 22 { 23 public CharacterMapping(DatabaseAdapter dba, Class type) 24 { 25 super(dba, type); 26 27 initTypeInfo(); 28 } 29 30 public CharacterMapping(Column col) 31 { 32 super(col); 33 34 col.setFixedLength(1); 35 col.checkString(); 36 37 initTypeInfo(); 38 } 39 40 public CharacterMapping(ClassBaseTable table, int relativeFieldNumber) 41 { 42 this(table.newColumn(relativeFieldNumber)); 43 } 44 45 protected TypeInfo getTypeInfo() 46 { 47 return dba.getTypeInfo(Types.CHAR); 48 } 49 50 public void setChar(PersistenceManager pm, PreparedStatement ps, int param, char value) 51 { 52 try 53 { 54 ps.setString(param, new Character (value).toString()); 55 } 56 catch (SQLException e) 57 { 58 throw dba.newDataStoreException("Can't set char parameter: value = " + value, e); 59 } 60 } 61 62 public char getChar(PersistenceManager pm, ResultSet rs, int param) 63 { 64 char value; 65 66 try 67 { 68 String s = rs.getString(param); 69 70 if (rs.wasNull()) 71 throw new NullValueException("Illegal null value in column " + col); 72 73 value = s.length() == 0 ? '\000' : s.charAt(0); 74 } 75 catch (SQLException e) 76 { 77 throw dba.newDataStoreException("Can't get char result: param = " + param, e); 78 } 79 80 return value; 81 } 82 83 public void setObject(PersistenceManager pm, PreparedStatement ps, int param, Object value) 84 { 85 try 86 { 87 if (value == null) 88 ps.setNull(param, typeInfo.dataType); 89 else 90 ps.setString(param, ((Character )value).toString()); 91 } 92 catch (SQLException e) 93 { 94 throw dba.newDataStoreException("Can't set Character parameter: value = " + value, e); 95 } 96 } 97 98 public Object getObject(PersistenceManager pm, ResultSet rs, int param) 99 { 100 Object value; 101 102 try 103 { 104 String s = rs.getString(param); 105 value = rs.wasNull() ? null : new Character (s.length() == 0 ? '\000' : s.charAt(0)); 106 } 107 catch (SQLException e) 108 { 109 throw dba.newDataStoreException("Can't get Character result: param = " + param, e); 110 } 111 112 return value; 113 } 114 115 public SQLExpression newSQLLiteral(QueryStatement qs, Object value) 116 { 117 return new CharacterLiteral(qs, ((Character )value).toString()); 118 } 119 120 public SQLExpression newSQLExpression(QueryStatement qs, QueryStatement.QueryColumn qsc, String fieldName) 121 { 122 return new CharacterExpression(qs, qsc); 123 } 124 } 125 | Popular Tags |