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.math.BigDecimal ; 37 import java.sql.PreparedStatement ; 38 import java.sql.ResultSet ; 39 import java.sql.SQLException ; 40 import java.sql.Types ; 41 42 45 public class BigDecimalType extends Type { 46 private static final L10N L = new L10N(BigDecimalType.class); 47 48 private int _scale = -1; 49 50 private BigDecimalType() 51 { 52 } 53 54 57 public static BigDecimalType create() 58 { 59 return new BigDecimalType(); 60 } 61 62 65 public String getName() 66 { 67 return "java.math.BigDecimal"; 68 } 69 70 73 public boolean isNumeric() 74 { 75 return true; 76 } 77 78 81 public int generateLoad(JavaWriter out, String rs, 82 String indexVar, int index) 83 throws IOException 84 { 85 out.print(rs + ".getBigDecimal(" + indexVar + " + " + index + ")"); 86 87 return index + 1; 88 } 89 90 93 public void generateSet(JavaWriter out, String pstmt, 94 String index, String value) 95 throws IOException 96 { 97 out.println("if (" + value + " == null)"); 98 out.println(" " + pstmt + ".setNull(" + index + "++, java.sql.Types.DECIMAL);"); 99 out.println("else"); 100 out.println(" " + pstmt + ".setBigDecimal(" + index + "++, " + value + ");"); 101 } 102 103 106 public void setParameter(PreparedStatement pstmt, int index, Object value) 107 throws SQLException 108 { 109 pstmt.setBigDecimal(index, (BigDecimal ) value); 110 } 111 112 115 public Object getObject(ResultSet rs, int index) 116 throws SQLException 117 { 118 return rs.getBigDecimal(index); 119 } 120 121 public String generateCreateColumnSQL(AmberPersistenceUnit manager, int length, int precision, int scale) 122 { 123 return manager.getCreateColumnSQL(Types.NUMERIC, length, precision, scale); 124 } 125 } 126 | Popular Tags |