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 <hsqldb/HTable.hxx>
23 #include <com/sun/star/sdbc/XRow.hpp>
24 #include <com/sun/star/sdbc/XResultSet.hpp>
25 #include <connectivity/sdbcx/IRefreshable.hxx>
26 #include <comphelper/types.hxx>
27 #include <connectivity/dbexception.hxx>
28 #include <connectivity/dbtools.hxx>
29 #include <TConnection.hxx>
31 using namespace ::comphelper
;
32 using namespace connectivity
;
33 using namespace connectivity::hsqldb
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::sdbc
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::lang
;
40 OUsers::OUsers( ::cppu::OWeakObject
& _rParent
,
41 ::osl::Mutex
& _rMutex
,
42 const ::std::vector
< OUString
> &_rVector
,
43 const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
,
44 connectivity::sdbcx::IRefreshableUsers
* _pParent
)
45 : sdbcx::OCollection(_rParent
, true, _rMutex
, _rVector
)
46 ,m_xConnection(_xConnection
)
52 sdbcx::ObjectType
OUsers::createObject(const OUString
& _rName
)
54 return new OHSQLUser(m_xConnection
,_rName
);
57 void OUsers::impl_refresh()
59 m_pParent
->refreshUsers();
62 Reference
< XPropertySet
> OUsers::createDescriptor()
64 OUserExtend
* pNew
= new OUserExtend(m_xConnection
);
69 sdbcx::ObjectType
OUsers::appendObject( const OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
71 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString( );
73 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD
)) >>= sPassword
;
74 OUString aSql
= "GRANT USAGE ON * TO " +
75 ::dbtools::quoteName(aQuote
,_rForName
) + " @\"%\" ";
76 if ( !sPassword
.isEmpty() )
78 aSql
+= " IDENTIFIED BY '" + sPassword
+ "'";
81 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
84 ::comphelper::disposeComponent(xStmt
);
86 return createObject( _rForName
);
90 void OUsers::dropObject(sal_Int32
/*nPos*/,const OUString
& _sElementName
)
92 OUString
aSql( "REVOKE ALL ON * FROM " );
93 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString( );
94 aSql
+= ::dbtools::quoteName(aQuote
,_sElementName
);
96 Reference
< XStatement
> xStmt
= m_xConnection
->createStatement( );
99 ::comphelper::disposeComponent(xStmt
);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */