bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / hsqldb / StorageFileAccess.cxx
bloba96309bc292c2b06eb1bac4c20eac71fb1490237
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/embed/XStorage.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <hsqldb/HStorageMap.hxx>
28 #include <osl/diagnose.h>
29 #include <sal/log.hxx>
32 using namespace ::com::sun::star::container;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::embed;
35 using namespace ::com::sun::star::io;
36 using namespace ::com::sun::star::lang;
37 using namespace ::connectivity::hsqldb;
40 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
41 * Method: isStreamElement
42 * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
44 extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement
45 (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
47 TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
48 auto storage = aStoragePair.mapStorage();
49 if ( storage.is() )
51 try
53 OUString sName = StorageContainer::jstring2ustring(env,name);
54 try
56 OUString sOldName = StorageContainer::removeOldURLPrefix(sName);
57 if ( storage->isStreamElement(sOldName) )
59 try
61 storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url));
63 catch(const Exception&)
68 catch(const NoSuchElementException&)
71 catch(const IllegalArgumentException&)
74 return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url));
76 catch(const NoSuchElementException&)
79 catch(const Exception& e)
81 OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement");
82 if (env->ExceptionCheck())
83 env->ExceptionClear();
84 SAL_WARN("connectivity.hsqldb", "forwarding Exception: " << e);
87 return JNI_FALSE;
92 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
93 * Method: removeElement
94 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
96 extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement
97 (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
99 #ifdef HSQLDB_DBG
101 OUString sKey = StorageContainer::jstring2ustring(env,key);
102 OUString sName = StorageContainer::jstring2ustring(env,name);
104 #endif
105 TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
106 auto storage = aStoragePair.mapStorage();
107 if ( storage.is() )
111 storage->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.url));
113 catch(const NoSuchElementException&)
115 if (env->ExceptionCheck())
116 env->ExceptionClear();
118 catch(const Exception& e)
120 SAL_WARN("connectivity.hsqldb", "Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement " << e);
121 StorageContainer::throwJavaException(e,env);
128 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
129 * Method: renameElement
130 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
132 extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement
133 (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname)
135 #ifdef HSQLDB_DBG
137 OUString sKey = StorageContainer::jstring2ustring(env,key);
138 OUString sNewName = StorageContainer::jstring2ustring(env,newname);
139 OUString sOldName = StorageContainer::jstring2ustring(env,oldname);
141 #endif
142 TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
143 auto storage = aStoragePair.mapStorage();
144 if ( storage.is() )
148 storage->renameElement(
149 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.url),
150 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.url)
152 #ifdef HSQLDB_DBG
154 OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second);
155 OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed");
157 #endif
159 catch(const NoSuchElementException&)
162 catch(const Exception& e)
164 OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement");
165 StorageContainer::throwJavaException(e,env);
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */