1 28 29 package com.caucho.amber.type; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.util.L10N; 33 34 import java.io.IOException ; 35 import java.sql.PreparedStatement ; 36 import java.sql.ResultSet ; 37 import java.sql.SQLException ; 38 39 42 public class CharacterArrayType extends ArrayType { 43 private static final L10N L = new L10N(CharacterArrayType.class); 44 45 private CharacterArrayType() 46 { 47 } 48 49 52 public static CharacterArrayType create() 53 { 54 return new CharacterArrayType(); 55 } 56 57 60 public String getName() 61 { 62 return "java.lang.Character[]"; 63 } 64 65 68 public String getJavaTypeName() 69 { 70 return "java.lang.Character[]"; 71 } 72 73 76 public String getJavaObjectTypeName() 77 { 78 return "java.lang.Character"; 79 } 80 81 85 public String getPrimitiveArrayTypeName() 86 { 87 return "char[]"; 88 } 89 90 93 public int generateLoad(JavaWriter out, String rs, 94 String indexVar, int index) 95 throws IOException 96 { 97 out.print(rs + ".getString(" + indexVar + " + " + index + ")"); 98 out.print(" == null || " + rs + ".wasNull() ? null : "); 99 out.print(rs + ".getString(" + indexVar + " + " + index + ").toCharArray()"); 100 101 return index + 1; 102 } 103 104 107 public void generateSet(JavaWriter out, String pstmt, 108 String index, String value) 109 throws IOException 110 { 111 out.println("if (" + value + " == null)"); 112 out.println(" " + pstmt + ".setNull(" + index + "++, java.sql.Types.CHAR);"); 113 out.println("else {"); 114 out.println(" java.lang.Character[] super_temp_" + index + " = " + value + ";"); 115 out.println(" char[] temp_" + index + " = new char[super_temp_" + index + ".length];"); 116 out.println(" for (int i=0; i < temp_" + index + ".length; i++)"); 117 out.println(" temp_" + index + "[i] = super_temp_" + index + "[i].charValue();"); 118 out.println(" " + pstmt + ".setString(" + index + "++, new String(temp_" + index + "));"); 119 out.println("}"); 120 } 121 122 125 public void setParameter(PreparedStatement pstmt, int index, Object value) 126 throws SQLException 127 { 128 Character [] wrapperCharacter = (Character []) value; 129 130 char[] primitiveCharacter = new char[wrapperCharacter.length]; 131 for (int i=0; i<wrapperCharacter.length; i++) 132 primitiveCharacter[i] = wrapperCharacter[i].charValue(); 133 134 pstmt.setString(index, new String (primitiveCharacter)); 135 } 136 137 140 public Object getObject(ResultSet rs, int index) 141 throws SQLException 142 { 143 char[] primitiveCharacter = rs.getString(index).toCharArray(); 144 145 if (rs.wasNull()) 146 return null; 147 148 Character [] wrapperCharacter = new Character [primitiveCharacter.length]; 149 for (int i=0; i < primitiveCharacter.length; i++) 150 wrapperCharacter[i] = new Character (primitiveCharacter[i]); 151 152 return wrapperCharacter; 153 } 154 } 155 | Popular Tags |