2010-10-27 13:11:31 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-12 22:04:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 15:18:56 +00:00
|
|
|
#ifndef _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
|
|
|
|
#define _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
|
|
|
|
|
|
|
|
#include <cstdarg>
|
2005-01-21 15:44:24 +00:00
|
|
|
#include <osl/thread.h>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <com/sun/star/sdbc/SQLException.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2013-01-16 15:16:05 +02:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <osl/diagnose.h>
|
2003-04-24 12:23:29 +00:00
|
|
|
#include <jvmaccess/virtualmachine.hxx>
|
2009-04-23 10:42:05 +00:00
|
|
|
#include <functional>
|
2004-11-09 11:17:08 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2003-04-24 12:23:29 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
//=====================================================================
|
|
|
|
|
|
|
|
#ifdef HAVE_64BIT_POINTERS
|
|
|
|
#error "no 64 bit pointer"
|
|
|
|
#endif //HAVE_64BIT_POINTERS
|
|
|
|
|
2007-06-27 13:37:56 +00:00
|
|
|
namespace comphelper
|
|
|
|
{
|
|
|
|
class ResourceBasedEventLogger;
|
|
|
|
}
|
2003-04-24 12:23:29 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
namespace connectivity
|
|
|
|
{
|
2004-11-09 11:17:08 +00:00
|
|
|
typedef ::boost::shared_ptr< jvmaccess::VirtualMachine::AttachGuard> TGuard;
|
2000-09-18 15:18:56 +00:00
|
|
|
class SDBThreadAttach
|
|
|
|
{
|
2005-01-21 15:44:24 +00:00
|
|
|
jvmaccess::VirtualMachine::AttachGuard m_aGuard;
|
2003-04-24 12:23:29 +00:00
|
|
|
SDBThreadAttach(SDBThreadAttach&);
|
2009-04-23 10:42:05 +00:00
|
|
|
SDBThreadAttach& operator= (SDBThreadAttach&);
|
2000-09-18 15:18:56 +00:00
|
|
|
public:
|
|
|
|
SDBThreadAttach();
|
|
|
|
~SDBThreadAttach();
|
|
|
|
|
2003-04-24 12:23:29 +00:00
|
|
|
JNIEnv* pEnv;
|
2004-11-09 11:17:08 +00:00
|
|
|
static void addRef();
|
|
|
|
static void releaseRef();
|
2007-11-21 14:07:27 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
JNIEnv& env() const
|
|
|
|
{
|
|
|
|
// according to the documentation of jvmaccess::VirtualMachine::AttachGuard, our env is never
|
|
|
|
// NULL, so why bothering with pointer checks?
|
|
|
|
return *pEnv;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
};
|
|
|
|
//=====================================================================
|
2009-04-23 10:42:05 +00:00
|
|
|
//=====================================================================
|
2000-09-18 15:18:56 +00:00
|
|
|
class java_lang_Object
|
|
|
|
{
|
2012-03-01 02:27:38 +01:00
|
|
|
// operator= and the copy ctor are forbidden
|
2009-04-23 10:42:05 +00:00
|
|
|
java_lang_Object& operator= (java_lang_Object&);
|
|
|
|
java_lang_Object(java_lang_Object&);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
protected:
|
2012-03-01 02:27:38 +01:00
|
|
|
// The Java handle to this class
|
2000-09-18 15:18:56 +00:00
|
|
|
jobject object;
|
|
|
|
|
2012-03-01 02:27:38 +01:00
|
|
|
// Class definiton
|
|
|
|
// New in SJ2:
|
|
|
|
static jclass theClass; // The class needs to be requested only once!
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2009-04-23 10:42:05 +00:00
|
|
|
virtual jclass getMyClass() const;
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
public:
|
2012-03-01 02:27:38 +01:00
|
|
|
// Ctor that should be used for the derived classes
|
2000-09-18 15:18:56 +00:00
|
|
|
java_lang_Object( JNIEnv * pEnv, jobject myObj );
|
2012-03-01 02:27:38 +01:00
|
|
|
|
|
|
|
// The actual ctor
|
2013-01-16 15:16:05 +02:00
|
|
|
java_lang_Object();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
virtual ~java_lang_Object();
|
|
|
|
|
|
|
|
void saveRef( JNIEnv * pEnv, jobject myObj );
|
|
|
|
jobject getJavaObject() const { return object; }
|
|
|
|
java_lang_Object * GetWrapper() { return this; }
|
2004-11-09 11:17:08 +00:00
|
|
|
void clearObject(JNIEnv& rEnv);
|
|
|
|
void clearObject();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
virtual OUString toString() const;
|
2007-06-27 13:37:56 +00:00
|
|
|
|
|
|
|
static void ThrowSQLException(JNIEnv * pEnv,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> & _rContext);
|
|
|
|
static void ThrowLoggedSQLException(
|
|
|
|
const ::comphelper::ResourceBasedEventLogger& _rLogger,
|
|
|
|
JNIEnv* pEnvironment,
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext
|
|
|
|
);
|
2003-04-24 12:23:29 +00:00
|
|
|
|
2013-01-16 15:16:05 +02:00
|
|
|
static ::rtl::Reference< jvmaccess::VirtualMachine > getVM(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext=NULL);
|
2009-04-23 10:42:05 +00:00
|
|
|
|
|
|
|
static jclass findMyClass(const char* _pClassName);
|
|
|
|
void obtainMethodId(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const;
|
|
|
|
|
|
|
|
sal_Bool callBooleanMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const;
|
|
|
|
sal_Bool callBooleanMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
|
|
|
|
jobject callResultSetMethod( JNIEnv& _rEnv, const char* _pMethodName, jmethodID& _inout_MethodID ) const;
|
|
|
|
sal_Int32 callIntMethod( const char* _pMethodName, jmethodID& _inout_MethodID,bool _bIgnoreException = false ) const;
|
|
|
|
sal_Int32 callIntMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
|
2013-04-07 12:06:47 +02:00
|
|
|
sal_Int32 callIntMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID,const OUString& _nArgument ) const;
|
|
|
|
OUString callStringMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const;
|
|
|
|
OUString callStringMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const;
|
2009-04-23 10:42:05 +00:00
|
|
|
void callVoidMethod( const char* _pMethodName, jmethodID& _inout_MethodID) const;
|
|
|
|
void callVoidMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument,bool _bIgnoreException = false ) const;
|
2014-02-18 10:53:46 +01:00
|
|
|
void callVoidMethodWithBoolArg( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument,bool _bIgnoreException = false ) const;
|
2013-04-07 12:06:47 +02:00
|
|
|
void callVoidMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID, const OUString& _nArgument ) const;
|
2009-04-23 10:42:05 +00:00
|
|
|
jobject callObjectMethod( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID ) const;
|
|
|
|
jobject callObjectMethodWithIntArg( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const;
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
T callMethodWithIntArg(T (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) ,const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const
|
|
|
|
{
|
|
|
|
SDBThreadAttach t;
|
|
|
|
obtainMethodId(t.pEnv, _pMethodName,_pSignature, _inout_MethodID);
|
|
|
|
T out = (t.pEnv->*pCallMethod)( object, _inout_MethodID,_nArgument);
|
|
|
|
ThrowSQLException( t.pEnv, NULL );
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
void callVoidMethod(const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID,sal_Int32 _nArgument, const T& _aValue) const
|
|
|
|
{
|
|
|
|
SDBThreadAttach t;
|
|
|
|
obtainMethodId(t.pEnv, _pMethodName,_pSignature, _inout_MethodID);
|
|
|
|
t.pEnv->CallVoidMethod( object, _inout_MethodID,_nArgument,_aValue);
|
|
|
|
ThrowSQLException( t.pEnv, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif //_CONNECTIVITY_JAVA_LANG_OBJJECT_HXX_
|
|
|
|
|
|
|
|
|
2010-10-27 13:11:31 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|