LibreOffice Module connectivity (master) 1
HUsers.cxx
Go to the documentation of this file.
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#include <hsqldb/HUsers.hxx>
21#include <hsqldb/HUser.hxx>
23#include <comphelper/types.hxx>
25#include <TConnection.hxx>
26#include <utility>
27
28using namespace ::comphelper;
29using namespace connectivity;
30using namespace connectivity::hsqldb;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::beans;
33using namespace ::com::sun::star::sdbc;
34using namespace ::com::sun::star::container;
35using namespace ::com::sun::star::lang;
36
38 ::osl::Mutex& _rMutex,
39 const ::std::vector< OUString> &_rVector,
40 css::uno::Reference< css::sdbc::XConnection > _xConnection,
42 : sdbcx::OCollection(_rParent, true, _rMutex, _rVector)
43 ,m_xConnection(std::move(_xConnection))
44 ,m_pParent(_pParent)
45{
46}
47
48
50{
51 return new OHSQLUser(m_xConnection,_rName);
52}
53
55{
57}
58
59Reference< XPropertySet > OUsers::createDescriptor()
60{
61 return new OUserExtend(m_xConnection);
62}
63
64// XAppend
65sdbcx::ObjectType OUsers::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
66{
67 OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
68 OUString sPassword;
69 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPassword;
70 OUString aSql = "GRANT USAGE ON * TO " +
71 ::dbtools::quoteName(aQuote,_rForName) + " @\"%\" ";
72 if ( !sPassword.isEmpty() )
73 {
74 aSql += " IDENTIFIED BY '" + sPassword + "'";
75 }
76
77 Reference< XStatement > xStmt = m_xConnection->createStatement( );
78 if(xStmt.is())
79 xStmt->execute(aSql);
80 ::comphelper::disposeComponent(xStmt);
81
82 return createObject( _rForName );
83}
84
85// XDrop
86void OUsers::dropObject(sal_Int32 /*nPos*/,const OUString& _sElementName)
87{
88 OUString aSql( "REVOKE ALL ON * FROM " );
89 OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
90 aSql += ::dbtools::quoteName(aQuote,_sElementName);
91
92 Reference< XStatement > xStmt = m_xConnection->createStatement( );
93 if(xStmt.is())
94 xStmt->execute(aSql);
95 ::comphelper::disposeComponent(xStmt);
96}
97
98
99/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: HUsers.cxx:59
connectivity::sdbcx::IRefreshableUsers * m_pParent
Definition: HUsers.hxx:35
virtual sdbcx::ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
appends an object described by a descriptor, under a given name
css::uno::Reference< css::sdbc::XConnection > m_xConnection
Definition: HUsers.hxx:34
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: HUsers.cxx:86
virtual sdbcx::ObjectType createObject(const OUString &_rName) override
Definition: HUsers.cxx:49
virtual void impl_refresh() override
Definition: HUsers.cxx:54
OCollection OUsers
Definition: VGroup.hxx:36
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
OUString quoteName(std::u16string_view _rQuote, const OUString &_rName)
quote the given name with the given quote string.
Reference< XConnection > m_xConnection
#define PROPERTY_ID_PASSWORD
Definition: propertyids.hxx:74