1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Clob.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "java/sql/Clob.hxx"
34 #include "java/tools.hxx"
35 #include "java/io/Reader.hxx"
36 #include <connectivity/dbexception.hxx>
37 using namespace connectivity
;
38 //**************************************************************
39 //************ Class: java.sql.Clob
40 //**************************************************************
42 jclass
java_sql_Clob::theClass
= 0;
44 java_sql_Clob::java_sql_Clob( JNIEnv
* pEnv
, jobject myObj
)
45 : java_lang_Object( pEnv
, myObj
)
47 SDBThreadAttach::addRef();
49 java_sql_Clob::~java_sql_Clob()
51 SDBThreadAttach::releaseRef();
54 jclass
java_sql_Clob::getMyClass() const
56 // die Klasse muss nur einmal geholt werden, daher statisch
58 theClass
= findMyClass("java/sql/Clob");
62 sal_Int64 SAL_CALL
java_sql_Clob::length( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
65 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
68 // temporaere Variable initialisieren
69 static const char * cSignature
= "()J";
70 static const char * cMethodName
= "length";
72 static jmethodID
mID(NULL
);
73 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
74 out
= t
.pEnv
->CallLongMethod( object
, mID
);
75 ThrowSQLException(t
.pEnv
,*this);
77 return (sal_Int64
)out
;
80 ::rtl::OUString SAL_CALL
java_sql_Clob::getSubString( sal_Int64 pos
, sal_Int32 subStringLength
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
82 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
85 // temporaere Variable initialisieren
86 static const char * cSignature
= "(JI)Ljava/lang/String;";
87 static const char * cMethodName
= "getSubString";
89 static jmethodID
mID(NULL
);
90 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
91 jstring out
= (jstring
)t
.pEnv
->CallObjectMethod( object
, mID
,pos
,subStringLength
);
92 ThrowSQLException(t
.pEnv
,*this);
93 aStr
= JavaString2String(t
.pEnv
,out
);
95 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
99 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
java_sql_Clob::getCharacterStream( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
102 static jmethodID
mID(NULL
);
103 jobject out
= callObjectMethod(t
.pEnv
,"getCharacterStream","()Ljava/io/Reader;", mID
);
105 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
106 return out
==0 ? 0 : new java_io_Reader( t
.pEnv
, out
);
109 sal_Int64 SAL_CALL
java_sql_Clob::position( const ::rtl::OUString
& searchstr
, sal_Int32 start
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
112 SDBThreadAttach t
; OSL_ENSURE(t
.pEnv
,"Java Enviroment geloescht worden!");
116 // Parameter konvertieren
117 args
[0].l
= convertwchar_tToJavaString(t
.pEnv
,searchstr
);
118 // temporaere Variable initialisieren
119 static const char * cSignature
= "(Ljava/lang/String;I)J";
120 static const char * cMethodName
= "position";
121 // Java-Call absetzen
122 static jmethodID
mID(NULL
);
123 obtainMethodId(t
.pEnv
, cMethodName
,cSignature
, mID
);
124 out
= t
.pEnv
->CallLongMethod( object
, mID
, args
[0].l
,start
);
125 ThrowSQLException(t
.pEnv
,*this);
126 t
.pEnv
->DeleteLocalRef((jstring
)args
[0].l
);
128 return (sal_Int64
)out
;
131 sal_Int64 SAL_CALL
java_sql_Clob::positionOfClob( const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XClob
>& /*pattern*/, sal_Int64
/*start*/ ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
133 ::dbtools::throwFeatureNotImplementedException( "XClob::positionOfClob", *this );
134 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore
135 // the pattern parameter. Since the effort for proper implementation is rather high - we would need
136 // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was
138 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com