KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws-clause
24

25 import org.polepos.teams.jdo.*;
26
27 import com.versant.core.common.BindingSupportImpl;
28
29
30 // import oracle.sql.BLOB;
31

32
33
34 /**
35  * This converter converts byte[] stored in Oracle BLOB columns to
36  * and from SQL.
37  * @keep-all
38  */

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

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

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

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

88     public Object JavaDoc get(ResultSet JavaDoc rs, int index, JdbcColumn col)
89             throws SQLException JavaDoc, JDOFatalDataStoreException {
90
91         VoaEdited.exception();
92         return null;
93         
94 // BLOB blob = (BLOB)rs.getBlob(index);
95
// if (blob == null || blob.isEmptyLob()) return null;
96
// if (blob.length() == 0) return EMPTY_BYTE_ARRAY;
97
// return blob.getBytes(1, (int)blob.length());
98

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

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

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

132     public void set(ResultSet JavaDoc rs, int index, JdbcColumn col, Object JavaDoc value)
133             throws SQLException JavaDoc, JDOFatalDataStoreException {
134         
135         VoaEdited.exception();
136
137 // BLOB blob = (BLOB)rs.getBlob(index);
138
// blob.putBytes(1, (byte[])value);
139

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

150     public Class JavaDoc getValueType() {
151         return byte[].class;
152     }
153
154 }
155
156
Popular Tags