1 28 29 package com.caucho.amber.type; 30 31 import com.caucho.amber.manager.AmberPersistenceUnit; 32 import com.caucho.java.JavaWriter; 33 import com.caucho.util.L10N; 34 35 import java.io.IOException ; 36 import java.sql.PreparedStatement ; 37 import java.sql.SQLException ; 38 import java.sql.Types ; 39 40 43 public class PrimitiveByteType extends PrimitiveType { 44 private static final L10N L = new L10N(PrimitiveByteType.class); 45 46 private static final PrimitiveByteType BYTE_TYPE = 47 new PrimitiveByteType(); 48 49 private PrimitiveByteType() 50 { 51 } 52 53 56 public static PrimitiveByteType create() 57 { 58 return BYTE_TYPE; 59 } 60 61 64 public String getName() 65 { 66 return "byte"; 67 } 68 69 72 public boolean isNumeric() 73 { 74 return true; 75 } 76 77 80 public Type getForeignType() 81 { 82 return ByteType.create(); 83 } 84 85 88 public String generateCreateColumnSQL(AmberPersistenceUnit manager, 89 int length, 90 int precision, 91 int scale) 92 { 93 return manager.getCreateColumnSQL(Types.TINYINT, length, precision, scale); 94 } 95 96 99 public int generateLoad(JavaWriter out, String rs, 100 String indexVar, int index) 101 throws IOException 102 { 103 out.print(rs + ".getByte(" + indexVar + " + " + index + ")"); 104 105 return index + 1; 106 } 107 108 111 public void generateSet(JavaWriter out, String pstmt, 112 String index, String value) 113 throws IOException 114 { 115 out.println(pstmt + ".setByte(" + index + "++, " + value + ");"); 116 } 117 118 121 public void generateSetNull(JavaWriter out, String pstmt, String index) 122 throws IOException 123 { 124 out.println(pstmt + ".setNull(" + index + "++, java.sql.Types.TINYINT);"); 125 } 126 127 130 public String toObject(String value) 131 { 132 return "new Byte(" + value + ")"; 133 } 134 135 138 public String generateCastFromObject(String value) 139 { 140 return "((Number) " + value + ").byteValue()"; 141 } 142 143 146 public void setParameter(PreparedStatement pstmt, int index, Object value) 147 throws SQLException 148 { 149 if (value instanceof Number ) 150 pstmt.setString(index, value.toString()); 151 else 152 throw new IllegalArgumentException ("Invalid argument for setParameter."); 153 } 154 } 155 | Popular Tags |