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 PrimitiveByteArrayType extends Type { 43 private static final L10N L = new L10N(PrimitiveByteArrayType.class); 44 45 private PrimitiveByteArrayType() 46 { 47 } 48 49 52 public static PrimitiveByteArrayType create() 53 { 54 return new PrimitiveByteArrayType(); 55 } 56 57 60 public String getName() 61 { 62 return "byte[]"; 63 } 64 65 68 public String getJavaTypeName() 69 { 70 return "byte[]"; 71 } 72 73 76 public int generateLoad(JavaWriter out, String rs, 77 String indexVar, int index) 78 throws IOException 79 { 80 out.print(rs + ".getBytes(" + indexVar + " + " + index + ")"); 81 82 return index + 1; 83 } 84 85 88 public void generateSet(JavaWriter out, String pstmt, 89 String index, String value) 90 throws IOException 91 { 92 out.println("if (" + value + " == null)"); 93 out.println(" " + pstmt + ".setNull(" + index + "++, java.sql.Types.LONGVARBINARY);"); 94 out.println("else"); 95 out.println(" " + pstmt + ".setBytes(" + index + "++, " + value + ");"); 96 } 97 98 101 public void setParameter(PreparedStatement pstmt, int index, Object value) 102 throws SQLException 103 { 104 pstmt.setBytes(index, (byte []) value); 105 } 106 107 110 public Object getObject(ResultSet rs, int index) 111 throws SQLException 112 { 113 return rs.getBytes(index); 114 } 115 } 116 | Popular Tags |