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