1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "java/sql/Clob.hxx" 31 #include "java/tools.hxx" 32 #include "java/io/Reader.hxx" 33 #include <connectivity/dbexception.hxx> 34 #include <rtl/logfile.hxx> 35 36 using namespace connectivity; 37 //************************************************************** 38 //************ Class: java.sql.Clob 39 //************************************************************** 40 41 jclass java_sql_Clob::theClass = 0; 42 43 java_sql_Clob::java_sql_Clob( JNIEnv * pEnv, jobject myObj ) 44 : java_lang_Object( pEnv, myObj ) 45 { 46 SDBThreadAttach::addRef(); 47 } 48 java_sql_Clob::~java_sql_Clob() 49 { 50 SDBThreadAttach::releaseRef(); 51 } 52 53 jclass java_sql_Clob::getMyClass() const 54 { 55 // die Klasse muss nur einmal geholt werden, daher statisch 56 if( !theClass ) 57 theClass = findMyClass("java/sql/Clob"); 58 return theClass; 59 } 60 61 sal_Int64 SAL_CALL java_sql_Clob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 62 { 63 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::length" ); 64 jlong out(0); 65 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 66 67 { 68 // temporaere Variable initialisieren 69 static const char * cSignature = "()J"; 70 static const char * cMethodName = "length"; 71 // Java-Call absetzen 72 static jmethodID mID(NULL); 73 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 74 out = t.pEnv->CallLongMethod( object, mID ); 75 ThrowSQLException(t.pEnv,*this); 76 } //t.pEnv 77 return (sal_Int64)out; 78 } 79 80 ::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) 81 { 82 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::getSubString" ); 83 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 84 ::rtl::OUString aStr; 85 { 86 // temporaere Variable initialisieren 87 static const char * cSignature = "(JI)Ljava/lang/String;"; 88 static const char * cMethodName = "getSubString"; 89 // Java-Call absetzen 90 static jmethodID mID(NULL); 91 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 92 jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID,pos,subStringLength); 93 ThrowSQLException(t.pEnv,*this); 94 aStr = JavaString2String(t.pEnv,out); 95 } //t.pEnv 96 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! 97 return aStr; 98 } 99 100 ::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) 101 { 102 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::getCharacterStream" ); 103 SDBThreadAttach t; 104 static jmethodID mID(NULL); 105 jobject out = callObjectMethod(t.pEnv,"getCharacterStream","()Ljava/io/Reader;", mID); 106 107 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! 108 return out==0 ? 0 : new java_io_Reader( t.pEnv, out ); 109 } 110 111 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) 112 { 113 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::position" ); 114 jlong out(0); 115 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!"); 116 117 { 118 jvalue args[1]; 119 // Parameter konvertieren 120 args[0].l = convertwchar_tToJavaString(t.pEnv,searchstr); 121 // temporaere Variable initialisieren 122 static const char * cSignature = "(Ljava/lang/String;I)J"; 123 static const char * cMethodName = "position"; 124 // Java-Call absetzen 125 static jmethodID mID(NULL); 126 obtainMethodId(t.pEnv, cMethodName,cSignature, mID); 127 out = t.pEnv->CallLongMethod( object, mID, args[0].l,start ); 128 ThrowSQLException(t.pEnv,*this); 129 t.pEnv->DeleteLocalRef((jstring)args[0].l); 130 } //t.pEnv 131 return (sal_Int64)out; 132 } 133 134 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) 135 { 136 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "jdbc", "Ocke.Janssen@sun.com", "java_sql_Clob::positionOfClob" ); 137 ::dbtools::throwFeatureNotImplementedException( "XClob::positionOfClob", *this ); 138 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore 139 // the pattern parameter. Since the effort for proper implementation is rather high - we would need 140 // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was 141 // unusable, anyway) 142 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com 143 return 0; 144 } 145 146 147