LibreOffice Module connectivity (master) 1
Object.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#pragma once
20
21#include <com/sun/star/uno/XComponentContext.hpp>
23
24#ifdef HAVE_64BIT_POINTERS
25#error "no 64 bit pointer"
26#endif //HAVE_64BIT_POINTERS
27
28namespace comphelper
29{
30 class EventLogger;
31}
32
33namespace connectivity
34{
36 {
40 public:
43
44 JNIEnv* pEnv;
45 static void addRef();
46 static void releaseRef();
47
48 public:
49 JNIEnv& env() const
50 {
51 // according to the documentation of jvmaccess::VirtualMachine::AttachGuard, our env is never
52 // NULL, so why bothering with pointer checks?
53 return *pEnv;
54 }
55 };
56
57
59 {
62
63 protected:
64 // The Java handle to this class
65 jobject object;
66
67 // Class definition
68 // New in SJ2:
69 static jclass theClass; // The class needs to be requested only once!
70
71 virtual jclass getMyClass() const;
72
73 public:
74 // Ctor that should be used for the derived classes
75 java_lang_Object( JNIEnv * pEnv, jobject myObj );
76
77 // The actual ctor
79
80 virtual ~java_lang_Object() COVERITY_NOEXCEPT_FALSE;
81
82 void saveRef( JNIEnv * pEnv, jobject myObj );
83 jobject getJavaObject() const { return object; }
84 void clearObject(JNIEnv& rEnv);
85 void clearObject();
86
87 OUString toString() const;
88
89 static void ThrowSQLException(JNIEnv * pEnv,const css::uno::Reference< css::uno::XInterface> & _rContext);
90 static void ThrowLoggedSQLException(
91 const ::comphelper::EventLogger& _rLogger,
92 JNIEnv* pEnvironment,
93 const css::uno::Reference< css::uno::XInterface >& _rxContext
94 );
95 static void ThrowRuntimeException(JNIEnv * pEnv,const css::uno::Reference< css::uno::XInterface> & _rContext);
96
97 static ::rtl::Reference< jvmaccess::VirtualMachine > getVM(const css::uno::Reference< css::uno::XComponentContext >& _rxContext=nullptr);
98
99 static jclass findMyClass(const char* _pClassName);
100 void obtainMethodId_throwSQL(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const;
101 void obtainMethodId_throwRuntime(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const;
102
103 bool callBooleanMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const;
104 bool callBooleanMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
105 jobject callResultSetMethod( JNIEnv& _rEnv, const char* _pMethodName, jmethodID& _inout_MethodID ) const;
106 sal_Int32 callIntMethod_ThrowSQL(const char* _pMethodName, jmethodID& _inout_MethodID) const;
107 sal_Int32 callIntMethod_ThrowRuntime(const char* _pMethodName, jmethodID& _inout_MethodID) const;
108 sal_Int32 callIntMethodWithIntArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
109 sal_Int32 callIntMethodWithIntArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
110 sal_Int32 callIntMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID,const OUString& _nArgument ) const;
111 OUString callStringMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const;
112 OUString callStringMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const;
113 void callVoidMethod_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID) const;
114 void callVoidMethod_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID) const;
115 void callVoidMethodWithIntArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
116 void callVoidMethodWithIntArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const;
117 void callVoidMethodWithBoolArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument ) const;
118 void callVoidMethodWithBoolArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument ) const;
119 void callVoidMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID, const OUString& _nArgument ) const;
120 jobject callObjectMethod( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID ) const;
121 jobject callObjectMethodWithIntArg( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const;
122
123 template< typename T >
124 T callMethodWithIntArg(T (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) ,const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const
125 {
127 obtainMethodId_throwSQL(t.pEnv, _pMethodName,_pSignature, _inout_MethodID);
128 T out = (t.pEnv->*pCallMethod)( object, _inout_MethodID,_nArgument);
129 ThrowSQLException( t.pEnv, nullptr );
130 return out;
131 }
132
133 template< typename T >
134 void callVoidMethod_ThrowSQL(const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID,sal_Int32 _nArgument, const T& _aValue) const
135 {
137 obtainMethodId_throwSQL(t.pEnv, _pMethodName,_pSignature, _inout_MethodID);
138 t.pEnv->CallVoidMethod( object, _inout_MethodID,_nArgument,_aValue);
139 ThrowSQLException( t.pEnv, nullptr );
140 }
141
142
143 };
144}
145
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
jvmaccess::VirtualMachine::AttachGuard m_aGuard
Definition: Object.hxx:37
JNIEnv & env() const
Definition: Object.hxx:49
static void releaseRef()
Definition: Object.cxx:81
SDBThreadAttach(SDBThreadAttach const &)=delete
SDBThreadAttach & operator=(SDBThreadAttach const &)=delete
jobject callObjectMethod(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:404
jobject callResultSetMethod(JNIEnv &_rEnv, const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:279
virtual ~java_lang_Object() COVERITY_NOEXCEPT_FALSE
Definition: Object.cxx:115
sal_Int32 callIntMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:286
virtual jclass getMyClass() const
Definition: Object.cxx:93
bool callBooleanMethod(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:252
OUString toString() const
Definition: Object.cxx:150
sal_Int32 callIntMethodWithStringArg(const char *_pMethodName, jmethodID &_inout_MethodID, const OUString &_nArgument) const
Definition: Object.cxx:444
java_lang_Object(java_lang_Object const &)=delete
static ::rtl::Reference< jvmaccess::VirtualMachine > getVM(const css::uno::Reference< css::uno::XComponentContext > &_rxContext=nullptr)
Definition: Object.cxx:49
void callVoidMethod_ThrowSQL(const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID, sal_Int32 _nArgument, const T &_aValue) const
Definition: Object.hxx:134
void callVoidMethodWithStringArg(const char *_pMethodName, jmethodID &_inout_MethodID, const OUString &_nArgument) const
Definition: Object.cxx:432
void callVoidMethod_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:330
sal_Int32 callIntMethodWithIntArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:308
void callVoidMethodWithIntArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:352
void saveRef(JNIEnv *pEnv, jobject myObj)
Definition: Object.cxx:142
void callVoidMethodWithBoolArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, bool _nArgument) const
Definition: Object.cxx:384
void callVoidMethodWithIntArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:363
T callMethodWithIntArg(T(JNIEnv::*pCallMethod)(jobject obj, jmethodID methodID,...), const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.hxx:124
OUString callStringMethod(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:394
jobject callObjectMethodWithIntArg(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:415
bool callBooleanMethodWithIntArg(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:266
OUString callStringMethodWithIntArg(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:424
static void ThrowSQLException(JNIEnv *pEnv, const css::uno::Reference< css::uno::XInterface > &_rContext)
Definition: Object.cxx:208
sal_Int32 callIntMethod_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:297
static void ThrowLoggedSQLException(const ::comphelper::EventLogger &_rLogger, JNIEnv *pEnvironment, const css::uno::Reference< css::uno::XInterface > &_rxContext)
Definition: Object.cxx:197
jobject getJavaObject() const
Definition: Object.hxx:83
static jclass findMyClass(const char *_pClassName)
Definition: Object.cxx:466
void obtainMethodId_throwRuntime(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:240
static void ThrowRuntimeException(JNIEnv *pEnv, const css::uno::Reference< css::uno::XInterface > &_rContext)
Definition: Object.cxx:215
java_lang_Object & operator=(java_lang_Object const &)=delete
void callVoidMethod_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID) const
Definition: Object.cxx:341
void callVoidMethodWithBoolArg_ThrowSQL(const char *_pMethodName, jmethodID &_inout_MethodID, bool _nArgument) const
Definition: Object.cxx:374
sal_Int32 callIntMethodWithIntArg_ThrowRuntime(const char *_pMethodName, jmethodID &_inout_MethodID, sal_Int32 _nArgument) const
Definition: Object.cxx:319
void obtainMethodId_throwSQL(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:229