Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / jdbc / Blob.cxx
blobc07a74da14b64aed16b8857bca9c81d95ca86334
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "java/sql/Blob.hxx"
30 #include "java/tools.hxx"
31 #include "java/io/InputStream.hxx"
32 #include <connectivity/dbexception.hxx>
34 #include <string.h>
36 using namespace connectivity;
37 //**************************************************************
38 //************ Class: java.sql.Blob
39 //**************************************************************
41 jclass java_sql_Blob::theClass = 0;
42 java_sql_Blob::java_sql_Blob( JNIEnv * pEnv, jobject myObj )
43 : java_lang_Object( pEnv, myObj )
45 SDBThreadAttach::addRef();
47 java_sql_Blob::~java_sql_Blob()
49 SDBThreadAttach::releaseRef();
52 jclass java_sql_Blob::getMyClass() const
54 // the class must be fetched only once, therefore it's static
55 if( !theClass )
56 theClass = findMyClass("java/sql/Blob");
57 return theClass;
60 sal_Int64 SAL_CALL java_sql_Blob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
62 jlong out(0);
63 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
66 // initialize temporary variable
67 static const char * cSignature = "()J";
68 static const char * cMethodName = "length";
69 // submit Java-Call
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;
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)
80 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
81 ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
83 // initialize temporary variable
84 static const char * cSignature = "(JI)[B";
85 static const char * cMethodName = "getBytes";
86 // submit Java-Call
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)
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);
98 } //t.pEnv
99 // WARNING: the caller becomes the owner of the returned pointer
100 return aSeq;
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)
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 // WARNING: the caller becomes the owner of the returned pointer
109 return out==0 ? 0 : new java_io_InputStream( t.pEnv, out );
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)
114 jlong out(0);
115 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
118 // initialize temporary variable
119 static const char * cSignature = "([BI)J";
120 static const char * cMethodName = "position";
121 // submit Java-Call
122 static jmethodID mID(NULL);
123 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
124 // convert Parameter
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;
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)
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 // #i57457#
142 return 0;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */