LibreOffice Module connectivity (master) 1
jdbc/Clob.cxx
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
20#include <java/sql/Clob.hxx>
21#include <java/tools.hxx>
22#include <java/io/Reader.hxx>
24#include <osl/diagnose.h>
25
26using namespace connectivity;
27
28//************ Class: java.sql.Clob
29
30
31jclass java_sql_Clob::theClass = nullptr;
32
33java_sql_Clob::java_sql_Clob( JNIEnv * pEnv, jobject myObj )
34 : java_lang_Object( pEnv, myObj )
35{
37}
39{
41}
42
44{
45 // the class must be fetched only once, therefore static
46 if( !theClass )
47 theClass = findMyClass("java/sql/Clob");
48 return theClass;
49}
50
51sal_Int64 SAL_CALL java_sql_Clob::length( )
52{
53 jlong out(0);
54 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
55
56 {
57 // initialize temporary variable
58 static const char * const cSignature = "()J";
59 static const char * const cMethodName = "length";
60 // execute Java-Call
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);
65 } //t.pEnv
66 return static_cast<sal_Int64>(out);
67}
68
69OUString SAL_CALL java_sql_Clob::getSubString( sal_Int64 pos, sal_Int32 subStringLength )
70{
71 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
72 OUString aStr;
73 {
74 // initialize temporary variable
75 static const char * const cSignature = "(JI)Ljava/lang/String;";
76 static const char * const cMethodName = "getSubString";
77 // execute Java-Call
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);
83 } //t.pEnv
84 // WARNING: the caller becomes the owner of the returned pointer
85 return aStr;
86}
87
88css::uno::Reference< css::io::XInputStream > SAL_CALL java_sql_Clob::getCharacterStream( )
89{
91 static jmethodID mID(nullptr);
92 jobject out = callObjectMethod(t.pEnv,"getCharacterStream","()Ljava/io/Reader;", mID);
93
94 // WARNING: the caller becomes the owner of the returned pointer
95 return out==nullptr ? nullptr : new java_io_Reader( t.pEnv, out );
96}
97
98sal_Int64 SAL_CALL java_sql_Clob::position( const OUString& searchstr, sal_Int32 start )
99{
100 jlong out(0);
101 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!");
102
103 {
104 jvalue args[1];
105 // convert Parameter
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";
110 // execute Java-Call
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));
116 } //t.pEnv
117 return static_cast<sal_Int64>(out);
118}
119
120sal_Int64 SAL_CALL java_sql_Clob::positionOfClob( const css::uno::Reference< css::sdbc::XClob >& /*pattern*/, sal_Int64 /*start*/ )
121{
122 ::dbtools::throwFeatureNotImplementedSQLException( "XClob::positionOfClob", *this );
123 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore
124 // the pattern parameter. Since the effort for proper implementation is rather high - we would need
125 // to translated pattern into a byte[] -, we defer this functionality for the moment (hey, it was
126 // unusable, anyway)
127 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com
128 return 0;
129}
130
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
static void releaseRef()
Definition: Object.cxx:81
jobject callObjectMethod(JNIEnv *pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:404
static void ThrowSQLException(JNIEnv *pEnv, const css::uno::Reference< css::uno::XInterface > &_rContext)
Definition: Object.cxx:208
static jclass findMyClass(const char *_pClassName)
Definition: Object.cxx:466
void obtainMethodId_throwSQL(JNIEnv *_pEnv, const char *_pMethodName, const char *_pSignature, jmethodID &_inout_MethodID) const
Definition: Object.cxx:229
virtual ~java_sql_Clob() override
Definition: jdbc/Clob.cxx:38
virtual OUString SAL_CALL getSubString(sal_Int64 pos, sal_Int32 length) override
Definition: jdbc/Clob.cxx:69
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream() override
Definition: jdbc/Clob.cxx:88
virtual sal_Int64 SAL_CALL position(const OUString &searchstr, sal_Int32 start) override
Definition: jdbc/Clob.cxx:98
virtual sal_Int64 SAL_CALL positionOfClob(const css::uno::Reference< css::sdbc::XClob > &pattern, sal_Int64 start) override
Definition: jdbc/Clob.cxx:120
virtual sal_Int64 SAL_CALL length() override
Definition: jdbc/Clob.cxx:51
virtual jclass getMyClass() const override
Definition: jdbc/Clob.cxx:43
aStr
OUString JavaString2String(JNIEnv *pEnv, jstring Str)
Definition: tools.cxx:162
jstring convertwchar_tToJavaString(JNIEnv *pEnv, const OUString &Temp)
Definition: tools.cxx:93
void throwFeatureNotImplementedSQLException(const OUString &_rFeatureName, const Reference< XInterface > &_rxContext, const Any &_rNextException)
args
size_t pos