1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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();
53 OUString sName
= StorageContainer::jstring2ustring(env
,name
);
56 OUString sOldName
= StorageContainer::removeOldURLPrefix(sName
);
57 if ( storage
->isStreamElement(sOldName
) )
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
);
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
)
101 OUString sKey
= StorageContainer::jstring2ustring(env
,key
);
102 OUString sName
= StorageContainer::jstring2ustring(env
,name
);
105 TStorages::mapped_type aStoragePair
= StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env
,key
));
106 auto storage
= aStoragePair
.mapStorage();
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
)
137 OUString sKey
= StorageContainer::jstring2ustring(env
,key
);
138 OUString sNewName
= StorageContainer::jstring2ustring(env
,newname
);
139 OUString sOldName
= StorageContainer::jstring2ustring(env
,oldname
);
142 TStorages::mapped_type aStoragePair
= StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env
,key
));
143 auto storage
= aStoragePair
.mapStorage();
148 storage
->renameElement(
149 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env
,oldname
),aStoragePair
.url
),
150 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env
,newname
),aStoragePair
.url
)
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");
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: */