1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "java/sql/JStatement.hxx"
#include "java/sql/ResultSet.hxx"
#include "java/sql/Connection.hxx"
#include "java/sql/SQLWarning.hxx"
#include "java/tools.hxx"
#include "java/ContextClassLoader.hxx"
#include <comphelper/property.hxx>
#include <com/sun/star/lang/DisposedException.hpp>
#include <cppuhelper/typeprovider.hxx>
#include <comphelper/sequence.hxx>
#include "TConnection.hxx"
#include <comphelper/types.hxx>
#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
#include <com/sun/star/sdbc/ResultSetType.hpp>
#include <com/sun/star/sdbc/FetchDirection.hpp>
#include "resource/jdbc_log.hrc"
#include <algorithm>
#include <string.h>
using namespace ::comphelper;
using namespace connectivity;
using namespace ::cppu;
//------------------------------------------------------------------------------
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
//------------------------------------------------------------------------------
//**************************************************************
//************ Class: java.sql.Statement
//**************************************************************
jclass java_sql_Statement_Base::theClass = 0;
// -------------------------------------------------------------------------
java_sql_Statement_Base::java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon )
:java_sql_Statement_BASE(m_aMutex)
,java_lang_Object( pEnv, NULL )
,OPropertySetHelper(java_sql_Statement_BASE::rBHelper)
,m_pConnection( &_rCon )
,m_aLogger( _rCon.getLogger(), java::sql::ConnectionLog::STATEMENT )
,m_nResultSetConcurrency(ResultSetConcurrency::READ_ONLY)
,m_nResultSetType(ResultSetType::FORWARD_ONLY)
,m_bEscapeProcessing(sal_True)
,rBHelper(java_sql_Statement_BASE::rBHelper)
{
m_pConnection->acquire();
}
//------------------------------------------------------------------------------
java_sql_Statement_Base::~java_sql_Statement_Base()
{
}
//------------------------------------------------------------------------------
void SAL_CALL OStatement_BASE2::disposing()
{
::osl::MutexGuard aGuard(m_aMutex);
if ( object )
{
static jmethodID mID(NULL);
callVoidMethod("close",mID);
}
::comphelper::disposeComponent(m_xGeneratedStatement);
if (m_pConnection)
m_pConnection->release();
m_pConnection = NULL;
dispose_ChildImpl();
java_sql_Statement_Base::disposing();
}
// -------------------------------------------------------------------------
jclass java_sql_Statement_Base::getMyClass() const
{
// the class must be fetched only once, therefore static
if( !theClass )
theClass = findMyClass("java/sql/Statement");
return theClass;
}
// -----------------------------------------------------------------------------
void SAL_CALL java_sql_Statement_Base::disposing(void)
{
m_aLogger.log( LogLevel::FINE, STR_LOG_CLOSING_STATEMENT );
java_sql_Statement_BASE::disposing();
clearObject();
}
// -------------------------------------------------------------------------
void SAL_CALL OStatement_BASE2::release() throw()
{
relase_ChildImpl();
}
// -------------------------------------------------------------------------
Any SAL_CALL java_sql_Statement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
{
if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) )
return Any();
Any aRet( java_sql_Statement_BASE::queryInterface(rType) );
return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
}
// -------------------------------------------------------------------------
Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( ) throw(RuntimeException)
{
::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes();
if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() )
{
::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(),
::getCppuType( (const Reference< XGeneratedResultSet > *)0 ));
aOldTypes.realloc(aOldTypes.getLength() - 1);
}
return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
}
// -----------------------------------------------------------------------------
Reference< XResultSet > SAL_CALL java_sql_Statement_Base::getGeneratedValues( ) throw (SQLException, RuntimeException)
{
m_aLogger.log( LogLevel::FINE, STR_LOG_GENERATED_VALUES );
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
jobject out(0);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
// initialize temporary Variable
try
{
static jmethodID mID(NULL);
out = callResultSetMethod(t.env(),"getGeneratedKeys",mID);
}
catch(const SQLException&)
{
// ignore
}
Reference< XResultSet > xRes;
if ( !out )
{
OSL_ENSURE( m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
if ( m_pConnection )
{
::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
if ( sStmt.getLength() )
{
m_aLogger.log( LogLevel::FINER, STR_LOG_GENERATED_VALUES_FALLBACK, sStmt );
::comphelper::disposeComponent(m_xGeneratedStatement);
m_xGeneratedStatement = m_pConnection->createStatement();
xRes = m_xGeneratedStatement->executeQuery(sStmt);
}
}
}
else
xRes = new java_sql_ResultSet( t.pEnv, out, m_aLogger,*m_pConnection, this );
return xRes;
}
// -------------------------------------------------------------------------
void SAL_CALL java_sql_Statement_Base::cancel( ) throw(RuntimeException)
{
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethod("cancel",mID);
}
// -------------------------------------------------------------------------
void SAL_CALL java_sql_Statement_Base::close( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
{
::osl::MutexGuard aGuard( m_aMutex );
if (java_sql_Statement_BASE::rBHelper.bDisposed)
throw DisposedException();
}
dispose();
}
// -------------------------------------------------------------------------
void SAL_CALL java_sql_Statement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
{
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethod("clearBatch",mID);
} //t.pEnv
}
// -------------------------------------------------------------------------
sal_Bool SAL_CALL java_sql_Statement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
{
m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_STATEMENT, sql );
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
jboolean out(sal_False);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
{
createStatement(t.pEnv);
m_sSqlStatement = sql;
// initialize temporary Variable
static const char * cSignature = "(Ljava/lang/String;)Z";
static const char * cMethodName = "execute";
// Java-Call
static jmethodID mID(NULL);
obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
// convert Parameter
jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
{
jdbc::ContextClassLoaderScope ccl( t.env(),
m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
m_aLogger,
*this
);
out = t.pEnv->CallBooleanMethod( object, mID, str.get() );
ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
}
} //t.pEnv
return out;
}
// -------------------------------------------------------------------------
Reference< XResultSet > SAL_CALL java_sql_Statement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_QUERY, sql );
jobject out(0);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
{
createStatement(t.pEnv);
m_sSqlStatement = sql;
// initialize temporary variable
static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/ResultSet;";
static const char * cMethodName = "executeQuery";
// Java-Call
static jmethodID mID(NULL);
obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
// convert Parameter
jdbc::LocalRef< jstring > str( t.env(), convertwchar_tToJavaString( t.pEnv, sql ) );
{
jdbc::ContextClassLoaderScope ccl( t.env(),
m_pConnection ? m_pConnection->getDriverClassLoader() : jdbc::GlobalRef< jobject >(),
m_aLogger,
*this
);
out = t.pEnv->CallObjectMethod( object, mID, str.get() );
ThrowLoggedSQLException( m_aLogger, t.pEnv, *this );
}
} //t.pEnv
// WARNING: the caller becomes the owner of the returned pointer
return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
}
// -------------------------------------------------------------------------
Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection( ) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
return (Reference< XConnection >)m_pConnection;
}
// -------------------------------------------------------------------------
Any SAL_CALL java_sql_Statement::queryInterface( const Type & rType ) throw(RuntimeException)
{
Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
return aRet.hasValue() ? aRet : java_sql_Statement_Base::queryInterface(rType);
}
// -------------------------------------------------------------------------
void SAL_CALL java_sql_Statement::addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
{
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithStringArg("addBatch",mID,sql);
} //t.pEnv
}
// -------------------------------------------------------------------------
Sequence< sal_Int32 > SAL_CALL java_sql_Statement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
Sequence< sal_Int32 > aSeq;
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
jintArray out = (jintArray)callObjectMethod(t.pEnv,"executeBatch","()[I", mID);
if (out)
{
jboolean p = sal_False;
aSeq.realloc(t.pEnv->GetArrayLength(out));
memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength());
t.pEnv->DeleteLocalRef(out);
}
return aSeq;
}
// -------------------------------------------------------------------------
sal_Int32 SAL_CALL java_sql_Statement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINE, STR_LOG_EXECUTE_UPDATE, sql );
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
m_sSqlStatement = sql;
static jmethodID mID(NULL);
return callIntMethodWithStringArg("executeUpdate",mID,sql);
}
// -------------------------------------------------------------------------
Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Statement_Base::getResultSet( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
jobject out = callResultSetMethod(t.env(),"getResultSet",mID);
// WARNING: the caller becomes the owner of the returned pointer
return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out, m_aLogger, *m_pConnection,this );
}
// -------------------------------------------------------------------------
sal_Int32 SAL_CALL java_sql_Statement_Base::getUpdateCount( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
sal_Int32 out = callIntMethod("getUpdateCount",mID);
m_aLogger.log( LogLevel::FINER, STR_LOG_UPDATE_COUNT, (sal_Int32)out );
return out;
}
// -------------------------------------------------------------------------
sal_Bool SAL_CALL java_sql_Statement_Base::getMoreResults( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return callBooleanMethod( "getMoreResults", mID );
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
Any SAL_CALL java_sql_Statement_Base::getWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
SDBThreadAttach t;
createStatement(t.pEnv);
static jmethodID mID(NULL);
jobject out = callObjectMethod(t.pEnv,"getWarnings","()Ljava/sql/SQLWarning;", mID);
// WARNING: the caller becomes the owner of the returned pointer
if( out )
{
java_sql_SQLWarning_BASE warn_base( t.pEnv, out );
return makeAny(
static_cast< starsdbc::SQLException >(
java_sql_SQLWarning(warn_base,*(::cppu::OWeakObject*)this)));
}
return Any();
}
// -------------------------------------------------------------------------
void SAL_CALL java_sql_Statement_Base::clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t;
{
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethod("clearWarnings",mID);
}
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getQueryTimeOut() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getQueryTimeOut",mID);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getMaxRows() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getMaxRows",mID);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getResultSetConcurrency() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getResultSetConcurrency",mID,m_nResultSetConcurrency);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getResultSetType() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getResultSetType",mID,m_nResultSetType);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault)
{
sal_Int32 out = _nDefault;
if ( object )
out = callIntMethod(_pMethodName,_inout_MethodID,true);
return out;
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID)
{
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
return callIntMethod(_pMethodName,_inout_MethodID,true);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getFetchDirection() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getFetchDirection",mID);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getFetchSize() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getFetchSize",mID);
}
//------------------------------------------------------------------------------
sal_Int32 java_sql_Statement_Base::getMaxFieldSize() throw(SQLException, RuntimeException)
{
static jmethodID mID(NULL);
return impl_getProperty("getMaxFieldSize",mID);
}
//------------------------------------------------------------------------------
::rtl::OUString java_sql_Statement_Base::getCursorName() throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
try
{
return callStringMethod("getCursorName",mID);
}
catch(const SQLException&)
{
}
return ::rtl::OUString();
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setQueryTimeOut(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithIntArg("setQueryTimeOut",mID,_par0,true);
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setEscapeProcessing(sal_Bool _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINE, STR_LOG_SET_ESCAPE_PROCESSING, _par0 );
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
m_bEscapeProcessing = _par0;
createStatement( t.pEnv );
static jmethodID mID(NULL);
callVoidMethodWithBoolArg("setEscapeProcessing",mID,_par0,true);
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithIntArg("setMaxRows",mID,_par0,true);
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_CONCURRENCY, (sal_Int32)_par0 );
m_nResultSetConcurrency = _par0;
clearObject();
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINE, STR_LOG_RESULT_SET_TYPE, (sal_Int32)_par0 );
m_nResultSetType = _par0;
clearObject();
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_DIRECTION, (sal_Int32)_par0 );
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithIntArg("setFetchDirection",mID,_par0,true);
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
m_aLogger.log( LogLevel::FINER, STR_LOG_FETCH_SIZE, (sal_Int32)_par0 );
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithIntArg("setFetchSize",mID,_par0,true);
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithIntArg("setMaxFieldSize",mID,_par0,true);
}
//------------------------------------------------------------------------------
void java_sql_Statement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
{
createStatement(t.pEnv);
static jmethodID mID(NULL);
callVoidMethodWithStringArg("setCursorName",mID,_par0);
} //t.pEnv
}
// -------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* java_sql_Statement_Base::createArrayHelper( ) const
{
Sequence< Property > aProps(10);
Property* pProperties = aProps.getArray();
sal_Int32 nPos = 0;
DECL_PROP0(CURSORNAME, ::rtl::OUString);
DECL_BOOL_PROP0(ESCAPEPROCESSING);
DECL_PROP0(FETCHDIRECTION,sal_Int32);
DECL_PROP0(FETCHSIZE, sal_Int32);
DECL_PROP0(MAXFIELDSIZE,sal_Int32);
DECL_PROP0(MAXROWS, sal_Int32);
DECL_PROP0(QUERYTIMEOUT,sal_Int32);
DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
DECL_PROP0(RESULTSETTYPE,sal_Int32);
DECL_BOOL_PROP0(USEBOOKMARKS);
return new ::cppu::OPropertyArrayHelper(aProps);
}
// -------------------------------------------------------------------------
::cppu::IPropertyArrayHelper & java_sql_Statement_Base::getInfoHelper()
{
return *const_cast<java_sql_Statement_Base*>(this)->getArrayHelper();
}
// -------------------------------------------------------------------------
sal_Bool java_sql_Statement_Base::convertFastPropertyValue(
Any & rConvertedValue,
Any & rOldValue,
sal_Int32 nHandle,
const Any& rValue )
throw (::com::sun::star::lang::IllegalArgumentException)
{
switch(nHandle)
{
case PROPERTY_ID_QUERYTIMEOUT:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
case PROPERTY_ID_MAXFIELDSIZE:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
case PROPERTY_ID_MAXROWS:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
case PROPERTY_ID_CURSORNAME:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
case PROPERTY_ID_RESULTSETCONCURRENCY:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
case PROPERTY_ID_RESULTSETTYPE:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
case PROPERTY_ID_FETCHDIRECTION:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
case PROPERTY_ID_FETCHSIZE:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
case PROPERTY_ID_ESCAPEPROCESSING:
return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
case PROPERTY_ID_USEBOOKMARKS:
// return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
default:
;
}
return sal_False;
}
// -------------------------------------------------------------------------
void java_sql_Statement_Base::setFastPropertyValue_NoBroadcast(
sal_Int32 nHandle,
const Any& rValue
)
throw (Exception)
{
switch(nHandle)
{
case PROPERTY_ID_QUERYTIMEOUT:
setQueryTimeOut(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_MAXFIELDSIZE:
setMaxFieldSize(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_MAXROWS:
setMaxRows(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_CURSORNAME:
setCursorName(comphelper::getString(rValue));
break;
case PROPERTY_ID_RESULTSETCONCURRENCY:
setResultSetConcurrency(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_RESULTSETTYPE:
setResultSetType(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_FETCHDIRECTION:
setFetchDirection(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_FETCHSIZE:
setFetchSize(comphelper::getINT32(rValue));
break;
case PROPERTY_ID_ESCAPEPROCESSING:
setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
break;
case PROPERTY_ID_USEBOOKMARKS:
// return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
default:
;
}
}
// -------------------------------------------------------------------------
void java_sql_Statement_Base::getFastPropertyValue(
Any& rValue,
sal_Int32 nHandle
) const
{
java_sql_Statement_Base* THIS = const_cast<java_sql_Statement_Base*>(this);
try
{
switch(nHandle)
{
case PROPERTY_ID_QUERYTIMEOUT:
rValue <<= THIS->getQueryTimeOut();
break;
case PROPERTY_ID_MAXFIELDSIZE:
rValue <<= THIS->getMaxFieldSize();
break;
case PROPERTY_ID_MAXROWS:
rValue <<= THIS->getMaxRows();
break;
case PROPERTY_ID_CURSORNAME:
rValue <<= THIS->getCursorName();
break;
case PROPERTY_ID_RESULTSETCONCURRENCY:
rValue <<= THIS->getResultSetConcurrency();
break;
case PROPERTY_ID_RESULTSETTYPE:
rValue <<= THIS->getResultSetType();
break;
case PROPERTY_ID_FETCHDIRECTION:
rValue <<= THIS->getFetchDirection();
break;
case PROPERTY_ID_FETCHSIZE:
rValue <<= THIS->getFetchSize();
break;
case PROPERTY_ID_ESCAPEPROCESSING:
rValue <<= (sal_Bool)m_bEscapeProcessing;
break;
case PROPERTY_ID_USEBOOKMARKS:
default:
;
}
}
catch(const Exception&)
{
}
}
// -------------------------------------------------------------------------
jclass java_sql_Statement::theClass = 0;
java_sql_Statement::~java_sql_Statement()
{}
jclass java_sql_Statement::getMyClass() const
{
// the class must be fetched only once, therefore static
if( !theClass )
theClass = findMyClass("java/sql/Statement");
return theClass;
}
// -----------------------------------------------------------------------------
void java_sql_Statement::createStatement(JNIEnv* _pEnv)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed);
if( _pEnv && !object ){
// initialize temporary variable
static const char * cSignature = "(II)Ljava/sql/Statement;";
static const char * cMethodName = "createStatement";
// Java-Call
jobject out = NULL;
static jmethodID mID(NULL);
if ( !mID )
mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature );
if( mID ){
out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency );
} //mID
else
{
static const char * cSignature2 = "()Ljava/sql/Statement;";
static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!");
if( mID2 ){
out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2);
} //mID
}
ThrowLoggedSQLException( m_aLogger, _pEnv, *this );
if ( out )
object = _pEnv->NewGlobalRef( out );
} //_pEnv
}
// -----------------------------------------------------------------------------
IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement");
// -----------------------------------------------------------------------------
void SAL_CALL java_sql_Statement_Base::acquire() throw()
{
java_sql_Statement_BASE::acquire();
}
// -----------------------------------------------------------------------------
void SAL_CALL java_sql_Statement_Base::release() throw()
{
java_sql_Statement_BASE::release();
}
// -----------------------------------------------------------------------------
void SAL_CALL java_sql_Statement::acquire() throw()
{
OStatement_BASE2::acquire();
}
// -----------------------------------------------------------------------------
void SAL_CALL java_sql_Statement::release() throw()
{
OStatement_BASE2::release();
}
// -----------------------------------------------------------------------------
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL java_sql_Statement_Base::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
{
return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
}
// -----------------------------------------------------------------------------
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|