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>
27 using namespace ::comphelper
;
28 using namespace connectivity
;
29 using namespace connectivity::hsqldb
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::beans
;
32 using namespace ::com::sun::star::sdbc
;
33 using namespace ::com::sun::star::container
;
34 using namespace ::com::sun::star::lang
;
36 OUsers::OUsers( ::cppu::OWeakObject
& _rParent
,
37 ::osl::Mutex
& _rMutex
,
38 const ::std::vector
< OUString
> &_rVector
,
39 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
40 connectivity::sdbcx::IRefreshableUsers
* _pParent
)
41 : sdbcx::OCollection(_rParent
, true, _rMutex
, _rVector
)
42 ,m_xConnection(_xConnection
)
48 sdbcx::ObjectType
OUsers::createObject(const OUString
& _rName
)
50 return new OHSQLUser(m_xConnection
,_rName
);
53 void OUsers::impl_refresh()
55 m_pParent
->refreshUsers();
58 Reference
< XPropertySet
> OUsers::createDescriptor()
60 return new OUserExtend(m_xConnection
);
64 sdbcx::ObjectType
OUsers::appendObject( const OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
66 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString( );
68 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD
)) >>= sPassword
;
69 OUString aSql
= "GRANT USAGE ON * TO " +
70 ::dbtools::quoteName(aQuote
,_rForName
) + " @\"%\" ";
71 if ( !sPassword
.isEmpty() )
73 aSql
+= " IDENTIFIED BY '" + sPassword
+ "'";
76 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
79 ::comphelper::disposeComponent(xStmt
);
81 return createObject( _rForName
);
85 void OUsers::dropObject(sal_Int32
/*nPos*/,const OUString
& _sElementName
)
87 OUString
aSql( "REVOKE ALL ON * FROM " );
88 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString( );
89 aSql
+= ::dbtools::quoteName(aQuote
,_sElementName
);
91 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
94 ::comphelper::disposeComponent(xStmt
);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */