01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.sql.conv;
12:
13: import com.versant.core.jdbc.JdbcConverter;
14: import com.versant.core.jdbc.JdbcConverterFactory;
15: import com.versant.core.jdbc.JdbcTypeRegistry;
16: import com.versant.core.jdbc.metadata.JdbcColumn;
17:
18: import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
19: import java.sql.PreparedStatement;
20: import java.sql.SQLException;
21: import java.sql.ResultSet;
22: import java.sql.Types;
23:
24: /**
25: * This converter treats CLOB columns as normal String columns. It is used
26: * for JDBC drivers that do not support CLOB as a data type e.g. Sybase
27: * and Microsoft SQL Server to avoid getting an exception when doing a
28: * setNull(index, Types.CLOB).
29: * @keep-all
30: */
31: public class ClobStringConverter extends JdbcConverterBase {
32:
33: public static class Factory extends NoArgJdbcConverterFactory {
34:
35: private ClobStringConverter converter;
36:
37: /**
38: * Create a converter for col using args as parameters. Return null if
39: * no converter is required.
40: */
41: public JdbcConverter createJdbcConverter(JdbcColumn col,
42: Object args, JdbcTypeRegistry jdbcTypeRegistry) {
43: if (converter == null)
44: converter = new ClobStringConverter();
45: return converter;
46: }
47:
48: }
49:
50: /**
51: * Get the value of col from rs at position index.
52: * @exception SQLException on SQL errors
53: * @exception JDOFatalDataStoreException if the ResultSet value is invalid
54: */
55: public Object get(ResultSet rs, int index, JdbcColumn col)
56: throws SQLException, JDOFatalDataStoreException {
57: return rs.getString(index);
58: }
59:
60: /**
61: * Set parameter index on ps to value (for col).
62: * @exception SQLException on SQL errors
63: * @exception JDOFatalDataStoreException if value is invalid
64: */
65: public void set(PreparedStatement ps, int index, JdbcColumn col,
66: Object value) throws SQLException,
67: JDOFatalDataStoreException {
68: if (value == null) {
69: ps.setNull(index, Types.LONGVARCHAR);
70: } else {
71: ps.setString(index, (String) value);
72: }
73: }
74:
75: /**
76: * Get the type of our expected value objects (e.g. java.util.Locale
77: * for a converter for Locale's).
78: */
79: public Class getValueType() {
80: return String.class;
81: }
82:
83: }
|