update dev300-m58
[ooovba.git] / connectivity / source / drivers / hsqldb / StorageNativeOutputStream.cxx
bloba19aa4403303485622fc427d117fe3c8651de5b2
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: StorageNativeOutputStream.cxx,v $
10 * $Revision: 1.11 $
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 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
34 #include <config.h>
35 #endif
37 #include "uno/mapping.hxx"
38 #include "uno/environment.hxx"
39 #include "cppuhelper/bootstrap.hxx"
40 #include "cppuhelper/compbase1.hxx"
41 #include "cppuhelper/component_context.hxx"
42 #include "accesslog.hxx"
43 #include <com/sun/star/embed/XTransactedObject.hpp>
44 #include <comphelper/processfactory.hxx>
45 #include <com/sun/star/io/XStream.hpp>
46 #include <com/sun/star/container/XNameAccess.hpp>
47 #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
48 #include <com/sun/star/embed/XStorage.hpp>
49 #include <com/sun/star/embed/ElementModes.hpp>
50 #include <comphelper/stl_types.hxx>
51 #include <comphelper/types.hxx>
52 #include "hsqldb/HStorageAccess.hxx"
53 #include "hsqldb/HStorageMap.hxx"
55 #include "jvmaccess/virtualmachine.hxx"
56 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
57 #include "diagnose_ex.h"
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::document;
62 using namespace ::com::sun::star::embed;
63 using namespace ::com::sun::star::io;
64 using namespace ::com::sun::star::lang;
65 using namespace ::connectivity::hsqldb;
67 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
68 /*****************************************************************************/
69 /* exception macros */
71 #define ThrowException(env, type, msg) { \
72 env->ThrowNew(env->FindClass(type), msg); }
74 // -----------------------------------------------------------------------------
76 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
77 * Method: openStream
78 * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
80 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_openStream
81 (JNIEnv * env, jobject /*obj_this*/, jstring name, jstring key, jint mode)
83 #ifdef HSQLDB_DBG
85 OperationLogFile( env, name, "output" ).logOperation( "openStream" );
86 LogFile( env, name, "output" ).create();
88 #endif
89 StorageContainer::registerStream(env,name,key,mode);
92 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
93 * Method: write
94 * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)V
96 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3BII
97 (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer, jint off, jint len)
99 #ifdef HSQLDB_DBG
100 OperationLogFile( env, name, "output" ).logOperation( "write( byte[], int, int )" );
102 DataLogFile aDataLog( env, name, "output" );
103 write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len, &aDataLog );
104 #else
105 write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len );
106 #endif
108 // -----------------------------------------------------------------------------
110 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
111 * Method: write
112 * Signature: (Ljava/lang/String;Ljava/lang/String;[B)V
114 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3B
115 (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer)
117 #ifdef HSQLDB_DBG
118 OperationLogFile( env, name, "output" ).logOperation( "write( byte[] )" );
120 DataLogFile aDataLog( env, name, "output" );
121 write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ), &aDataLog );
122 #else
123 write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ) );
124 #endif
126 // -----------------------------------------------------------------------------
128 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
129 * Method: close
130 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
132 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_close
133 (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
135 #ifdef HSQLDB_DBG
136 OperationLogFile aOpLog( env, name, "output" );
137 aOpLog.logOperation( "close" );
139 LogFile aDataLog( env, name, "output" );
140 #endif
142 ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
143 Reference< XOutputStream> xFlush = pHelper.get() ? pHelper->getOutputStream() : Reference< XOutputStream>();
144 if ( xFlush.is() )
147 xFlush->flush();
149 catch(Exception&)
152 #ifdef HSQLDB_DBG
153 aDataLog.close();
154 aOpLog.close();
155 #endif
156 StorageContainer::revokeStream(env,name,key);
158 // -----------------------------------------------------------------------------
160 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
161 * Method: write
162 * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
164 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2I
165 (JNIEnv * env, jobject obj_this, jstring key, jstring name,jint b)
167 #ifdef HSQLDB_DBG
168 OperationLogFile( env, name, "output" ).logOperation( "write( int )" );
170 DataLogFile aDataLog( env, name, "output" );
171 write_to_storage_stream( env, obj_this, name, key, b, &aDataLog );
172 #else
173 write_to_storage_stream( env, obj_this, name, key, b );
174 #endif
176 // -----------------------------------------------------------------------------
178 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
179 * Method: flush
180 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
182 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_flush
183 (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
185 OSL_UNUSED( env );
186 OSL_UNUSED( key );
187 OSL_UNUSED( name );
188 #ifdef HSQLDB_DBG
189 OperationLogFile( env, name, "output" ).logOperation( "flush" );
191 ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key);
192 ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name);
193 #endif
195 // -----------------------------------------------------------------------------
197 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
198 * Method: sync
199 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
201 extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_sync
202 (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
204 #ifdef HSQLDB_DBG
205 OperationLogFile( env, name, "output" ).logOperation( "sync" );
206 #endif
207 ::boost::shared_ptr< StreamHelper > pStream = StorageContainer::getRegisteredStream( env, name, key );
208 Reference< XOutputStream > xFlush = pStream.get() ? pStream->getOutputStream() : Reference< XOutputStream>();
209 OSL_ENSURE( xFlush.is(), "StorageNativeOutputStream::sync: could not retrieve an output stream!" );
210 if ( xFlush.is() )
214 xFlush->flush();
216 catch(Exception&)
218 OSL_ENSURE( false, "StorageNativeOutputStream::sync: could not flush output stream!" );
222 // -----------------------------------------------------------------------------