1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PreparedStatement.cxx,v $
10 * $Revision: 1.24.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "java/sql/PreparedStatement.hxx"
34 #include "java/sql/ResultSet.hxx"
35 #include "java/sql/ResultSetMetaData.hxx"
36 #include "java/sql/Connection.hxx"
37 #include "java/sql/Timestamp.hxx"
38 #include "java/math/BigDecimal.hxx"
39 #include "java/tools.hxx"
40 #include <cppuhelper/typeprovider.hxx>
41 #include <comphelper/sequence.hxx>
42 #include "connectivity/dbtools.hxx"
43 #include "connectivity/FValue.hxx"
44 #include "connectivity/dbexception.hxx"
45 #include "resource/jdbc_log.hrc"
46 #include "resource/common_res.hrc"
47 #include "resource/sharedresources.hxx"
51 using namespace connectivity
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::sdbc
;
55 using namespace ::com::sun::star::container
;
56 using namespace ::com::sun::star::lang
;
58 //**************************************************************
59 //************ Class: java.sql.PreparedStatement
60 //**************************************************************
61 IMPLEMENT_SERVICE_INFO(java_sql_PreparedStatement
,"com.sun.star.sdbcx.JPreparedStatement","com.sun.star.sdbc.PreparedStatement");
63 java_sql_PreparedStatement::java_sql_PreparedStatement( JNIEnv
* pEnv
, java_sql_Connection
& _rCon
, const ::rtl::OUString
& sql
)
64 : OStatement_BASE2( pEnv
, _rCon
)
66 m_sSqlStatement
= sql
;
68 // -----------------------------------------------------------------------------
69 jclass
java_sql_PreparedStatement::theClass
= 0;
71 java_sql_PreparedStatement::~java_sql_PreparedStatement()
74 // -----------------------------------------------------------------------------
76 jclass
java_sql_PreparedStatement::getMyClass() const
78 // die Klasse muss nur einmal geholt werden, daher statisch
80 theClass
= findMyClass("java/sql/PreparedStatement");
83 // -------------------------------------------------------------------------
85 ::com::sun::star::uno::Any SAL_CALL
java_sql_PreparedStatement::queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
)
87 ::com::sun::star::uno::Any aRet
= OStatement_BASE2::queryInterface(rType
);
88 return aRet
.hasValue() ? aRet
: ::cppu::queryInterface( rType
,
89 static_cast< XPreparedStatement
*>(this),
90 static_cast< XParameters
*>(this),
91 static_cast< XResultSetMetaDataSupplier
*>(this),
92 static_cast< XPreparedBatchExecution
*>(this));
94 // -------------------------------------------------------------------------
95 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
java_sql_PreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException
)
97 ::cppu::OTypeCollection
aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference
< XPreparedStatement
> *)0 ),
98 ::getCppuType( (const ::com::sun::star::uno::Reference
< XParameters
> *)0 ),
99 ::getCppuType( (const ::com::sun::star::uno::Reference
< XResultSetMetaDataSupplier
> *)0 ),
100 ::getCppuType( (const ::com::sun::star::uno::Reference
< XPreparedBatchExecution
> *)0 ));
102 return ::comphelper::concatSequences(aTypes
.getTypes(),OStatement_BASE2::getTypes());
104 // -------------------------------------------------------------------------
106 sal_Bool SAL_CALL
java_sql_PreparedStatement::execute( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
108 m_aLogger
.log( LogLevel::FINE
, STR_LOG_EXECUTING_PREPARED
);
109 ::osl::MutexGuard
aGuard( m_aMutex
);
110 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
112 static jmethodID
mID(NULL
);
113 return callBooleanMethod( "execute", mID
);
115 // -------------------------------------------------------------------------
117 sal_Int32 SAL_CALL
java_sql_PreparedStatement::executeUpdate( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
119 ::osl::MutexGuard
aGuard( m_aMutex
);
120 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
121 m_aLogger
.log( LogLevel::FINE
, STR_LOG_EXECUTING_PREPARED_UPDATE
);
122 static jmethodID
mID(NULL
);
123 return callIntMethod("executeUpdate",mID
);
125 // -------------------------------------------------------------------------
127 void SAL_CALL
java_sql_PreparedStatement::setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
129 ::osl::MutexGuard
aGuard( m_aMutex
);
130 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
131 m_aLogger
.log( LogLevel::FINER
, STR_LOG_STRING_PARAMETER
, parameterIndex
, x
);
133 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
134 { // temporaere Variable initialisieren
135 createStatement(t
.pEnv
);
136 static const char * cSignature
= "(ILjava/lang/String;)V";
137 static const char * cMethodName
= "setString";
138 // Java-Call absetzen
139 static jmethodID
mID(NULL
);
140 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
141 jstring str
= convertwchar_tToJavaString(t
.pEnv
,x
);
142 t
.pEnv
->CallVoidMethod( object
, mID
, parameterIndex
,str
);
144 t
.pEnv
->DeleteLocalRef(str
);
145 ThrowLoggedSQLException( m_aLogger
, t
.pEnv
, *this );
148 // -------------------------------------------------------------------------
150 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
java_sql_PreparedStatement::getConnection( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
152 return (Reference
< XConnection
>)m_pConnection
;
154 // -------------------------------------------------------------------------
156 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
java_sql_PreparedStatement::executeQuery( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
158 m_aLogger
.log( LogLevel::FINE
, STR_LOG_EXECUTING_PREPARED_QUERY
);
159 ::osl::MutexGuard
aGuard( m_aMutex
);
160 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
162 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
163 createStatement(t
.pEnv
);
164 static jmethodID
mID(NULL
);
165 jobject out
= callResultSetMethod(t
.env(),"executeQuery",mID
);
167 return out
==0 ? 0 : new java_sql_ResultSet( t
.pEnv
, out
, m_aLogger
, *m_pConnection
,this);
169 // -------------------------------------------------------------------------
171 void SAL_CALL
java_sql_PreparedStatement::setBoolean( sal_Int32 parameterIndex
, sal_Bool x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
173 m_aLogger
.log( LogLevel::FINER
, STR_LOG_BOOLEAN_PARAMETER
, parameterIndex
, x
);
174 ::osl::MutexGuard
aGuard( m_aMutex
);
175 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
177 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
178 createStatement(t
.pEnv
);
179 static jmethodID
mID(NULL
);
180 callVoidMethod("setBoolean", "(IZ)V", mID
, parameterIndex
, x
);
182 // -------------------------------------------------------------------------
184 void SAL_CALL
java_sql_PreparedStatement::setByte( sal_Int32 parameterIndex
, sal_Int8 x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
186 m_aLogger
.log( LogLevel::FINER
, STR_LOG_BYTE_PARAMETER
, parameterIndex
, (sal_Int32
)x
);
187 ::osl::MutexGuard
aGuard( m_aMutex
);
188 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
190 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
191 createStatement(t
.pEnv
);
192 static jmethodID
mID(NULL
);
193 callVoidMethod("setByte", "(IB)V", mID
, parameterIndex
, x
);
195 // -------------------------------------------------------------------------
197 void SAL_CALL
java_sql_PreparedStatement::setDate( sal_Int32 parameterIndex
, const ::com::sun::star::util::Date
& x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
199 m_aLogger
.log( LogLevel::FINER
, STR_LOG_DATE_PARAMETER
, parameterIndex
, x
);
200 ::osl::MutexGuard
aGuard( m_aMutex
);
201 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
203 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
204 createStatement(t
.pEnv
);
206 static jmethodID
mID(NULL
);
207 callVoidMethod("setDate", "(ILjava/sql/Date;)V", mID
, parameterIndex
, aT
.getJavaObject());
209 // -------------------------------------------------------------------------
212 void SAL_CALL
java_sql_PreparedStatement::setTime( sal_Int32 parameterIndex
, const ::com::sun::star::util::Time
& x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
214 m_aLogger
.log( LogLevel::FINER
, STR_LOG_TIME_PARAMETER
, parameterIndex
, x
);
215 ::osl::MutexGuard
aGuard( m_aMutex
);
216 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
218 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
219 createStatement(t
.pEnv
);
221 static jmethodID
mID(NULL
);
222 callVoidMethod("setTime", "(ILjava/sql/Time;)V", mID
, parameterIndex
, aT
.getJavaObject());
224 // -------------------------------------------------------------------------
226 void SAL_CALL
java_sql_PreparedStatement::setTimestamp( sal_Int32 parameterIndex
, const ::com::sun::star::util::DateTime
& x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
228 m_aLogger
.log( LogLevel::FINER
, STR_LOG_TIMESTAMP_PARAMETER
, parameterIndex
, x
);
229 ::osl::MutexGuard
aGuard( m_aMutex
);
230 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
232 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
233 createStatement(t
.pEnv
);
234 static jmethodID
mID(NULL
);
235 java_sql_Timestamp
aD(x
);
236 callVoidMethod("setTimestamp", "(ILjava/sql/Timestamp;)V", mID
, parameterIndex
, aD
.getJavaObject());
238 // -------------------------------------------------------------------------
239 void SAL_CALL
java_sql_PreparedStatement::setDouble( sal_Int32 parameterIndex
, double x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
241 m_aLogger
.log( LogLevel::FINER
, STR_LOG_DOUBLE_PARAMETER
, parameterIndex
, x
);
242 ::osl::MutexGuard
aGuard( m_aMutex
);
243 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
245 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
246 createStatement(t
.pEnv
);
247 static jmethodID
mID(NULL
);
248 callVoidMethod("setDouble", "(ID)V", mID
, parameterIndex
, x
);
250 // -------------------------------------------------------------------------
252 void SAL_CALL
java_sql_PreparedStatement::setFloat( sal_Int32 parameterIndex
, float x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
254 m_aLogger
.log( LogLevel::FINER
, STR_LOG_FLOAT_PARAMETER
, parameterIndex
, x
);
255 ::osl::MutexGuard
aGuard( m_aMutex
);
256 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
258 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
259 createStatement(t
.pEnv
);
260 static jmethodID
mID(NULL
);
261 callVoidMethod("setFloat", "(IF)V", mID
, parameterIndex
, x
);
263 // -------------------------------------------------------------------------
265 void SAL_CALL
java_sql_PreparedStatement::setInt( sal_Int32 parameterIndex
, sal_Int32 x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
267 m_aLogger
.log( LogLevel::FINER
, STR_LOG_INT_PARAMETER
, parameterIndex
, x
);
268 ::osl::MutexGuard
aGuard( m_aMutex
);
269 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
271 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
272 createStatement(t
.pEnv
);
273 static jmethodID
mID(NULL
);
274 callVoidMethod("setInt", "(II)V", mID
, parameterIndex
, x
);
276 // -------------------------------------------------------------------------
278 void SAL_CALL
java_sql_PreparedStatement::setLong( sal_Int32 parameterIndex
, sal_Int64 x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
280 m_aLogger
.log( LogLevel::FINER
, STR_LOG_LONG_PARAMETER
, parameterIndex
, x
);
281 ::osl::MutexGuard
aGuard( m_aMutex
);
282 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
284 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
285 createStatement(t
.pEnv
);
286 static jmethodID
mID(NULL
);
287 callVoidMethod("setLong", "(IJ)V", mID
, parameterIndex
, x
);
289 // -------------------------------------------------------------------------
291 void SAL_CALL
java_sql_PreparedStatement::setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
293 m_aLogger
.log( LogLevel::FINER
, STR_LOG_NULL_PARAMETER
, parameterIndex
, sqlType
);
294 ::osl::MutexGuard
aGuard( m_aMutex
);
295 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
297 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
298 createStatement(t
.pEnv
);
299 static jmethodID
mID(NULL
);
300 callVoidMethod("setNull", "(II)V", mID
, parameterIndex
, sqlType
);
302 // -------------------------------------------------------------------------
304 void SAL_CALL
java_sql_PreparedStatement::setClob( sal_Int32
/*parameterIndex*/, const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XClob
>& /*x*/ ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
306 ::dbtools::throwFeatureNotImplementedException( "XParameters::setClob", *this );
308 // -------------------------------------------------------------------------
310 void SAL_CALL
java_sql_PreparedStatement::setBlob( sal_Int32
/*parameterIndex*/, const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XBlob
>& /*x*/ ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
312 ::dbtools::throwFeatureNotImplementedException( "XParameters::setBlob", *this );
314 // -------------------------------------------------------------------------
316 void SAL_CALL
java_sql_PreparedStatement::setArray( sal_Int32
/*parameterIndex*/, const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XArray
>& /*x*/ ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
318 ::dbtools::throwFeatureNotImplementedException( "XParameters::setArray", *this );
320 // -------------------------------------------------------------------------
322 void SAL_CALL
java_sql_PreparedStatement::setRef( sal_Int32
/*parameterIndex*/, const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRef
>& /*x*/ ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
324 ::dbtools::throwFeatureNotImplementedException( "XParameters::setRef", *this );
326 // -------------------------------------------------------------------------
328 void SAL_CALL
java_sql_PreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex
, const ::com::sun::star::uno::Any
& x
, sal_Int32 targetSqlType
, sal_Int32 scale
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
330 m_aLogger
.log( LogLevel::FINER
, STR_LOG_OBJECT_NULL_PARAMETER
, parameterIndex
);
331 ::osl::MutexGuard
aGuard( m_aMutex
);
332 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
334 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
336 createStatement(t
.pEnv
);
338 // temporaere Variable initialisieren
339 static const char * cSignature
= "(ILjava/lang/Object;II)V";
340 static const char * cMethodName
= "setObject";
341 // Java-Call absetzen
342 static jmethodID
mID(NULL
);
343 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
347 switch(targetSqlType
)
349 case DataType::DECIMAL
:
350 case DataType::NUMERIC
:
352 ::std::auto_ptr
<java_math_BigDecimal
> pBigDecimal
;
355 pBigDecimal
.reset(new java_math_BigDecimal(nTemp
));
356 //setDouble(parameterIndex,nTemp);
363 const ::rtl::OUString sValue
= aValue
;
364 if ( sValue
.getLength() )
365 pBigDecimal
.reset(new java_math_BigDecimal(sValue
));
367 pBigDecimal
.reset(new java_math_BigDecimal(0.0));
369 //obj = convertwchar_tToJavaString(t.pEnv,::comphelper::getString(x));
370 t
.pEnv
->CallVoidMethod( object
, mID
, parameterIndex
,pBigDecimal
->getJavaObject(),targetSqlType
,scale
);
371 ThrowLoggedSQLException( m_aLogger
, t
.pEnv
, *this );
375 obj
= convertwchar_tToJavaString(t
.pEnv
,::comphelper::getString(x
));
378 t
.pEnv
->CallVoidMethod( object
, mID
, parameterIndex
,obj
,targetSqlType
,scale
);
379 t
.pEnv
->DeleteLocalRef(obj
);
380 ThrowLoggedSQLException( m_aLogger
, t
.pEnv
, *this );
385 // -------------------------------------------------------------------------
387 void SAL_CALL
java_sql_PreparedStatement::setObjectNull( sal_Int32 parameterIndex
, sal_Int32
/*sqlType*/, const ::rtl::OUString
& /*typeName*/ ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
389 m_aLogger
.log( LogLevel::FINER
, STR_LOG_OBJECT_NULL_PARAMETER
, parameterIndex
);
390 ::osl::MutexGuard
aGuard( m_aMutex
);
391 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
393 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
394 createStatement(t
.pEnv
);
395 static jmethodID
mID(NULL
);
396 callVoidMethod
<jobject
>("setObject", "(ILjava/lang/Object;)V", mID
, parameterIndex
, NULL
);
398 // -------------------------------------------------------------------------
400 void SAL_CALL
java_sql_PreparedStatement::setObject( sal_Int32 parameterIndex
, const ::com::sun::star::uno::Any
& x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
402 if(!::dbtools::implSetObject(this,parameterIndex
,x
))
404 const ::rtl::OUString
sError( m_pConnection
->getResources().getResourceStringWithSubstitution(
405 STR_UNKNOWN_PARA_TYPE
,
406 "$position$", ::rtl::OUString::valueOf(parameterIndex
)
408 ::dbtools::throwGenericSQLException(sError
,*this);
411 // -------------------------------------------------------------------------
413 void SAL_CALL
java_sql_PreparedStatement::setShort( sal_Int32 parameterIndex
, sal_Int16 x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
415 m_aLogger
.log( LogLevel::FINER
, STR_LOG_SHORT_PARAMETER
, parameterIndex
, x
);
416 ::osl::MutexGuard
aGuard( m_aMutex
);
417 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
419 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
420 createStatement(t
.pEnv
);
421 static jmethodID
mID(NULL
);
422 callVoidMethod("setShort", "(IS)V", mID
, parameterIndex
, x
);
424 // -------------------------------------------------------------------------
426 void SAL_CALL
java_sql_PreparedStatement::setBytes( sal_Int32 parameterIndex
, const ::com::sun::star::uno::Sequence
< sal_Int8
>& x
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
428 m_aLogger
.log( LogLevel::FINER
, STR_LOG_BYTES_PARAMETER
, parameterIndex
);
429 ::osl::MutexGuard
aGuard( m_aMutex
);
430 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
432 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
434 createStatement(t
.pEnv
);
436 // temporaere Variable initialisieren
437 static const char * cSignature
= "(I[B)V";
438 static const char * cMethodName
= "setBytes";
439 // Java-Call absetzen
440 static jmethodID
mID(NULL
);
441 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
442 jbyteArray pByteArray
= t
.pEnv
->NewByteArray(x
.getLength());
443 t
.pEnv
->SetByteArrayRegion(pByteArray
,0,x
.getLength(),(jbyte
*)x
.getConstArray());
444 t
.pEnv
->CallVoidMethod( object
, mID
, parameterIndex
,pByteArray
);
445 t
.pEnv
->DeleteLocalRef(pByteArray
);
446 ThrowLoggedSQLException( m_aLogger
, t
.pEnv
, *this );
449 // -------------------------------------------------------------------------
451 void SAL_CALL
java_sql_PreparedStatement::setCharacterStream( sal_Int32 parameterIndex
, const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
453 m_aLogger
.log( LogLevel::FINER
, STR_LOG_CHARSTREAM_PARAMETER
, parameterIndex
);
454 ::osl::MutexGuard
aGuard( m_aMutex
);
455 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
457 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
459 createStatement(t
.pEnv
);
461 // temporaere Variable initialisieren
462 static const char * cSignature
= "(ILjava/io/InputStream;I)V";
463 static const char * cMethodName
= "setCharacterStream";
464 // Java-Call absetzen
465 static jmethodID
mID(NULL
);
466 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
467 Sequence
< sal_Int8
> aSeq
;
469 x
->readBytes( aSeq
, length
);
470 sal_Int32 actualLength
= aSeq
.getLength();
473 jbyteArray pByteArray
= t
.pEnv
->NewByteArray( actualLength
);
474 t
.pEnv
->SetByteArrayRegion(pByteArray
,0,actualLength
,(jbyte
*)aSeq
.getConstArray());
475 args2
[0].l
= pByteArray
;
477 args2
[2].i
= actualLength
;
478 // temporaere Variable initialisieren
479 const char * cSignatureStream
= "([BII)V";
480 // Java-Call absetzen
481 jclass aClass
= t
.pEnv
->FindClass("java/io/CharArrayInputStream");
482 static jmethodID mID2
= NULL
;
484 mID2
= t
.pEnv
->GetMethodID( aClass
, "<init>", cSignatureStream
);
485 jobject tempObj
= NULL
;
487 tempObj
= t
.pEnv
->NewObjectA( aClass
, mID2
, args2
);
489 t
.pEnv
->CallVoidMethod( object
, mID
, parameterIndex
,tempObj
,actualLength
);
491 t
.pEnv
->DeleteLocalRef(pByteArray
);
492 t
.pEnv
->DeleteLocalRef(tempObj
);
493 t
.pEnv
->DeleteLocalRef(aClass
);
494 ThrowLoggedSQLException( m_aLogger
, t
.pEnv
, *this );
497 // -------------------------------------------------------------------------
499 void SAL_CALL
java_sql_PreparedStatement::setBinaryStream( sal_Int32 parameterIndex
, const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
501 m_aLogger
.log( LogLevel::FINER
, STR_LOG_BINARYSTREAM_PARAMETER
, parameterIndex
);
502 ::osl::MutexGuard
aGuard( m_aMutex
);
503 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
505 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
507 createStatement(t
.pEnv
);
508 // temporaere Variable initialisieren
509 static const char * cSignature
= "(ILjava/io/InputStream;I)V";
510 static const char * cMethodName
= "setBinaryStream";
511 // Java-Call absetzen
512 static jmethodID
mID(NULL
);
513 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
515 Sequence
< sal_Int8
> aSeq
;
517 x
->readBytes( aSeq
, length
);
518 sal_Int32 actualLength
= aSeq
.getLength();
521 jbyteArray pByteArray
= t
.pEnv
->NewByteArray(actualLength
);
522 t
.pEnv
->SetByteArrayRegion(pByteArray
,0,actualLength
,(jbyte
*)aSeq
.getConstArray());
523 args2
[0].l
= pByteArray
;
525 args2
[2].i
= (sal_Int32
)actualLength
;
527 // temporaere Variable initialisieren
528 const char * cSignatureStream
= "([BII)V";
529 // Java-Call absetzen
530 jclass aClass
= t
.pEnv
->FindClass("java/io/ByteArrayInputStream");
531 static jmethodID mID2
= NULL
;
533 mID2
= t
.pEnv
->GetMethodID( aClass
, "<init>", cSignatureStream
);
534 jobject tempObj
= NULL
;
536 tempObj
= t
.pEnv
->NewObjectA( aClass
, mID2
, args2
);
537 t
.pEnv
->CallVoidMethod( object
, mID
, parameterIndex
,tempObj
,(sal_Int32
)actualLength
);
539 t
.pEnv
->DeleteLocalRef(pByteArray
);
540 t
.pEnv
->DeleteLocalRef(tempObj
);
541 t
.pEnv
->DeleteLocalRef(aClass
);
542 ThrowLoggedSQLException( m_aLogger
, t
.pEnv
, *this );
546 // -------------------------------------------------------------------------
548 void SAL_CALL
java_sql_PreparedStatement::clearParameters( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
550 m_aLogger
.log( LogLevel::FINER
, STR_LOG_CLEAR_PARAMETERS
);
551 ::osl::MutexGuard
aGuard( m_aMutex
);
552 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
556 createStatement(t
.pEnv
);
558 static jmethodID
mID(NULL
);
559 callVoidMethod("clearParameters",mID
);
562 // -------------------------------------------------------------------------
563 void SAL_CALL
java_sql_PreparedStatement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
565 ::osl::MutexGuard
aGuard( m_aMutex
);
566 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
567 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
569 createStatement(t
.pEnv
);
570 static jmethodID
mID(NULL
);
571 callVoidMethod("clearBatch",mID
);
574 // -------------------------------------------------------------------------
576 void SAL_CALL
java_sql_PreparedStatement::addBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
578 ::osl::MutexGuard
aGuard( m_aMutex
);
579 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
580 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
582 createStatement(t
.pEnv
);
583 static jmethodID
mID(NULL
);
584 callVoidMethod("addBatch",mID
);
587 // -------------------------------------------------------------------------
589 ::com::sun::star::uno::Sequence
< sal_Int32
> SAL_CALL
java_sql_PreparedStatement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
591 ::osl::MutexGuard
aGuard( m_aMutex
);
592 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
593 ::com::sun::star::uno::Sequence
< sal_Int32
> aSeq
;
594 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
595 createStatement(t
.pEnv
);
596 static jmethodID
mID(NULL
);
597 jintArray out
= (jintArray
)callObjectMethod(t
.pEnv
,"executeBatch","()[I", mID
);
600 jboolean p
= sal_False
;
601 aSeq
.realloc(t
.pEnv
->GetArrayLength(out
));
602 memcpy(aSeq
.getArray(),t
.pEnv
->GetIntArrayElements(out
,&p
),aSeq
.getLength());
603 t
.pEnv
->DeleteLocalRef(out
);
607 // -------------------------------------------------------------------------
608 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> SAL_CALL
java_sql_PreparedStatement::getMetaData( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
610 ::osl::MutexGuard
aGuard( m_aMutex
);
611 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
612 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
613 createStatement(t
.pEnv
);
614 static jmethodID
mID(NULL
);
615 jobject out
= callObjectMethod(t
.pEnv
,"getMetaData","()Ljava/sql/ResultSetMetaData;", mID
);
617 return out
==0 ? 0 : new java_sql_ResultSetMetaData( t
.pEnv
, out
, m_aLogger
,*m_pConnection
);
619 // -----------------------------------------------------------------------------
620 void SAL_CALL
java_sql_PreparedStatement::acquire() throw()
622 OStatement_BASE2::acquire();
624 // -----------------------------------------------------------------------------
625 void SAL_CALL
java_sql_PreparedStatement::release() throw()
627 OStatement_BASE2::release();
629 // -----------------------------------------------------------------------------
630 void java_sql_PreparedStatement::createStatement(JNIEnv
* _pEnv
)
632 ::osl::MutexGuard
aGuard( m_aMutex
);
633 checkDisposed(java_sql_Statement_BASE::rBHelper
.bDisposed
);
635 if( !object
&& _pEnv
){
636 // temporaere Variable initialisieren
637 static const char * cSignature
= "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;";
638 static const char * cMethodName
= "prepareStatement";
641 // Parameter konvertieren
642 args
[0].l
= convertwchar_tToJavaString(_pEnv
,m_sSqlStatement
);
643 // Java-Call absetzen
645 static jmethodID
mID(NULL
);
647 mID
= _pEnv
->GetMethodID( m_pConnection
->getMyClass(), cMethodName
, cSignature
);
650 out
= _pEnv
->CallObjectMethod( m_pConnection
->getJavaObject(), mID
, args
[0].l
,m_nResultSetType
,m_nResultSetConcurrency
);
654 static const char * cSignature2
= "(Ljava/lang/String;)Ljava/sql/PreparedStatement;";
655 static jmethodID mID2
= NULL
;
657 mID2
= _pEnv
->GetMethodID( m_pConnection
->getMyClass(), cMethodName
, cSignature2
);OSL_ENSURE(mID
,"Unknown method id!");
659 out
= _pEnv
->CallObjectMethod( m_pConnection
->getJavaObject(), mID2
, args
[0].l
);
661 _pEnv
->DeleteLocalRef((jstring
)args
[0].l
);
662 ThrowLoggedSQLException( m_aLogger
, _pEnv
, *this );
664 object
= _pEnv
->NewGlobalRef( out
);
667 // -----------------------------------------------------------------------------