1 23 package com.lutris.dods.builder.generator.query; 24 25 import java.math.BigDecimal ; 26 27 38 public class RDBColumnValue extends RDBColumn { 39 40 51 public RDBColumnValue(RDBColumn column, Object val) { 52 super(column.table, column.name); 53 value = val; 54 } 55 private Object value; 56 57 66 public Object getValue() { 67 return value; 68 } 69 70 77 public void setValue(Object o) { 78 value = o; 79 } 80 81 90 public String getString() 91 throws ColumnTypeException { 92 if (!(value instanceof String )) { 93 throw new ColumnTypeException(this, "String"); 94 } 95 return (String ) value; 96 } 97 98 111 public int getInteger(boolean nullOk) 112 throws ColumnTypeException, ColumnNullException { 113 if (!(value instanceof Integer )) { 114 throw new ColumnTypeException(this, "Integer"); 115 } 116 if (null == value) { 117 if (!nullOk) { 118 throw new ColumnNullException(this); 119 } else { 120 return 0; 121 } 122 } 123 return ((Integer ) value).intValue(); 124 } 125 126 136 public Integer getInteger() 137 throws ColumnTypeException { 138 if (!(value instanceof Integer )) { 139 throw new ColumnTypeException(this, "Integer"); 140 } 141 return (Integer ) value; 142 } 143 144 157 public double getDouble(boolean nullOk) 158 throws ColumnTypeException, ColumnNullException { 159 if (null == value) { 160 if (!nullOk) { 161 throw new ColumnNullException(this); 162 } else { 163 return 0; 164 } 165 } 166 Double d = getDouble(); 167 168 return d.doubleValue(); 169 } 170 171 181 public Double getDouble() 182 throws ColumnTypeException { 183 if (value instanceof Double ) { 184 return (Double ) value; 185 } 186 if (value instanceof BigDecimal ) { 187 BigDecimal b = (BigDecimal ) value; 188 189 return (Double ) new Double (b.toString()); 190 } 191 throw new ColumnTypeException(this, "Double/BigDecimal"); 192 } 193 194 204 public BigDecimal getBigDecimal() 205 throws ColumnTypeException { 206 if (value instanceof Long ) { 208 return new BigDecimal (value.toString()); 209 } 210 if (!(value instanceof BigDecimal )) { 211 throw new ColumnTypeException(this, "BigDecimal"); 212 } 213 return (BigDecimal ) value; 214 } 215 } 216 | Popular Tags |