merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / jdbc / Blob.cxx
blobe94e50ebf3793820d3ca4df61980bf67f7ed6b07
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Blob.cxx,v $
10 * $Revision: 1.12 $
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/Blob.hxx"
34 #include "java/tools.hxx"
35 #include "java/io/InputStream.hxx"
36 #ifndef _INC_MEMORY
37 //#include <memory.h>
38 #endif
39 #include <connectivity/dbexception.hxx>
41 #include <string.h>
43 using namespace connectivity;
44 //**************************************************************
45 //************ Class: java.sql.Blob
46 //**************************************************************
48 jclass java_sql_Blob::theClass = 0;
49 java_sql_Blob::java_sql_Blob( JNIEnv * pEnv, jobject myObj )
50 : java_lang_Object( pEnv, myObj )
52 SDBThreadAttach::addRef();
54 java_sql_Blob::~java_sql_Blob()
56 SDBThreadAttach::releaseRef();
59 jclass java_sql_Blob::getMyClass() const
61 // die Klasse muss nur einmal geholt werden, daher statisch
62 if( !theClass )
63 theClass = findMyClass("java/sql/Blob");
64 return theClass;
67 sal_Int64 SAL_CALL java_sql_Blob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
69 jlong out(0);
70 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
73 // temporaere Variable initialisieren
74 static const char * cSignature = "()J";
75 static const char * cMethodName = "length";
76 // Java-Call absetzen
77 static jmethodID mID(NULL);
78 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
79 out = t.pEnv->CallLongMethod( object, mID );
80 ThrowSQLException(t.pEnv,*this);
81 } //t.pEnv
82 return (sal_Int64)out;
84 ::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)
87 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
88 ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
90 // temporaere Variable initialisieren
91 static const char * cSignature = "(JI)[B";
92 static const char * cMethodName = "getBytes";
93 // Java-Call absetzen
94 static jmethodID mID(NULL);
95 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
96 jbyteArray out = (jbyteArray)t.pEnv->CallObjectMethod( object, mID,pos,count);
97 ThrowSQLException(t.pEnv,*this);
98 if(out)
100 jboolean p = sal_False;
101 aSeq.realloc(t.pEnv->GetArrayLength(out));
102 memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength());
103 t.pEnv->DeleteLocalRef(out);
105 } //t.pEnv
106 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
107 return aSeq;
110 ::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)
112 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
113 static jmethodID mID(NULL);
114 jobject out = callObjectMethod(t.pEnv,"getBinaryStream","()Ljava/io/InputStream;", mID);
115 // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
116 return out==0 ? 0 : new java_io_InputStream( t.pEnv, out );
119 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)
121 jlong out(0);
122 SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java Enviroment geloescht worden!");
125 // temporaere Variable initialisieren
126 static const char * cSignature = "([BI)J";
127 static const char * cMethodName = "position";
128 // Java-Call absetzen
129 static jmethodID mID(NULL);
130 obtainMethodId(t.pEnv, cMethodName,cSignature, mID);
131 // Parameter konvertieren
132 jbyteArray pByteArray = t.pEnv->NewByteArray(pattern.getLength());
133 t.pEnv->SetByteArrayRegion(pByteArray,0,pattern.getLength(),(jbyte*)pattern.getConstArray());
134 out = t.pEnv->CallLongMethod( object, mID, pByteArray,start );
135 t.pEnv->DeleteLocalRef(pByteArray);
136 ThrowSQLException(t.pEnv,*this);
137 } //t.pEnv
138 return (sal_Int64)out;
141 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)
143 ::dbtools::throwFeatureNotImplementedException( "XBlob::positionOfBlob", *this );
144 // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore
145 // the pattern parameter. Since the effort for proper implementation is rather high - we would need
146 // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was
147 // unusable, anyway)
148 // 2005-11-15 / #i57457# / frank.schoenheit@sun.com
149 return 0;