01: package simpleorm.core;
02:
03: import simpleorm.properties.*;
04: import java.sql.ResultSet;
05:
06: /** Represents Long field meta data. Default SQL type is
07: NUMERIC(18,0), which is roughly sql-92.*/
08:
09: public class SFieldLong extends SFieldScalar {
10: public SFieldLong(SRecordMeta meta, String columnName,
11: SPropertyValue[] pvals) {
12: super (meta, columnName, pvals);
13: }
14:
15: public SFieldLong(SRecordMeta meta, String columnName) {
16: this (meta, columnName, new SPropertyValue[0]);
17: }
18:
19: public SFieldLong(SRecordMeta meta, String columnName,
20: SPropertyValue pval) {
21: this (meta, columnName, new SPropertyValue[] { pval });
22: }
23:
24: public SFieldLong(SRecordMeta meta, String columnName,
25: SPropertyValue pval1, SPropertyValue pval2) {
26: this (meta, columnName, new SPropertyValue[] { pval1, pval2 });
27: }
28:
29: /** Abstract specializer. Clone this key field to be a foreign key
30: to <code>rmeta</code> of the same type.*/
31: SFieldMeta makeForeignKey(SRecordMeta rmeta, String prefix,
32: SPropertyValue[] pvals) {
33: return new SFieldLong(rmeta, (prefix == null ? "" : prefix)
34: + getString(SCon.SCOLUMN_NAME), pvals);
35: }
36:
37: Object queryFieldValue(ResultSet rs, int sqlIndex) throws Exception {
38: long res = rs.getLong(sqlIndex);
39: if (rs.wasNull()) // ie. last operation!
40: return null;
41: else
42: return SJSharp.newLong(res);
43: }
44:
45: Object convertToField(Object raw) throws Exception {
46: if (SJSharp.isLong(raw))
47: return raw;
48: if (raw == null)
49: return null;
50: if (raw instanceof Number)
51: return SJSharp.newLong((Number) raw);
52: if (raw instanceof String) {
53: return SJSharp.newLong((String) raw);
54: }
55: throw new SException.Data("Cannot convert " + raw + " to Long.");
56: }
57:
58: /** Specializes SFieldMeta. This is basically SQL 2, and fairly
59: database independent, we hope. Note that "LONG" for Oracle
60: means a text field that can contain over 2K characters! */
61: String defaultDataType() {
62: return "NUMERIC(18,0)";
63: }
64:
65: }
|