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 .
20 #include <hsqldb/HUsers.hxx>
21 #include <hsqldb/HUser.hxx>
22 #include <connectivity/sdbcx/IRefreshable.hxx>
23 #include <comphelper/types.hxx>
24 #include <connectivity/dbtools.hxx>
25 #include <TConnection.hxx>
28 using namespace ::comphelper
;
29 using namespace connectivity
;
30 using namespace connectivity::hsqldb
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::sdbc
;
35 OUsers::OUsers( ::cppu::OWeakObject
& _rParent
,
36 ::osl::Mutex
& _rMutex
,
37 const ::std::vector
< OUString
> &_rVector
,
38 css::uno::Reference
< css::sdbc::XConnection
> _xConnection
,
39 connectivity::sdbcx::IRefreshableUsers
* _pParent
)
40 : sdbcx::OCollection(_rParent
, true, _rMutex
, _rVector
)
41 ,m_xConnection(std::move(_xConnection
))
47 sdbcx::ObjectType
OUsers::createObject(const OUString
& _rName
)
49 return new OHSQLUser(m_xConnection
,_rName
);
52 void OUsers::impl_refresh()
54 m_pParent
->refreshUsers();
57 Reference
< XPropertySet
> OUsers::createDescriptor()
59 return new OUserExtend(m_xConnection
);
63 sdbcx::ObjectType
OUsers::appendObject( const OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
65 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString( );
67 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD
)) >>= sPassword
;
68 OUString aSql
= "GRANT USAGE ON * TO " +
69 ::dbtools::quoteName(aQuote
,_rForName
) + " @\"%\" ";
70 if ( !sPassword
.isEmpty() )
72 aSql
+= " IDENTIFIED BY '" + sPassword
+ "'";
75 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
78 ::comphelper::disposeComponent(xStmt
);
80 return createObject( _rForName
);
84 void OUsers::dropObject(sal_Int32
/*nPos*/,const OUString
& _sElementName
)
86 OUString
aSql( u
"REVOKE ALL ON * FROM "_ustr
);
87 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString( );
88 aSql
+= ::dbtools::quoteName(aQuote
,_sElementName
);
90 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
93 ::comphelper::disposeComponent(xStmt
);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */