1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <java/sql/Clob.hxx>
21 #include <java/tools.hxx>
22 #include <java/io/Reader.hxx>
23 #include <connectivity/dbexception.hxx>
24 #include <osl/diagnose.h>
26 using namespace connectivity
;
28 //************ Class: java.sql.Clob
31 jclass
java_sql_Clob::theClass
= nullptr;
33 java_sql_Clob::java_sql_Clob( JNIEnv
* pEnv
, jobject myObj
)
34 : java_lang_Object( pEnv
, myObj
)
36 SDBThreadAttach::addRef();
38 java_sql_Clob::~java_sql_Clob()
40 SDBThreadAttach::releaseRef();
43 jclass
java_sql_Clob::getMyClass() const
45 // the class must be fetched only once, therefore static
47 theClass
= findMyClass("java/sql/Clob");
51 sal_Int64 SAL_CALL
java_sql_Clob::length( )
54 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java environment has been deleted!");
57 // initialize temporary variable
58 static const char * const cSignature
= "()J";
59 static const char * const cMethodName
= "length";
61 static jmethodID
mID(nullptr);
62 obtainMethodId_throwSQL(t
.pEnv
, cMethodName
,cSignature
, mID
);
63 out
= t
.pEnv
->CallLongMethod( object
, mID
);
64 ThrowSQLException(t
.pEnv
,*this);
66 return static_cast<sal_Int64
>(out
);
69 OUString SAL_CALL
java_sql_Clob::getSubString( sal_Int64 pos
, sal_Int32 subStringLength
)
71 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java environment has been deleted!");
74 // initialize temporary variable
75 static const char * const cSignature
= "(JI)Ljava/lang/String;";
76 static const char * const cMethodName
= "getSubString";
78 static jmethodID
mID(nullptr);
79 obtainMethodId_throwSQL(t
.pEnv
, cMethodName
,cSignature
, mID
);
80 jstring out
= static_cast<jstring
>(t
.pEnv
->CallObjectMethod( object
, mID
,pos
,subStringLength
));
81 ThrowSQLException(t
.pEnv
,*this);
82 aStr
= JavaString2String(t
.pEnv
,out
);
84 // WARNING: the caller becomes the owner of the returned pointer
88 css::uno::Reference
< css::io::XInputStream
> SAL_CALL
java_sql_Clob::getCharacterStream( )
91 static jmethodID
mID(nullptr);
92 jobject out
= callObjectMethod(t
.pEnv
,"getCharacterStream","()Ljava/io/Reader;", mID
);
94 // WARNING: the caller becomes the owner of the returned pointer
95 return out
==nullptr ? nullptr : new java_io_Reader( t
.pEnv
, out
);
98 sal_Int64 SAL_CALL
java_sql_Clob::position( const OUString
& searchstr
, sal_Int32 start
)
101 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java environment has been deleted!");
106 args
[0].l
= convertwchar_tToJavaString(t
.pEnv
,searchstr
);
107 // initialize temporary Variable
108 static const char * const cSignature
= "(Ljava/lang/String;I)J";
109 static const char * const cMethodName
= "position";
111 static jmethodID
mID(nullptr);
112 obtainMethodId_throwSQL(t
.pEnv
, cMethodName
,cSignature
, mID
);
113 out
= t
.pEnv
->CallLongMethod( object
, mID
, args
[0].l
,start
);
114 ThrowSQLException(t
.pEnv
,*this);
115 t
.pEnv
->DeleteLocalRef(static_cast<jstring
>(args
[0].l
));
117 return static_cast<sal_Int64
>(out
);
120 sal_Int64 SAL_CALL
java_sql_Clob::positionOfClob( const css::uno::Reference
< css::sdbc::XClob
>& /*pattern*/, sal_Int64
/*start*/ )
122 ::dbtools::throwFeatureNotImplementedSQLException( u
"XClob::positionOfClob"_ustr
, *this );
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */