1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
27cdf0e10cSrcweir #include <config.h>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "uno/mapping.hxx"
31cdf0e10cSrcweir #include "uno/environment.hxx"
32cdf0e10cSrcweir #include "cppuhelper/bootstrap.hxx"
33cdf0e10cSrcweir #include "cppuhelper/compbase1.hxx"
34cdf0e10cSrcweir #include "cppuhelper/component_context.hxx"
35cdf0e10cSrcweir #include "accesslog.hxx"
36cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
37cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
40cdf0e10cSrcweir #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
41cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
42cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
43cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
44cdf0e10cSrcweir #include <comphelper/types.hxx>
45cdf0e10cSrcweir #include "hsqldb/HStorageAccess.hxx"
46cdf0e10cSrcweir #include "hsqldb/HStorageMap.hxx"
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include "jvmaccess/virtualmachine.hxx"
49cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp"
50cdf0e10cSrcweir #include "diagnose_ex.h"
51cdf0e10cSrcweir
52cdf0e10cSrcweir using namespace ::com::sun::star::container;
53cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54cdf0e10cSrcweir using namespace ::com::sun::star::document;
55cdf0e10cSrcweir using namespace ::com::sun::star::embed;
56cdf0e10cSrcweir using namespace ::com::sun::star::io;
57cdf0e10cSrcweir using namespace ::com::sun::star::lang;
58cdf0e10cSrcweir using namespace ::connectivity::hsqldb;
59cdf0e10cSrcweir
60cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
61cdf0e10cSrcweir /*****************************************************************************/
62cdf0e10cSrcweir /* exception macros */
63cdf0e10cSrcweir
64cdf0e10cSrcweir #define ThrowException(env, type, msg) { \
65cdf0e10cSrcweir env->ThrowNew(env->FindClass(type), msg); }
66cdf0e10cSrcweir
67cdf0e10cSrcweir // -----------------------------------------------------------------------------
68cdf0e10cSrcweir /*
69cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
70cdf0e10cSrcweir * Method: openStream
71cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
72cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_openStream(JNIEnv * env,jobject,jstring name,jstring key,jint mode)73cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_openStream
74cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/, jstring name, jstring key, jint mode)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir #ifdef HSQLDB_DBG
77cdf0e10cSrcweir {
78cdf0e10cSrcweir OperationLogFile( env, name, "output" ).logOperation( "openStream" );
79cdf0e10cSrcweir LogFile( env, name, "output" ).create();
80cdf0e10cSrcweir }
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir StorageContainer::registerStream(env,name,key,mode);
83cdf0e10cSrcweir }
84cdf0e10cSrcweir /*
85cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
86cdf0e10cSrcweir * Method: write
87cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)V
88cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3BII(JNIEnv * env,jobject obj_this,jstring key,jstring name,jbyteArray buffer,jint off,jint len)89cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3BII
90cdf0e10cSrcweir (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer, jint off, jint len)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir #ifdef HSQLDB_DBG
93cdf0e10cSrcweir OperationLogFile( env, name, "output" ).logOperation( "write( byte[], int, int )" );
94cdf0e10cSrcweir
95cdf0e10cSrcweir DataLogFile aDataLog( env, name, "output" );
96cdf0e10cSrcweir write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len, &aDataLog );
97cdf0e10cSrcweir #else
98cdf0e10cSrcweir write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len );
99cdf0e10cSrcweir #endif
100cdf0e10cSrcweir }
101cdf0e10cSrcweir // -----------------------------------------------------------------------------
102cdf0e10cSrcweir /*
103cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
104cdf0e10cSrcweir * Method: write
105cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;[B)V
106cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3B(JNIEnv * env,jobject obj_this,jstring key,jstring name,jbyteArray buffer)107cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3B
108cdf0e10cSrcweir (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir #ifdef HSQLDB_DBG
111cdf0e10cSrcweir OperationLogFile( env, name, "output" ).logOperation( "write( byte[] )" );
112cdf0e10cSrcweir
113cdf0e10cSrcweir DataLogFile aDataLog( env, name, "output" );
114cdf0e10cSrcweir write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ), &aDataLog );
115cdf0e10cSrcweir #else
116cdf0e10cSrcweir write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ) );
117cdf0e10cSrcweir #endif
118cdf0e10cSrcweir }
119cdf0e10cSrcweir // -----------------------------------------------------------------------------
120cdf0e10cSrcweir /*
121cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
122cdf0e10cSrcweir * Method: close
123cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)V
124cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_close(JNIEnv * env,jobject,jstring key,jstring name)125cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_close
126cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir #ifdef HSQLDB_DBG
129cdf0e10cSrcweir OperationLogFile aOpLog( env, name, "output" );
130cdf0e10cSrcweir aOpLog.logOperation( "close" );
131cdf0e10cSrcweir
132cdf0e10cSrcweir LogFile aDataLog( env, name, "output" );
133cdf0e10cSrcweir #endif
134cdf0e10cSrcweir
135cdf0e10cSrcweir ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
136cdf0e10cSrcweir Reference< XOutputStream> xFlush = pHelper.get() ? pHelper->getOutputStream() : Reference< XOutputStream>();
137cdf0e10cSrcweir if ( xFlush.is() )
138cdf0e10cSrcweir try
139cdf0e10cSrcweir {
140cdf0e10cSrcweir xFlush->flush();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir catch(Exception&)
143cdf0e10cSrcweir {}
144cdf0e10cSrcweir
145cdf0e10cSrcweir #ifdef HSQLDB_DBG
146cdf0e10cSrcweir aDataLog.close();
147cdf0e10cSrcweir aOpLog.close();
148cdf0e10cSrcweir #endif
149cdf0e10cSrcweir StorageContainer::revokeStream(env,name,key);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir // -----------------------------------------------------------------------------
152cdf0e10cSrcweir /*
153cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
154cdf0e10cSrcweir * Method: write
155cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
156cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2I(JNIEnv * env,jobject obj_this,jstring key,jstring name,jint b)157cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2I
158cdf0e10cSrcweir (JNIEnv * env, jobject obj_this, jstring key, jstring name,jint b)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir #ifdef HSQLDB_DBG
161cdf0e10cSrcweir OperationLogFile( env, name, "output" ).logOperation( "write( int )" );
162cdf0e10cSrcweir
163cdf0e10cSrcweir DataLogFile aDataLog( env, name, "output" );
164cdf0e10cSrcweir write_to_storage_stream( env, obj_this, name, key, b, &aDataLog );
165cdf0e10cSrcweir #else
166cdf0e10cSrcweir write_to_storage_stream( env, obj_this, name, key, b );
167cdf0e10cSrcweir #endif
168cdf0e10cSrcweir }
169cdf0e10cSrcweir // -----------------------------------------------------------------------------
170cdf0e10cSrcweir /*
171cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
172cdf0e10cSrcweir * Method: flush
173cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)V
174cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_flush(JNIEnv * env,jobject,jstring key,jstring name)175cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_flush
176cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir OSL_UNUSED( env );
179cdf0e10cSrcweir OSL_UNUSED( key );
180cdf0e10cSrcweir OSL_UNUSED( name );
181cdf0e10cSrcweir #ifdef HSQLDB_DBG
182cdf0e10cSrcweir OperationLogFile( env, name, "output" ).logOperation( "flush" );
183cdf0e10cSrcweir
184cdf0e10cSrcweir ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key);
185cdf0e10cSrcweir ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name);
186cdf0e10cSrcweir #endif
187cdf0e10cSrcweir }
188cdf0e10cSrcweir // -----------------------------------------------------------------------------
189cdf0e10cSrcweir /*
190cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
191cdf0e10cSrcweir * Method: sync
192cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)V
193cdf0e10cSrcweir */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_sync(JNIEnv * env,jobject,jstring key,jstring name)194cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_sync
195cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir #ifdef HSQLDB_DBG
198cdf0e10cSrcweir OperationLogFile( env, name, "output" ).logOperation( "sync" );
199cdf0e10cSrcweir #endif
200cdf0e10cSrcweir ::boost::shared_ptr< StreamHelper > pStream = StorageContainer::getRegisteredStream( env, name, key );
201cdf0e10cSrcweir Reference< XOutputStream > xFlush = pStream.get() ? pStream->getOutputStream() : Reference< XOutputStream>();
202cdf0e10cSrcweir OSL_ENSURE( xFlush.is(), "StorageNativeOutputStream::sync: could not retrieve an output stream!" );
203cdf0e10cSrcweir if ( xFlush.is() )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir try
206cdf0e10cSrcweir {
207cdf0e10cSrcweir xFlush->flush();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir catch(Exception&)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir OSL_ENSURE( false, "StorageNativeOutputStream::sync: could not flush output stream!" );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir // -----------------------------------------------------------------------------
216