01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: OracleStringMapping.java,v 1.2 2002/10/17 21:00:57 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import com.triactive.jdo.PersistenceManager;
14: import java.sql.PreparedStatement;
15: import java.sql.ResultSet;
16: import java.sql.Types;
17:
18: public class OracleStringMapping extends StringMapping {
19: static final String EMPTY_STRING_SURROGATE = "\u0001";
20:
21: public OracleStringMapping(DatabaseAdapter dba, Class type) {
22: super (dba, type);
23: }
24:
25: public OracleStringMapping(Column col) {
26: super (col);
27: }
28:
29: public OracleStringMapping(ClassBaseTable table,
30: int relativeFieldNumber) {
31: this (table.newColumn(relativeFieldNumber));
32: }
33:
34: protected TypeInfo getTypeInfo() {
35: TypeInfo ti;
36:
37: if (col == null)
38: ti = dba.getTypeInfo(Types.VARCHAR);
39: else {
40: switch (col.getLengthType()) {
41: case Column.FIXED_LENGTH:
42: ti = dba.getTypeInfo(Types.CHAR);
43: break;
44:
45: case Column.MAXIMUM_LENGTH:
46: default:
47: ti = dba.getTypeInfo(Types.VARCHAR);
48: break;
49: }
50: }
51:
52: return ti;
53: }
54:
55: public void setString(PersistenceManager pm, PreparedStatement ps,
56: int param, String value) {
57: if (value != null && value.length() == 0)
58: value = EMPTY_STRING_SURROGATE;
59:
60: super .setString(pm, ps, param, value);
61: }
62:
63: public String getString(PersistenceManager pm, ResultSet rs,
64: int param) {
65: String value = super .getString(pm, rs, param);
66:
67: if (value != null && value.equals(EMPTY_STRING_SURROGATE))
68: value = "";
69:
70: return value;
71: }
72: }
|