1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "java/sql/Blob.hxx"
27 #include "java/tools.hxx"
28 #include "java/io/InputStream.hxx"
29 #ifndef _INC_MEMORY
30 //#include <memory.h>
31 #endif
32 #include <connectivity/dbexception.hxx>
33
34 #include <string.h>
35
36 using namespace connectivity;
37 //**************************************************************
38 //************ Class: java.sql.Blob
39 //**************************************************************
40
41 jclass java_sql_Blob::theClass = 0;
java_sql_Blob(JNIEnv * pEnv,jobject myObj)42 java_sql_Blob::java_sql_Blob( JNIEnv * pEnv, jobject myObj )
43 : java_lang_Object( pEnv, myObj )
44 {
45 SDBThreadAttach::addRef();
46 }
~java_sql_Blob()47 java_sql_Blob::~java_sql_Blob()
48 {
49 SDBThreadAttach::releaseRef();
50 }
51
getMyClass() const52 jclass java_sql_Blob::getMyClass() const
53 {
54 // die Klasse muss nur einmal geholt werden, daher statisch
55 if( !theClass )
56 theClass = findMyClass("java/sql/Blob");
57 return theClass;
58 }
59
length()60 sal_Int64 SAL_CALL java_sql_Blob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
61 {
62 jlong out(0);
63 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
64
65 {
66 // temporaere Variable initialisieren
67 static const char * cSignature = "()J";
68 static const char * cMethodName = "length";
69 // Java-Call absetzen
70 static jmethodID mID(NULL);
71 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
72 out = t.pEnv->CallLongMethod( object, mID );
73 ThrowSQLException(t.pEnv,*this);
74 } //t.pEnv
75 return (sal_Int64)out;
76 }
getBytes(sal_Int64 pos,sal_Int32 count)77 ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL java_sql_Blob::getBytes( sal_Int64 pos, sal_Int32 count ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
78 {
79
80 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
81 ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
82 {
83 // temporaere Variable initialisieren
84 static const char * cSignature = "(JI)[B";
85 static const char * cMethodName = "getBytes";
86 // Java-Call absetzen
87 static jmethodID mID(NULL);
88 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
89 jbyteArray out = (jbyteArray)t.pEnv->CallObjectMethod( object, mID,pos,count);
90 ThrowSQLException(t.pEnv,*this);
91 if(out)
92 {
93 jboolean p = sal_False;
94 aSeq.realloc(t.pEnv->GetArrayLength(out));
95 memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength());
96 t.pEnv->DeleteLocalRef(out);
97 }
98 } //t.pEnv
99 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
100 return aSeq;
101 }
102
getBinaryStream()103 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_Blob::getBinaryStream( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
104 {
105 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
106 static jmethodID mID(NULL);
107 jobject out = callObjectMethod(t.pEnv,"getBinaryStream","()Ljava/io/InputStream;", mID);
108 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
109 return out==0 ? 0 : new java_io_InputStream( t.pEnv, out );
110 }
111
position(const::com::sun::star::uno::Sequence<sal_Int8> & pattern,sal_Int64 start)112 sal_Int64 SAL_CALL java_sql_Blob::position( const ::com::sun::star::uno::Sequence< sal_Int8 >& pattern, sal_Int64 start ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
113 {
114 jlong out(0);
115 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
116
117 {
118 // temporaere Variable initialisieren
119 static const char * cSignature = "([BI)J";
120 static const char * cMethodName = "position";
121 // Java-Call absetzen
122 static jmethodID mID(NULL);
123 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
124 // Parameter konvertieren
125 jbyteArray pByteArray = t.pEnv->NewByteArray(pattern.getLength());
126 t.pEnv->SetByteArrayRegion(pByteArray,0,pattern.getLength(),(jbyte*)pattern.getConstArray());
127 out = t.pEnv->CallLongMethod( object, mID, pByteArray,start );
128 t.pEnv->DeleteLocalRef(pByteArray);
129 ThrowSQLException(t.pEnv,*this);
130 } //t.pEnv
131 return (sal_Int64)out;
132 }
133
positionOfBlob(const::com::sun::star::uno::Reference<::com::sun::star::sdbc::XBlob> &,sal_Int64)134 sal_Int64 SAL_CALL java_sql_Blob::positionOfBlob( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& /*pattern*/, sal_Int64 /*start*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
135 {
136 ::dbtools::throwFeatureNotImplementedException( "XBlob::positionOfBlob", *this );
137 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore
138 // the pattern parameter. Since the effort for proper implementation is rather high - we would need
139 // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was
140 // unusable, anyway)
141 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com
142 return 0;
143 }
144
145