Branch data Line data Source code
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/Blob.hxx"
21 : : #include "java/tools.hxx"
22 : : #include "java/io/InputStream.hxx"
23 : : #include <connectivity/dbexception.hxx>
24 : :
25 : : #include <string.h>
26 : :
27 : : using namespace connectivity;
28 : : //**************************************************************
29 : : //************ Class: java.sql.Blob
30 : : //**************************************************************
31 : :
32 : : jclass java_sql_Blob::theClass = 0;
33 : 0 : java_sql_Blob::java_sql_Blob( JNIEnv * pEnv, jobject myObj )
34 : 0 : : java_lang_Object( pEnv, myObj )
35 : : {
36 : 0 : SDBThreadAttach::addRef();
37 : 0 : }
38 : 0 : java_sql_Blob::~java_sql_Blob()
39 : : {
40 : 0 : SDBThreadAttach::releaseRef();
41 : 0 : }
42 : :
43 : 0 : jclass java_sql_Blob::getMyClass() const
44 : : {
45 : : // the class must be fetched only once, therefore it's static
46 : 0 : if( !theClass )
47 : 0 : theClass = findMyClass("java/sql/Blob");
48 : 0 : return theClass;
49 : : }
50 : :
51 : 0 : sal_Int64 SAL_CALL java_sql_Blob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
52 : : {
53 : 0 : jlong out(0);
54 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
55 : :
56 : : {
57 : : // initialize temporary variable
58 : : static const char * cSignature = "()J";
59 : : static const char * cMethodName = "length";
60 : : // submit Java-Call
61 : : static jmethodID mID(NULL);
62 : 0 : obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
63 : 0 : out = t.pEnv->CallLongMethod( object, mID );
64 : 0 : ThrowSQLException(t.pEnv,*this);
65 : : } //t.pEnv
66 : 0 : return (sal_Int64)out;
67 : : }
68 : 0 : ::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)
69 : : {
70 : :
71 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
72 : 0 : ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
73 : : {
74 : : // initialize temporary variable
75 : : static const char * cSignature = "(JI)[B";
76 : : static const char * cMethodName = "getBytes";
77 : : // submit Java-Call
78 : : static jmethodID mID(NULL);
79 : 0 : obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
80 : 0 : jbyteArray out = (jbyteArray)t.pEnv->CallObjectMethod( object, mID,pos,count);
81 : 0 : ThrowSQLException(t.pEnv,*this);
82 : 0 : if(out)
83 : : {
84 : 0 : jboolean p = sal_False;
85 : 0 : aSeq.realloc(t.pEnv->GetArrayLength(out));
86 : 0 : memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength());
87 : 0 : t.pEnv->DeleteLocalRef(out);
88 : : }
89 : : } //t.pEnv
90 : : // WARNING: the caller becomes the owner of the returned pointer
91 : 0 : return aSeq;
92 : : }
93 : :
94 : 0 : ::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)
95 : : {
96 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
97 : : static jmethodID mID(NULL);
98 : 0 : jobject out = callObjectMethod(t.pEnv,"getBinaryStream","()Ljava/io/InputStream;", mID);
99 : : // WARNING: the caller becomes the owner of the returned pointer
100 : 0 : return out==0 ? 0 : new java_io_InputStream( t.pEnv, out );
101 : : }
102 : :
103 : 0 : 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)
104 : : {
105 : 0 : jlong out(0);
106 : 0 : SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
107 : :
108 : : {
109 : : // initialize temporary variable
110 : : static const char * cSignature = "([BI)J";
111 : : static const char * cMethodName = "position";
112 : : // submit Java-Call
113 : : static jmethodID mID(NULL);
114 : 0 : obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
115 : : // convert Parameter
116 : 0 : jbyteArray pByteArray = t.pEnv->NewByteArray(pattern.getLength());
117 : 0 : t.pEnv->SetByteArrayRegion(pByteArray,0,pattern.getLength(),(jbyte*)pattern.getConstArray());
118 : 0 : out = t.pEnv->CallLongMethod( object, mID, pByteArray,start );
119 : 0 : t.pEnv->DeleteLocalRef(pByteArray);
120 : 0 : ThrowSQLException(t.pEnv,*this);
121 : : } //t.pEnv
122 : 0 : return (sal_Int64)out;
123 : : }
124 : :
125 : 0 : 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)
126 : : {
127 : 0 : ::dbtools::throwFeatureNotImplementedException( "XBlob::positionOfBlob", *this );
128 : : // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore
129 : : // the pattern parameter. Since the effort for proper implementation is rather high - we would need
130 : : // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was
131 : : // unusable, anyway)
132 : : // #i57457#
133 : 0 : return 0;
134 : : }
135 : :
136 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|