1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 package com.sun.star.comp.sdbc; 22 23 import java.io.Reader; 24 25 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.ResourceBasedEventLogger; 26 import org.apache.openoffice.comp.sdbc.dbtools.util.Resources; 27 import org.apache.openoffice.comp.sdbc.dbtools.util.SharedResources; 28 import org.apache.openoffice.comp.sdbc.dbtools.util.StandardSQLState; 29 30 import com.sun.star.io.XInputStream; 31 import com.sun.star.lib.uno.adapter.InputStreamToXInputStreamAdapter; 32 import com.sun.star.lib.uno.helper.ComponentBase; 33 import com.sun.star.logging.LogLevel; 34 import com.sun.star.sdbc.SQLException; 35 import com.sun.star.sdbc.XClob; 36 import com.sun.star.uno.Any; 37 38 public class JavaSQLClob extends ComponentBase implements XClob { 39 private final ResourceBasedEventLogger logger; 40 private final java.sql.Clob jdbcClob; 41 JavaSQLClob(ResourceBasedEventLogger logger, java.sql.Clob jdbcClob)42 public JavaSQLClob(ResourceBasedEventLogger logger, java.sql.Clob jdbcClob) { 43 this.logger = logger; 44 this.jdbcClob = jdbcClob; 45 } 46 47 @Override postDisposing()48 protected void postDisposing() { 49 try { 50 jdbcClob.free(); 51 } catch (java.sql.SQLException jdbcSQLException) { 52 logger.log(LogLevel.WARNING, jdbcSQLException); 53 } 54 } 55 56 @Override getCharacterStream()57 public XInputStream getCharacterStream() throws SQLException { 58 try { 59 Reader reader = jdbcClob.getCharacterStream(); 60 if (reader != null) { 61 return new InputStreamToXInputStreamAdapter(new ReaderInputStream(reader)); 62 } else { 63 return null; 64 } 65 } catch (java.sql.SQLException jdbcSQLException) { 66 throw Tools.toUnoException(this, jdbcSQLException); 67 } 68 } 69 70 @Override getSubString(long pos, int length)71 public String getSubString(long pos, int length) throws SQLException { 72 try { 73 return jdbcClob.getSubString(pos, length); 74 } catch (java.sql.SQLException jdbcSQLException) { 75 throw Tools.toUnoException(this, jdbcSQLException); 76 } 77 } 78 79 @Override length()80 public long length() throws SQLException { 81 try { 82 return jdbcClob.length(); 83 } catch (java.sql.SQLException jdbcSQLException) { 84 throw Tools.toUnoException(this, jdbcSQLException); 85 } 86 } 87 88 @Override position(String searchstr, int start)89 public long position(String searchstr, int start) throws SQLException { 90 try { 91 return jdbcClob.position(searchstr, start); 92 } catch (java.sql.SQLException jdbcSQLException) { 93 throw Tools.toUnoException(this, jdbcSQLException); 94 } 95 } 96 97 @Override positionOfClob(XClob arg0, long arg1)98 public long positionOfClob(XClob arg0, long arg1) throws SQLException { 99 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore 100 // the pattern parameter. Since the effort for proper implementation is rather high - we would need 101 // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was 102 // unusable, anyway) 103 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com 104 throw new SQLException( 105 SharedResources.getInstance().getResourceStringWithSubstitution( 106 Resources.STR_UNSUPPORTED_FEATURE, "$featurename$", "XClob::positionOfClob"), 107 this, StandardSQLState.SQL_FEATURE_NOT_IMPLEMENTED.name(), 0, Any.VOID); 108 } 109 } 110