KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > OracleStringMapping


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: OracleStringMapping.java,v 1.2 2002/10/17 21:00:57 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import com.triactive.jdo.PersistenceManager;
14 import java.sql.PreparedStatement JavaDoc;
15 import java.sql.ResultSet JavaDoc;
16 import java.sql.Types JavaDoc;
17
18
19 public class OracleStringMapping extends StringMapping
20 {
21     static final String JavaDoc EMPTY_STRING_SURROGATE = "\u0001";
22
23     public OracleStringMapping(DatabaseAdapter dba, Class JavaDoc type)
24     {
25         super(dba, type);
26     }
27
28     public OracleStringMapping(Column col)
29     {
30         super(col);
31     }
32
33     public OracleStringMapping(ClassBaseTable table, int relativeFieldNumber)
34     {
35         this(table.newColumn(relativeFieldNumber));
36     }
37
38     protected TypeInfo getTypeInfo()
39     {
40         TypeInfo ti;
41
42         if (col == null)
43             ti = dba.getTypeInfo(Types.VARCHAR);
44         else
45         {
46             switch (col.getLengthType())
47             {
48                 case Column.FIXED_LENGTH:
49                     ti = dba.getTypeInfo(Types.CHAR);
50                     break;
51
52                 case Column.MAXIMUM_LENGTH:
53                 default:
54                     ti = dba.getTypeInfo(Types.VARCHAR);
55                     break;
56             }
57         }
58
59         return ti;
60     }
61
62
63     public void setString(PersistenceManager pm, PreparedStatement JavaDoc ps, int param, String JavaDoc value)
64     {
65         if (value != null && value.length() == 0)
66             value = EMPTY_STRING_SURROGATE;
67
68         super.setString(pm, ps, param, value);
69     }
70
71     public String JavaDoc getString(PersistenceManager pm, ResultSet JavaDoc rs, int param)
72     {
73         String JavaDoc value = super.getString(pm, rs, param);
74
75         if (value != null && value.equals(EMPTY_STRING_SURROGATE))
76             value = "";
77
78         return value;
79     }
80 }
81
Popular Tags