01: package simpleorm.core;
02:
03: import simpleorm.properties.*;
04: import java.sql.ResultSet;
05:
06: /** Represents Double field meta data. */
07:
08: public class SFieldDouble extends SFieldScalar {
09: public SFieldDouble(SRecordMeta meta, String columnName,
10: SPropertyValue[] pvals) {
11: super (meta, columnName, pvals);
12: }
13:
14: public SFieldDouble(SRecordMeta meta, String columnName) {
15: this (meta, columnName, new SPropertyValue[0]);
16: }
17:
18: public SFieldDouble(SRecordMeta meta, String columnName,
19: SPropertyValue pval) {
20: this (meta, columnName, new SPropertyValue[] { pval });
21: }
22:
23: public SFieldDouble(SRecordMeta meta, String columnName,
24: SPropertyValue pval1, SPropertyValue pval2) {
25: this (meta, columnName, new SPropertyValue[] { pval1, pval2 });
26: }
27:
28: /** Abstract specializer. Clone this key field to be a foreign key
29: to <code>rmeta</code> of the same type.*/
30: SFieldMeta makeForeignKey(SRecordMeta rmeta, String prefix,
31: SPropertyValue[] pvals) {
32: return new SFieldDouble(rmeta, (prefix == null ? "" : prefix)
33: + getString(SCon.SCOLUMN_NAME), pvals);
34: }
35:
36: /** Specidalizes abstract method to actually query a column from a
37: result set. */
38: Object queryFieldValue(ResultSet rs, int sqlIndex) throws Exception {
39: double res = rs.getDouble(sqlIndex);
40: if (rs.wasNull()) // ie. last operation!
41: return null;
42: else
43: return SJSharp.newDouble(res);
44: }
45:
46: Object convertToField(Object raw) throws Exception {
47: if (SJSharp.isDouble(raw))
48: return raw;
49: if (raw == null)
50: return null; // Follows JDBC
51: if (raw instanceof Number)
52: return SJSharp.newDouble((Number) raw);
53: if (raw instanceof String) {
54: return SJSharp.newDouble((String) raw);
55: }
56: throw new SException.Data("Cannot convert " + raw
57: + " to Double.");
58: }
59:
60: /** Specializes SFieldMeta. */
61: String defaultDataType() {
62: return "DOUBLE PRECISION";
63: }
64:
65: }
|