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 PrimitiveFloatType extends PrimitiveType { 44 private static final L10N L = new L10N(PrimitiveFloatType.class); 45 46 private static final PrimitiveFloatType FLOAT_TYPE = new PrimitiveFloatType(); 47 48 private PrimitiveFloatType() 49 { 50 } 51 52 55 public static PrimitiveFloatType create() 56 { 57 return FLOAT_TYPE; 58 } 59 60 63 public String getName() 64 { 65 return "float"; 66 } 67 68 71 public boolean isNumeric() 72 { 73 return true; 74 } 75 76 79 public Type getForeignType() 80 { 81 return FloatType.create(); 82 } 83 84 87 public String generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale) 88 { 89 return manager.getCreateColumnSQL(Types.REAL, length, precision, scale); 90 } 91 92 95 public int generateLoad(JavaWriter out, String rs, 96 String indexVar, int index) 97 throws IOException 98 { 99 out.print(rs + ".getFloat(" + indexVar + " + " + index + ")"); 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(pstmt + ".setFloat(" + index + "++, " + value + ");"); 112 } 113 114 117 public void generateSetNull(JavaWriter out, String pstmt, String index) 118 throws IOException 119 { 120 out.println(pstmt + ".setNull(" + index + "++, java.sql.Types.REAL);"); 121 } 122 123 126 public String toObject(String value) 127 { 128 return "new Float(" + value + ")"; 129 } 130 131 134 public String generateCastFromObject(String value) 135 { 136 return "((Number) " + value + ").floatValue()"; 137 } 138 139 142 public void setParameter(PreparedStatement pstmt, int index, Object value) 143 throws SQLException 144 { 145 if (value instanceof Number ) pstmt.setString(index, value.toString()); 147 else 148 throw new IllegalArgumentException ("Invalid argument for setParameter."); 149 } 150 } 151 | Popular Tags |