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