01: package simpleorm.core;
02:
03: import simpleorm.properties.*;
04: import java.sql.ResultSet;
05:
06: /** Represents columns that are not objects known to SimpleORM. No
07: conversions are done, so this provides a direct gateway to
08: <code>java.sql.RecordSet.getObject</code>. Useful for database
09: specific data types such as PostgreSQL's GIS types, and also for
10: the new SQL array and object types. <p>
11:
12: ## Should add the JDBC object mapping property, but normally the
13: default map is OK.*/
14:
15: public class SFieldObject extends SFieldScalar {
16: public SFieldObject(SRecordMeta meta, String columnName,
17: SPropertyValue[] pvals) {
18: super (meta, columnName, pvals);
19: }
20:
21: public SFieldObject(SRecordMeta meta, String columnName) {
22: this (meta, columnName, new SPropertyValue[0]);
23: }
24:
25: public SFieldObject(SRecordMeta meta, String columnName,
26: SPropertyValue pval) {
27: this (meta, columnName, new SPropertyValue[] { pval });
28: }
29:
30: public SFieldObject(SRecordMeta meta, String columnName,
31: SPropertyValue pval1, SPropertyValue pval2) {
32: this (meta, columnName, new SPropertyValue[] { pval1, pval2 });
33: }
34:
35: /** Abstract specializer. Clone this key field to be a foreign key
36: to <code>rmeta</code> of the same type.*/
37: SFieldMeta makeForeignKey(SRecordMeta rmeta, String prefix,
38: SPropertyValue[] pvals) {
39: return new SFieldObject(rmeta, (prefix == null ? "" : prefix)
40: + getString(SCon.SCOLUMN_NAME), pvals);
41: }
42:
43: /** Specidalizes abstract method to actually query a column from a
44: result set. */
45: Object queryFieldValue(ResultSet rs, int sqlIndex) throws Exception {
46: Object res = rs.getObject(sqlIndex);
47: if (rs.wasNull()) // ie. last operation!
48: return null;
49: else
50: return res;
51: }
52:
53: Object convertToField(Object raw) throws Exception {
54: return raw; // No Conversions.
55: }
56:
57: String defaultDataType() {
58: return "OBJECT";
59: }
60: }
|