01: package simpleorm.core;
02:
03: import simpleorm.properties.*;
04: import java.sql.ResultSet;
05:
06: /** Represents String field meta data. */
07:
08: public class SFieldString extends SFieldScalar {
09:
10: /** <code>maxSize</code> is the maximum size in bytes (not
11: characters) of the column. This fairly meaningless number is
12: required for all database DDL except PostgreSQL, for which it is
13: ignored. */
14: public SFieldString(SRecordMeta meta, String columnName,
15: int maxSize, SPropertyValue[] pvals) {
16: super (meta, columnName, pvals);
17: putProperty(SCon.SBYTE_SIZE, SJSharp.newInteger(maxSize)); // for Create Table only.
18: }
19:
20: public SFieldString(SRecordMeta meta, String columnName, int maxSize) {
21: this (meta, columnName, maxSize, new SPropertyValue[0]);
22: }
23:
24: public SFieldString(SRecordMeta meta, String columnName,
25: int maxSize, SPropertyValue pval) {
26: this (meta, columnName, maxSize, new SPropertyValue[] { pval });
27: }
28:
29: public SFieldString(SRecordMeta meta, String columnName,
30: int maxSize, SPropertyValue pval1, SPropertyValue pval2) {
31: this (meta, columnName, maxSize, new SPropertyValue[] { pval1,
32: 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 SFieldString(rmeta, (prefix == null ? "" : prefix)
40: + getString(SCon.SCOLUMN_NAME), SJSharp
41: .object2Int(getProperty(SCon.SBYTE_SIZE)), pvals);
42: }
43:
44: Object queryFieldValue(ResultSet rs, int sqlIndex) throws Exception {
45: return rs.getString(sqlIndex);
46: }
47:
48: Object convertToField(Object raw) {
49: return raw == null ? null : raw.toString();
50: }
51:
52: /** Specializes SFieldMeta. */
53: String defaultDataType() {
54: return getBoolean(SCon.SSTRING_CHAR) ? "CHAR" : "VARCHAR";
55: }
56:
57: // OK public SFieldString tester() {return this;}
58: }
|