1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
31*cdf0e10cSrcweir #include <config.h>
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include "uno/mapping.hxx"
35*cdf0e10cSrcweir #include "uno/environment.hxx"
36*cdf0e10cSrcweir #include "cppuhelper/bootstrap.hxx"
37*cdf0e10cSrcweir #include "cppuhelper/compbase1.hxx"
38*cdf0e10cSrcweir #include "cppuhelper/component_context.hxx"
39*cdf0e10cSrcweir #include "accesslog.hxx"
40*cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
42*cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
47*cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
48*cdf0e10cSrcweir #include <comphelper/types.hxx>
49*cdf0e10cSrcweir #include "hsqldb/HStorageAccess.hxx"
50*cdf0e10cSrcweir #include "hsqldb/HStorageMap.hxx"
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include "jvmaccess/virtualmachine.hxx"
53*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp"
54*cdf0e10cSrcweir #include "diagnose_ex.h"
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace ::com::sun::star::container;
57*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
58*cdf0e10cSrcweir using namespace ::com::sun::star::document;
59*cdf0e10cSrcweir using namespace ::com::sun::star::embed;
60*cdf0e10cSrcweir using namespace ::com::sun::star::io;
61*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
62*cdf0e10cSrcweir using namespace ::connectivity::hsqldb;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
65*cdf0e10cSrcweir /*****************************************************************************/
66*cdf0e10cSrcweir /* exception macros */
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #define ThrowException(env, type, msg) { \
69*cdf0e10cSrcweir 	env->ThrowNew(env->FindClass(type), msg); }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir // -----------------------------------------------------------------------------
72*cdf0e10cSrcweir /*
73*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
74*cdf0e10cSrcweir  * Method:    openStream
75*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
76*cdf0e10cSrcweir  */
77*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_openStream
78*cdf0e10cSrcweir   (JNIEnv * env, jobject /*obj_this*/, jstring name, jstring key, jint mode)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir #ifdef HSQLDB_DBG
81*cdf0e10cSrcweir     {
82*cdf0e10cSrcweir         OperationLogFile( env, name, "output" ).logOperation( "openStream" );
83*cdf0e10cSrcweir         LogFile( env, name, "output" ).create();
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir #endif
86*cdf0e10cSrcweir 	StorageContainer::registerStream(env,name,key,mode);
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir /*
89*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
90*cdf0e10cSrcweir  * Method:    write
91*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)V
92*cdf0e10cSrcweir  */
93*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3BII
94*cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer, jint off, jint len)
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir #ifdef HSQLDB_DBG
97*cdf0e10cSrcweir     OperationLogFile( env, name, "output" ).logOperation( "write( byte[], int, int )" );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     DataLogFile aDataLog( env, name, "output" );
100*cdf0e10cSrcweir     write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len, &aDataLog );
101*cdf0e10cSrcweir #else
102*cdf0e10cSrcweir     write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len );
103*cdf0e10cSrcweir #endif
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir // -----------------------------------------------------------------------------
106*cdf0e10cSrcweir /*
107*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
108*cdf0e10cSrcweir  * Method:    write
109*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;[B)V
110*cdf0e10cSrcweir  */
111*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2_3B
112*cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer)
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir #ifdef HSQLDB_DBG
115*cdf0e10cSrcweir     OperationLogFile( env, name, "output" ).logOperation( "write( byte[] )" );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     DataLogFile aDataLog( env, name, "output" );
118*cdf0e10cSrcweir     write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ), &aDataLog );
119*cdf0e10cSrcweir #else
120*cdf0e10cSrcweir     write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ) );
121*cdf0e10cSrcweir #endif
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir // -----------------------------------------------------------------------------
124*cdf0e10cSrcweir /*
125*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
126*cdf0e10cSrcweir  * Method:    close
127*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
128*cdf0e10cSrcweir  */
129*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_close
130*cdf0e10cSrcweir   (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir #ifdef HSQLDB_DBG
133*cdf0e10cSrcweir     OperationLogFile aOpLog( env, name, "output" );
134*cdf0e10cSrcweir     aOpLog.logOperation( "close" );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     LogFile aDataLog( env, name, "output" );
137*cdf0e10cSrcweir #endif
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     ::boost::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
140*cdf0e10cSrcweir     Reference< XOutputStream> xFlush = pHelper.get() ? pHelper->getOutputStream() : Reference< XOutputStream>();
141*cdf0e10cSrcweir     if ( xFlush.is() )
142*cdf0e10cSrcweir         try
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             xFlush->flush();
145*cdf0e10cSrcweir         }
146*cdf0e10cSrcweir         catch(Exception&)
147*cdf0e10cSrcweir         {}
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir #ifdef HSQLDB_DBG
150*cdf0e10cSrcweir     aDataLog.close();
151*cdf0e10cSrcweir     aOpLog.close();
152*cdf0e10cSrcweir #endif
153*cdf0e10cSrcweir 	StorageContainer::revokeStream(env,name,key);
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir // -----------------------------------------------------------------------------
156*cdf0e10cSrcweir /*
157*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
158*cdf0e10cSrcweir  * Method:    write
159*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
160*cdf0e10cSrcweir  */
161*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_write__Ljava_lang_String_2Ljava_lang_String_2I
162*cdf0e10cSrcweir   (JNIEnv * env, jobject obj_this, jstring key, jstring name,jint b)
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir #ifdef HSQLDB_DBG
165*cdf0e10cSrcweir     OperationLogFile( env, name, "output" ).logOperation( "write( int )" );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     DataLogFile aDataLog( env, name, "output" );
168*cdf0e10cSrcweir     write_to_storage_stream( env, obj_this, name, key, b, &aDataLog );
169*cdf0e10cSrcweir #else
170*cdf0e10cSrcweir     write_to_storage_stream( env, obj_this, name, key, b );
171*cdf0e10cSrcweir #endif
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir // -----------------------------------------------------------------------------
174*cdf0e10cSrcweir /*
175*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
176*cdf0e10cSrcweir  * Method:    flush
177*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
178*cdf0e10cSrcweir  */
179*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_flush
180*cdf0e10cSrcweir   (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     OSL_UNUSED( env );
183*cdf0e10cSrcweir     OSL_UNUSED( key );
184*cdf0e10cSrcweir     OSL_UNUSED( name );
185*cdf0e10cSrcweir #ifdef HSQLDB_DBG
186*cdf0e10cSrcweir     OperationLogFile( env, name, "output" ).logOperation( "flush" );
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key);
189*cdf0e10cSrcweir     ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name);
190*cdf0e10cSrcweir #endif
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir // -----------------------------------------------------------------------------
193*cdf0e10cSrcweir /*
194*cdf0e10cSrcweir  * Class:     com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
195*cdf0e10cSrcweir  * Method:    sync
196*cdf0e10cSrcweir  * Signature: (Ljava/lang/String;Ljava/lang/String;)V
197*cdf0e10cSrcweir  */
198*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_sync
199*cdf0e10cSrcweir   (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir #ifdef HSQLDB_DBG
202*cdf0e10cSrcweir     OperationLogFile( env, name, "output" ).logOperation( "sync" );
203*cdf0e10cSrcweir #endif
204*cdf0e10cSrcweir     ::boost::shared_ptr< StreamHelper > pStream = StorageContainer::getRegisteredStream( env, name, key );
205*cdf0e10cSrcweir     Reference< XOutputStream > xFlush = pStream.get() ? pStream->getOutputStream() : Reference< XOutputStream>();
206*cdf0e10cSrcweir     OSL_ENSURE( xFlush.is(), "StorageNativeOutputStream::sync: could not retrieve an output stream!" );
207*cdf0e10cSrcweir     if ( xFlush.is() )
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         try
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             xFlush->flush();
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir         catch(Exception&)
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir             OSL_ENSURE( false, "StorageNativeOutputStream::sync: could not flush output stream!" );
216*cdf0e10cSrcweir         }
217*cdf0e10cSrcweir     }
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir // -----------------------------------------------------------------------------
220