01: package simpleorm.core;
02:
03: import simpleorm.properties.*;
04: import java.sql.ResultSet;
05:
06: /** Represents Integer field meta data. */
07:
08: public class SFieldInteger extends SFieldScalar {
09: public SFieldInteger(SRecordMeta meta, String columnName,
10: SPropertyValue[] pvals) {
11: super (meta, columnName, pvals);
12: }
13:
14: public SFieldInteger(SRecordMeta meta, String columnName) {
15: this (meta, columnName, new SPropertyValue[0]);
16: }
17:
18: public SFieldInteger(SRecordMeta meta, String columnName,
19: SPropertyValue pval) {
20: this (meta, columnName, new SPropertyValue[] { pval });
21: }
22:
23: public SFieldInteger(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 SFieldInteger(rmeta, (prefix == null ? "" : prefix)
33: + getString(SCon.SCOLUMN_NAME), pvals);
34: }
35:
36: Object queryFieldValue(ResultSet rs, int sqlIndex) throws Exception {
37: int res = rs.getInt(sqlIndex);
38: if (rs.wasNull()) // ie. last operation!
39: return null;
40: else
41: return SJSharp.newInteger(res);
42: }
43:
44: Object convertToField(Object raw) throws Exception {
45: if (SJSharp.isInteger(raw))
46: return raw;
47: if (raw == null)
48: return null;
49: if (raw instanceof Number)
50: return SJSharp.newInteger((Number) raw);
51: if (raw instanceof String) {
52: return SJSharp.newInteger((String) raw);
53: }
54: throw new SException.Data("Cannot convert " + raw
55: + " to Integer.");
56: }
57:
58: /** Specializes SFieldMeta. */
59: String defaultDataType() {
60: return "INTEGER";
61: }
62:
63: }
|