KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > conv > OracleClobConverter


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql.conv;
13
14 import com.versant.core.jdbc.JdbcConverter;
15 import com.versant.core.jdbc.JdbcConverterFactory;
16 import com.versant.core.jdbc.JdbcTypeRegistry;
17 import com.versant.core.jdbc.metadata.JdbcColumn;
18
19 import java.sql.PreparedStatement JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import java.sql.ResultSet JavaDoc;
22 import java.sql.Clob JavaDoc;
23
24
25 // import oracle.sql.CLOB;
26

27
28 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws-clause
29

30 import org.polepos.teams.jdo.*;
31
32 import com.versant.core.common.BindingSupportImpl;
33
34 /**
35  * This converter converts Strings stored in Oracle CLOB columns to
36  * and from SQL.
37  * @keep-all
38  */

39 public class OracleClobConverter implements JdbcConverter {
40     
41     public OracleClobConverter(){
42         VoaEdited.exception();
43     }
44
45     public static class Factory extends NoArgJdbcConverterFactory {
46
47         private OracleClobConverter converter;
48
49         /**
50          * Create a converter for col using args as parameters. Return null if
51          * no converter is required.
52          */

53         public JdbcConverter createJdbcConverter(JdbcColumn col, Object JavaDoc args,
54                 JdbcTypeRegistry jdbcTypeRegistry) {
55             if (converter == null) converter = new OracleClobConverter();
56             return converter;
57         }
58
59     }
60
61     /**
62      * Is this converter for an Oracle style LOB column? Oracle LOBs require
63      * a hard coded a value into the insert/update statement instead of using
64      * a replaceable parameter and then select the value (if not null) and
65      * modify it.
66      */

67     public boolean isOracleStyleLOB() {
68         return true;
69     }
70
71     /**
72      * This is only called if isOracleStyleLOB returns true. Get the String
73      * to be embedded in an SQL insert/update statement when the value for
74      * this column is not null (e.g. "empty_clob()");
75      */

76     public String JavaDoc getOracleStyleLOBNotNullString() {
77         return "empty_clob()";
78     }
79
80     /**
81      * Get the value of col from rs at position index.
82      * @exception SQLException on SQL errors
83      * @exception JDOFatalDataStoreException if the ResultSet value is invalid
84      */

85     public Object JavaDoc get(ResultSet JavaDoc rs, int index, JdbcColumn col)
86             throws SQLException JavaDoc, JDOFatalDataStoreException {
87         
88         VoaEdited.exception();
89         return null;
90
91 // CLOB clob = (CLOB)rs.getClob(index);
92
// if (clob == null || clob.isEmptyLob()) return null;
93
// if (clob.length() == 0) return "";
94
// return clob.getSubString(1, (int)clob.length());
95

96     }
97
98
99
100
101     /**
102      * Set parameter index on ps to value (for col).
103      * @exception SQLException on SQL errors
104      * @exception JDOFatalDataStoreException if value is invalid
105      */

106     public void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col, Object JavaDoc value)
107             throws SQLException JavaDoc, JDOFatalDataStoreException {
108         throw BindingSupportImpl.getInstance().internal("set(ps..) called");
109     }
110
111     /**
112      * Set parameter index on ps to value (for col). This special form is used
113      * when the value to be set is available as an int to avoid creating
114      * an wrapper instance.
115      * @exception SQLException on SQL errors
116      * @exception JDOFatalDataStoreException if value is invalid
117      */

118     public void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col, int value)
119             throws SQLException JavaDoc, JDOFatalDataStoreException {
120         throw BindingSupportImpl.getInstance().internal("set(..int) called");
121     }
122
123     /**
124      * This method is called for converters that return true for
125      * isOracleStyleLOB. The value at index in rs will contain the LOB to
126      * be updated.
127      * @exception SQLException on SQL errors
128      * @exception JDOFatalDataStoreException if value is invalid
129      */

130     public void set(ResultSet JavaDoc rs, int index, JdbcColumn col, Object JavaDoc value)
131             throws SQLException JavaDoc, JDOFatalDataStoreException {
132         
133         VoaEdited.exception();
134
135 // String s = (String)value;
136
// CLOB clob = (CLOB)rs.getClob(index);
137
// clob.putString(1, s);
138

139         // Calling trim leaks cursors - we make new CLOBs for every update to
140
// avoid this problem
141
// DO NOT DO - clob.trim(s.length());
142
}
143
144
145     /**
146      * Get the type of our expected value objects (e.g. java.util.Locale
147      * for a converter for Locale's).
148      */

149     public Class JavaDoc getValueType() {
150         return String JavaDoc.class;
151     }
152
153 }
154
155
Popular Tags