1 29 30 package com.caucho.amber.type; 31 32 import com.caucho.amber.manager.AmberPersistenceUnit; 33 import com.caucho.java.JavaWriter; 34 import com.caucho.util.L10N; 35 36 import java.io.IOException ; 37 import java.sql.ResultSet ; 38 import java.sql.SQLException ; 39 import java.sql.Types ; 40 41 44 public class CharacterType extends Type { 45 private static final L10N L = new L10N(CharacterType.class); 46 47 private static final CharacterType CHAR_TYPE = new CharacterType(); 48 49 private CharacterType() 50 { 51 } 52 53 56 public static CharacterType create() 57 { 58 return CHAR_TYPE; 59 } 60 61 64 public String getName() 65 { 66 return "java.lang.Character"; 67 } 68 69 72 public String generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale) 73 { 74 return manager.getCreateColumnSQL(Types.CHAR, 0, precision, scale); 75 } 76 77 80 public int generateLoad(JavaWriter out, String rs, 81 String indexVar, int index) 82 throws IOException 83 { 84 out.print("com.caucho.amber.type.CharacterType.toChar(" + rs + ".getString(" + indexVar + " + " + index + "))"); 85 86 return index + 1; 87 } 88 89 92 public void generateSet(JavaWriter out, String pstmt, 93 String index, String value) 94 throws IOException 95 { 96 out.println("if (" + value + " == null)"); 97 out.println(" " + pstmt + ".setNull(" + index + "++, java.sql.Types.CHAR);"); 98 out.println("else"); 99 out.println(" " + pstmt + ".setString(" + index + "++, String.valueOf(" + value + "));"); 100 } 101 102 105 public void generateSetNull(JavaWriter out, String pstmt, String index) 106 throws IOException 107 { 108 out.println(pstmt + ".setNull(" + index + "++, java.sql.Types.CHAR);"); 109 } 110 111 114 public static Character toChar(String value) 115 { 116 if (value == null || value.length() == 0) 117 return null; 118 else 119 return new Character (value.charAt(0)); 120 } 121 122 125 public Object getObject(ResultSet rs, int index) 126 throws SQLException 127 { 128 String value = rs.getString(index); 129 130 return (value == null || value.length() == 0) ? null : new Character (value.charAt(0)); 131 } 132 } 133 | Popular Tags |