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
21 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 #include <com/sun/star/embed/XStorage.hpp>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <hsqldb/HStorageMap.hxx>
27 #include <osl/diagnose.h>
28 #include <tools/diagnose_ex.h>
29
30 using namespace ::com::sun::star::container;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::embed;
33 using namespace ::com::sun::star::io;
34 using namespace ::com::sun::star::lang;
35 using namespace ::connectivity::hsqldb;
36
37 /*
38 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
39 * Method: isStreamElement
40 * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
41 */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement(JNIEnv * env,jobject,jstring key,jstring name)42 extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement
43 (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
44 {
45 TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
46 auto storage = aStoragePair.mapStorage();
47 if ( storage.is() )
48 {
49 try
50 {
51 OUString sName = StorageContainer::jstring2ustring(env,name);
52 try
53 {
54 OUString sOldName = StorageContainer::removeOldURLPrefix(sName);
55 if ( storage->isStreamElement(sOldName) )
56 {
57 try
58 {
59 storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url));
60 }
61 catch(const Exception&)
62 {
63 }
64 }
65 }
66 catch(const NoSuchElementException&)
67 {
68 }
69 catch(const IllegalArgumentException&)
70 {
71 }
72 return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url));
73 }
74 catch(const NoSuchElementException&)
75 {
76 }
77 catch(const Exception&)
78 {
79 TOOLS_WARN_EXCEPTION("connectivity.hsqldb", "forwarding");
80 if (env->ExceptionCheck())
81 env->ExceptionClear();
82 }
83 }
84 return JNI_FALSE;
85 }
86
87
88 /*
89 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
90 * Method: removeElement
91 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
92 */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement(JNIEnv * env,jobject,jstring key,jstring name)93 extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement
94 (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
95 {
96 #ifdef HSQLDB_DBG
97 {
98 OUString sKey = StorageContainer::jstring2ustring(env,key);
99 OUString sName = StorageContainer::jstring2ustring(env,name);
100 }
101 #endif
102 TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
103 auto storage = aStoragePair.mapStorage();
104 if ( !storage.is() )
105 return;
106
107 try
108 {
109 storage->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.url));
110 }
111 catch(const NoSuchElementException&)
112 {
113 if (env->ExceptionCheck())
114 env->ExceptionClear();
115 }
116 catch(const Exception& e)
117 {
118 TOOLS_WARN_EXCEPTION("connectivity.hsqldb", "");
119 StorageContainer::throwJavaException(e,env);
120 }
121 }
122
123
124 /*
125 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
126 * Method: renameElement
127 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
128 */
Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement(JNIEnv * env,jobject,jstring key,jstring oldname,jstring newname)129 extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement
130 (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname)
131 {
132 #ifdef HSQLDB_DBG
133 {
134 OUString sKey = StorageContainer::jstring2ustring(env,key);
135 OUString sNewName = StorageContainer::jstring2ustring(env,newname);
136 OUString sOldName = StorageContainer::jstring2ustring(env,oldname);
137 }
138 #endif
139 TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
140 auto storage = aStoragePair.mapStorage();
141 if ( !storage.is() )
142 return;
143
144 try
145 {
146 storage->renameElement(
147 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.url),
148 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.url)
149 );
150 #ifdef HSQLDB_DBG
151 {
152 OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second);
153 OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed");
154 }
155 #endif
156 }
157 catch(const NoSuchElementException&)
158 {
159 }
160 catch(const Exception& e)
161 {
162 TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement");
163 StorageContainer::throwJavaException(e,env);
164 }
165 }
166
167
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
169