KickJava   Java API By Example, From Geeks To Geeks.

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


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.metadata.JdbcColumn;
17
18 import java.sql.PreparedStatement JavaDoc;
19 import java.sql.SQLException JavaDoc;
20 import java.sql.ResultSet JavaDoc;
21
22 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws-clause
23

24 import com.versant.core.common.BindingSupportImpl;
25
26 /**
27  * <p>Base class for converters. This implements most methods in JdbcConverter
28  * assuming that this is not a Oracle style LOB converter. Subclasses
29  * only have to provide the following methods:</p>
30  *
31  * <ul>
32  * <li>{@link #get(ResultSet, int, JdbcColumn) }
33  * <li>{@link #set(PreparedStatement, int, JdbcColumn, Object) }
34  * <li>{@link #getValueType() }
35  * </ul>
36  *
37  * <p>A {@link JdbcConverterFactory} must also be written.</p>
38  *
39  * @keep-all
40  */

41 public abstract class JdbcConverterBase implements JdbcConverter {
42
43     /**
44      * Is this converter for an Oracle style LOB column? Oracle LOBs require
45      * a hard coded a value into the insert/update statement instead of using
46      * a replaceable parameter and then select the value (if not null) and
47      * modify it.
48      */

49     public boolean isOracleStyleLOB() {
50         return false;
51     }
52
53     /**
54      * This is only called if isOracleStyleLOB returns true. Get the String
55      * to be embedded in an SQL insert/update statement when the value for
56      * this column is not null (e.g. "empty_clob()");
57      */

58     public String JavaDoc getOracleStyleLOBNotNullString() {
59         return null;
60     }
61
62     /**
63      * Get the value of col from rs at position index.
64      * @exception SQLException on SQL errors
65      * @exception JDOFatalDataStoreException if the ResultSet value is invalid
66      */

67     public abstract Object JavaDoc get(ResultSet JavaDoc rs, int index, JdbcColumn col)
68             throws SQLException JavaDoc, JDOFatalDataStoreException;
69
70
71
72
73
74     /**
75      * Set parameter index on ps to value (for col).
76      * @exception SQLException on SQL errors
77      * @exception JDOFatalDataStoreException if value is invalid
78      */

79     public abstract void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col,
80             Object JavaDoc value) throws SQLException JavaDoc, JDOFatalDataStoreException;
81
82     /**
83      * Set parameter index on ps to value (for col). This special form is used
84      * when the value to be set is available as an int to avoid creating
85      * an wrapper instance.
86      * @exception SQLException on SQL errors
87      * @exception JDOFatalDataStoreException if value is invalid
88      */

89     public void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col, int value)
90             throws SQLException JavaDoc, JDOFatalDataStoreException {
91         throw BindingSupportImpl.getInstance().fatalDatastore("set(..int) called");
92     }
93
94     /**
95      * This method is called for converters that return true for
96      * isOracleStyleLOB. The value at index in rs will contain the LOB to
97      * be updated.
98      * @exception SQLException on SQL errors
99      * @exception JDOFatalDataStoreException if value is invalid
100      */

101     public void set(ResultSet JavaDoc rs, int index, JdbcColumn col, Object JavaDoc value)
102             throws SQLException JavaDoc, JDOFatalDataStoreException {
103         throw BindingSupportImpl.getInstance().fatalDatastore("set(rs..) called");
104     }
105
106     /**
107      * Get the type of our expected value objects (e.g. java.util.Locale
108      * for a converter for Locale's).
109      */

110     public abstract Class JavaDoc getValueType();
111
112 }
113
114
Popular Tags