LibreOffice Module connectivity (master) 1
StorageNativeOutputStream.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
21#include <config.h>
22#endif
23
25#include <osl/diagnose.h>
26#include "accesslog.hxx"
27#include <com/sun/star/embed/XTransactedObject.hpp>
28#include <com/sun/star/io/XStream.hpp>
29#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
32
33using namespace ::com::sun::star::container;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::document;
36using namespace ::com::sun::star::embed;
37using namespace ::com::sun::star::io;
38using namespace ::com::sun::star::lang;
39using namespace ::connectivity::hsqldb;
40
41
42/*
43 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
44 * Method: openStream
45 * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
46 */
48 (JNIEnv * env, jobject /*obj_this*/, jstring name, jstring key, jint mode)
49{
50#ifdef HSQLDB_DBG
51 {
52 OperationLogFile( env, name, "output" ).logOperation( "openStream" );
53 LogFile( env, name, "output" ).create();
54 }
55#endif
56 StorageContainer::registerStream(env,name,key,mode);
57}
58/*
59 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
60 * Method: write
61 * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)V
62 */
64 (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer, jint off, jint len)
65{
66#ifdef HSQLDB_DBG
67 OperationLogFile( env, name, "output" ).logOperation( "write( byte[], int, int )" );
68
69 DataLogFile aDataLog( env, name, "output" );
70 write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, off, len, &aDataLog );
71#else
72 (void)obj_this;
73 write_to_storage_stream_from_buffer( env, name, key, buffer, off, len );
74#endif
75}
76
77/*
78 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
79 * Method: write
80 * Signature: (Ljava/lang/String;Ljava/lang/String;[B)V
81 */
83 (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer)
84{
85#ifdef HSQLDB_DBG
86 OperationLogFile( env, name, "output" ).logOperation( "write( byte[] )" );
87
88 DataLogFile aDataLog( env, name, "output" );
89 write_to_storage_stream_from_buffer( env, obj_this, name, key, buffer, 0, env->GetArrayLength( buffer ), &aDataLog );
90#else
91 (void)obj_this;
92 write_to_storage_stream_from_buffer( env, name, key, buffer, 0, env->GetArrayLength( buffer ) );
93#endif
94}
95
96/*
97 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
98 * Method: close
99 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
100 */
102 (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
103{
104#ifdef HSQLDB_DBG
105 OperationLogFile aOpLog( env, name, "output" );
106 aOpLog.logOperation( "close" );
107
108 LogFile aDataLog( env, name, "output" );
109#endif
110
111 std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key);
112 Reference< XOutputStream> xFlush = pHelper ? pHelper->getOutputStream() : Reference< XOutputStream>();
113 if ( xFlush.is() )
114 try
115 {
116 xFlush->flush();
117 }
118 catch(Exception&)
119 {}
120
121#ifdef HSQLDB_DBG
122 aDataLog.close();
123 aOpLog.close();
124#endif
125 StorageContainer::revokeStream(env,name,key);
126}
127
128/*
129 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
130 * Method: write
131 * Signature: (Ljava/lang/String;Ljava/lang/String;I)V
132 */
134 (JNIEnv * env, jobject obj_this, jstring key, jstring name,jint b)
135{
136#ifdef HSQLDB_DBG
137 OperationLogFile( env, name, "output" ).logOperation( "write( int )" );
138
139 DataLogFile aDataLog( env, name, "output" );
140 write_to_storage_stream( env, name, key, b, &aDataLog );
141#else
142 (void)obj_this;
143 write_to_storage_stream( env, name, key, b );
144#endif
145}
146
147/*
148 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
149 * Method: flush
150 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
151 */
153 (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
154{
155#ifdef HSQLDB_DBG
156 OperationLogFile( env, name, "output" ).logOperation( "flush" );
157
158 OUString sKey = StorageContainer::jstring2ustring(env,key);
159 OUString sName = StorageContainer::jstring2ustring(env,name);
160#else
161 (void) env;
162 (void) key;
163 (void) name;
164#endif
165}
166
167/*
168 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream
169 * Method: sync
170 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
171 */
173 (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name)
174{
175#ifdef HSQLDB_DBG
176 OperationLogFile( env, name, "output" ).logOperation( "sync" );
177#endif
178 std::shared_ptr< StreamHelper > pStream = StorageContainer::getRegisteredStream( env, name, key );
179 Reference< XOutputStream > xFlush = pStream ? pStream->getOutputStream() : Reference< XOutputStream>();
180 OSL_ENSURE( xFlush.is(), "StorageNativeOutputStream::sync: could not retrieve an output stream!" );
181 if ( xFlush.is() )
182 {
183 try
184 {
185 xFlush->flush();
186 }
187 catch(Exception&)
188 {
189 OSL_FAIL( "StorageNativeOutputStream::sync: could not flush output stream!" );
190 }
191 }
192}
193
194
195/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void write_to_storage_stream_from_buffer(JNIEnv *env, jstring name, jstring key, jbyteArray buffer, jint off, jint len)
void write_to_storage_stream(JNIEnv *env, jstring name, jstring key, jint v)
SAL_JNI_EXPORT void JNICALL 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)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_openStream(JNIEnv *env, jobject, jstring name, jstring key, jint mode)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_sync(JNIEnv *env, jobject, jstring key, jstring name)
SAL_JNI_EXPORT void JNICALL 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)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_flush(JNIEnv *env, jobject, jstring key, jstring name)
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeOutputStream_close(JNIEnv *env, jobject, jstring key, jstring name)
SAL_JNI_EXPORT void JNICALL 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)
OUString sName
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
@ Exception
OUString name
Definition: pq_statics.cxx:74
ConversionMode mode