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 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_connectivity.hxx" 26 #include "java/sql/Clob.hxx" 27 #include "java/tools.hxx" 28 #include "java/io/Reader.hxx" 29 #include <connectivity/dbexception.hxx> 30 #include <rtl/logfile.hxx> 31 32 using namespace connectivity; 33 //************************************************************** 34 //************ Class: java.sql.Clob 35 //************************************************************** 36 37 jclass java_sql_Clob::theClass = 0; 38 39 java_sql_Clob::java_sql_Clob( JNIEnv * pEnv, jobject myObj ) 40 : java_lang_Object( pEnv, myObj ) 41 { 42 SDBThreadAttach::addRef(); 43 } 44 java_sql_Clob::~java_sql_Clob() 45 { 46 SDBThreadAttach::releaseRef(); 47 } 48 49 jclass java_sql_Clob::getMyClass() const 50 { 51 // die Klasse muss nur einmal geholt werden, daher statisch 52 if( !theClass ) 53 theClass = findMyClass("java/sql/Clob"); 54 return theClass; 55 } 56 57 sal_Int64 SAL_CALL java_sql_Clob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 58 { 59 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::length" ); 60 jlong out(0); 61 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 62 63 { 64 // temporaere Variable initialisieren 65 static const char * cSignature = "()J"; 66 static const char * cMethodName = "length"; 67 // Java-Call absetzen 68 static jmethodID mID(NULL); 69 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 70 out = t.pEnv->CallLongMethod( object, mID ); 71 ThrowSQLException(t.pEnv,*this); 72 } //t.pEnv 73 return (sal_Int64)out; 74 } 75 76 ::rtl::OUString SAL_CALL java_sql_Clob::getSubString( sal_Int64 pos, sal_Int32 subStringLength ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 77 { 78 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::getSubString" ); 79 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 80 ::rtl::OUString aStr; 81 { 82 // temporaere Variable initialisieren 83 static const char * cSignature = "(JI)Ljava/lang/String;"; 84 static const char * cMethodName = "getSubString"; 85 // Java-Call absetzen 86 static jmethodID mID(NULL); 87 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 88 jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID,pos,subStringLength); 89 ThrowSQLException(t.pEnv,*this); 90 aStr = JavaString2String(t.pEnv,out); 91 } //t.pEnv 92 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! 93 return aStr; 94 } 95 96 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_Clob::getCharacterStream( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 97 { 98 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::getCharacterStream" ); 99 SDBThreadAttach t; 100 static jmethodID mID(NULL); 101 jobject out = callObjectMethod(t.pEnv,"getCharacterStream","()Ljava/io/Reader;", mID); 102 103 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! 104 return out==0 ? 0 : new java_io_Reader( t.pEnv, out ); 105 } 106 107 sal_Int64 SAL_CALL java_sql_Clob::position( const ::rtl::OUString& searchstr, sal_Int32 start ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 108 { 109 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::position" ); 110 jlong out(0); 111 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 112 113 { 114 jvalue args[1]; 115 // Parameter konvertieren 116 args[0].l = convertwchar_tToJavaString(t.pEnv,searchstr); 117 // temporaere Variable initialisieren 118 static const char * cSignature = "(Ljava/lang/String;I)J"; 119 static const char * cMethodName = "position"; 120 // Java-Call absetzen 121 static jmethodID mID(NULL); 122 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 123 out = t.pEnv->CallLongMethod( object, mID, args[0].l,start ); 124 ThrowSQLException(t.pEnv,*this); 125 t.pEnv->DeleteLocalRef((jstring)args[0].l); 126 } //t.pEnv 127 return (sal_Int64)out; 128 } 129 130 sal_Int64 SAL_CALL java_sql_Clob::positionOfClob( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& /*pattern*/, sal_Int64 /*start*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 131 { 132 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::positionOfClob" ); 133 ::dbtools::throwFeatureNotImplementedException( "XClob::positionOfClob", *this ); 134 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore 135 // the pattern parameter. Since the effort for proper implementation is rather high - we would need 136 // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was 137 // unusable, anyway) 138 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com 139 return 0; 140 } 141 142 143