1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StorageNativeOutputStream.cxx,v $
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
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
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
)
85 OperationLogFile( env
, name
, "output" ).logOperation( "openStream" );
86 LogFile( env
, name
, "output" ).create();
89 StorageContainer::registerStream(env
,name
,key
,mode
);
92 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
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
)
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
);
105 write_to_storage_stream_from_buffer( env
, obj_this
, name
, key
, buffer
, off
, len
);
108 // -----------------------------------------------------------------------------
110 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
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
)
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
);
123 write_to_storage_stream_from_buffer( env
, obj_this
, name
, key
, buffer
, 0, env
->GetArrayLength( buffer
) );
126 // -----------------------------------------------------------------------------
128 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
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
)
136 OperationLogFile
aOpLog( env
, name
, "output" );
137 aOpLog
.logOperation( "close" );
139 LogFile
aDataLog( env
, name
, "output" );
142 ::boost::shared_ptr
<StreamHelper
> pHelper
= StorageContainer::getRegisteredStream(env
,name
,key
);
143 Reference
< XOutputStream
> xFlush
= pHelper
.get() ? pHelper
->getOutputStream() : Reference
< XOutputStream
>();
156 StorageContainer::revokeStream(env
,name
,key
);
158 // -----------------------------------------------------------------------------
160 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
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
)
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
);
173 write_to_storage_stream( env
, obj_this
, name
, key
, b
);
176 // -----------------------------------------------------------------------------
178 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
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
)
189 OperationLogFile( env
, name
, "output" ).logOperation( "flush" );
191 ::rtl::OUString sKey
= StorageContainer::jstring2ustring(env
,key
);
192 ::rtl::OUString sName
= StorageContainer::jstring2ustring(env
,name
);
195 // -----------------------------------------------------------------------------
197 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
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
)
205 OperationLogFile( env
, name
, "output" ).logOperation( "sync" );
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!" );
218 OSL_ENSURE( false, "StorageNativeOutputStream::sync: could not flush output stream!" );
222 // -----------------------------------------------------------------------------