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 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 27cdf0e10cSrcweir #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H 28cdf0e10cSrcweir #include <config.h> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 31cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 32cdf0e10cSrcweir #include "hsqldb/StorageFileAccess.h" 33cdf0e10cSrcweir #include "hsqldb/HStorageMap.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <rtl/logfile.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir using namespace ::com::sun::star::container; 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::embed; 40cdf0e10cSrcweir using namespace ::com::sun::star::io; 41cdf0e10cSrcweir using namespace ::com::sun::star::lang; 42cdf0e10cSrcweir using namespace ::connectivity::hsqldb; 43cdf0e10cSrcweir 44cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 45cdf0e10cSrcweir /*****************************************************************************/ 46cdf0e10cSrcweir /* exception macros */ 47cdf0e10cSrcweir 48cdf0e10cSrcweir #define ThrowException(env, type, msg) { \ 49cdf0e10cSrcweir env->ThrowNew(env->FindClass(type), msg); } 50cdf0e10cSrcweir 51cdf0e10cSrcweir /* 52cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess 53cdf0e10cSrcweir * Method: isStreamElement 54cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)Z 55cdf0e10cSrcweir */ 56cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement 57cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); 60cdf0e10cSrcweir if ( aStoragePair.first.first.is() ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir try 63cdf0e10cSrcweir { 64cdf0e10cSrcweir ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name); 65cdf0e10cSrcweir try 66cdf0e10cSrcweir { 67cdf0e10cSrcweir ::rtl::OUString sOldName = StorageContainer::removeOldURLPrefix(sName); 68cdf0e10cSrcweir if ( aStoragePair.first.first->isStreamElement(sOldName) ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir try 71cdf0e10cSrcweir { 72cdf0e10cSrcweir aStoragePair.first.first->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.first.second)); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir catch(Exception&) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir catch(NoSuchElementException&) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir } 82cdf0e10cSrcweir return aStoragePair.first.first->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.first.second)); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir catch(NoSuchElementException&) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir catch(Exception& e) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement"); 90cdf0e10cSrcweir if (JNI_FALSE != env->ExceptionCheck()) 91cdf0e10cSrcweir env->ExceptionClear(); 92cdf0e10cSrcweir ::rtl::OString cstr( ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) ); 93cdf0e10cSrcweir OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir return JNI_FALSE; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir // ----------------------------------------------------------------------------- 99cdf0e10cSrcweir 100cdf0e10cSrcweir /* 101cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess 102cdf0e10cSrcweir * Method: removeElement 103cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)V 104cdf0e10cSrcweir */ 105cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement 106cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir #ifdef HSQLDB_DBG 109cdf0e10cSrcweir { 110cdf0e10cSrcweir ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key); 111cdf0e10cSrcweir ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir #endif 114cdf0e10cSrcweir TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); 115cdf0e10cSrcweir if ( aStoragePair.first.first.is() ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir try 118cdf0e10cSrcweir { 119cdf0e10cSrcweir aStoragePair.first.first->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.first.second)); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir catch(NoSuchElementException&) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir if (JNI_FALSE != env->ExceptionCheck()) 124cdf0e10cSrcweir env->ExceptionClear(); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir catch(Exception& e) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement"); 129cdf0e10cSrcweir StorageContainer::throwJavaException(e,env); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir // ----------------------------------------------------------------------------- 134cdf0e10cSrcweir 135cdf0e10cSrcweir /* 136cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess 137cdf0e10cSrcweir * Method: renameElement 138cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V 139cdf0e10cSrcweir */ 140cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement 141cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir #ifdef HSQLDB_DBG 144cdf0e10cSrcweir { 145cdf0e10cSrcweir ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key); 146cdf0e10cSrcweir ::rtl::OUString sNewName = StorageContainer::jstring2ustring(env,newname); 147cdf0e10cSrcweir ::rtl::OUString sOldName = StorageContainer::jstring2ustring(env,oldname); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir #endif 150cdf0e10cSrcweir TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); 151cdf0e10cSrcweir if ( aStoragePair.first.first.is() ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir try 154cdf0e10cSrcweir { 155cdf0e10cSrcweir aStoragePair.first.first->renameElement( 156cdf0e10cSrcweir StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.first.second), 157cdf0e10cSrcweir StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second) 158cdf0e10cSrcweir ); 159cdf0e10cSrcweir #ifdef HSQLDB_DBG 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ::rtl::OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second); 162cdf0e10cSrcweir OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed"); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir #endif 165cdf0e10cSrcweir } 166cdf0e10cSrcweir catch(NoSuchElementException&) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir } 169cdf0e10cSrcweir catch(Exception& e) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); 172cdf0e10cSrcweir StorageContainer::throwJavaException(e,env); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir // ----------------------------------------------------------------------------- 177