bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mysql_jdbc / YUsers.cxx
blobed33cb0e2d7cc5b3fcd3741de67dd0f0a69a1618
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <mysql/YUsers.hxx>
21 #include <mysql/YUser.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::mysql;
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, ::osl::Mutex& _rMutex,
37 const ::std::vector<OUString>& _rVector,
38 const css::uno::Reference<css::sdbc::XConnection>& _xConnection,
39 connectivity::sdbcx::IRefreshableUsers* _pParent)
40 : sdbcx::OCollection(_rParent, true, _rMutex, _rVector)
41 , m_xConnection(_xConnection)
42 , m_pParent(_pParent)
46 sdbcx::ObjectType OUsers::createObject(const OUString& _rName)
48 return new OMySQLUser(m_xConnection, _rName);
51 void OUsers::impl_refresh() { m_pParent->refreshUsers(); }
53 Reference<XPropertySet> OUsers::createDescriptor() { return new OUserExtend(m_xConnection); }
55 // XAppend
56 sdbcx::ObjectType OUsers::appendObject(const OUString& _rForName,
57 const Reference<XPropertySet>& descriptor)
59 OUString aSql("GRANT USAGE ON * TO ");
60 OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString();
61 aSql += ::dbtools::quoteName(aQuote, _rForName) + " @\"%\" ";
62 OUString sPassword;
63 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD))
64 >>= sPassword;
65 if (!sPassword.isEmpty())
67 aSql += " IDENTIFIED BY '" + sPassword + "'";
70 Reference<XStatement> xStmt = m_xConnection->createStatement();
71 if (xStmt.is())
72 xStmt->execute(aSql);
73 ::comphelper::disposeComponent(xStmt);
75 return createObject(_rForName);
78 // XDrop
79 void OUsers::dropObject(sal_Int32 /*_nPos*/, const OUString& _sElementName)
81 OUString aSql("DROP USER ");
82 OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString();
83 aSql += ::dbtools::quoteName(aQuote, _sElementName);
85 Reference<XStatement> xStmt = m_xConnection->createStatement();
86 if (xStmt.is())
87 xStmt->execute(aSql);
88 ::comphelper::disposeComponent(xStmt);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */