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 PrimitiveCharArrayType extends Type { 43 private static final L10N L = new L10N(PrimitiveCharArrayType.class); 44 45 private PrimitiveCharArrayType() 46 { 47 } 48 49 52 public static PrimitiveCharArrayType create() 53 { 54 return new PrimitiveCharArrayType(); 55 } 56 57 60 public String getName() 61 { 62 return "char[]"; 63 } 64 65 68 public String getJavaTypeName() 69 { 70 return "char[]"; 71 } 72 73 76 public int generateLoad(JavaWriter out, String rs, 77 String indexVar, int index) 78 throws IOException 79 { 80 out.print(rs + ".getString(" + indexVar + " + " + index + ")"); 81 out.print(" == null || " + rs + ".wasNull() ? null : "); 82 out.print(rs + ".getString(" + indexVar + " + " + index + ").toCharArray()"); 83 84 return index + 1; 85 } 86 87 90 public void generateSet(JavaWriter out, String pstmt, 91 String index, String value) 92 throws IOException 93 { 94 out.println("if (" + value + " == null)"); 95 out.println(" " + pstmt + ".setNull(" + index + "++, java.sql.Types.CHAR);"); 96 out.println("else"); 97 out.println(" " + pstmt + ".setString(" + index + "++, new String(" + value + "));"); 98 } 99 100 103 public void setParameter(PreparedStatement pstmt, int index, Object value) 104 throws SQLException 105 { 106 if (value == null) 107 pstmt.setNull(index, java.sql.Types.CHAR); 108 else 109 pstmt.setString(index, new String ((char []) value)); 110 } 111 112 115 public Object getObject(ResultSet rs, int index) 116 throws SQLException 117 { 118 String s = rs.getString(index); 119 120 if (rs.wasNull()) 121 return null; 122 123 return s.toCharArray(); 124 } 125 } 126 | Popular Tags |