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