LibreOffice Module connectivity (master) 1
pq_xuser.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * Effective License of whole file:
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
19 *
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 *
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
24 *
25 * Copyright: 2000 by Sun Microsystems, Inc.
26 *
27 * Contributor(s): Joerg Budischewski
28 *
29 * All parts contributed on or after August 2011:
30 *
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
34 *
35 ************************************************************************/
36
37#include <sal/log.hxx>
38#include <rtl/ref.hxx>
39#include <rtl/ustrbuf.hxx>
40
43
44#include <com/sun/star/sdbc/SQLException.hpp>
45
46#include "pq_xuser.hxx"
47#include "pq_tools.hxx"
48#include "pq_statics.hxx"
49
52using com::sun::star::uno::Any;
53using com::sun::star::uno::Type;
54
56
57using com::sun::star::sdbc::XStatement;
58using com::sun::star::sdbc::SQLException;
59
60namespace pq_sdbc_driver
61{
62
63User::User( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
64 const Reference< css::sdbc::XConnection > & connection,
65 ConnectionSettings *pSettings )
66 : ReflectionBase(
67 getStatics().refl.user.implName,
68 getStatics().refl.user.serviceNames,
69 refMutex,
70 connection,
71 pSettings,
72 * getStatics().refl.user.pProps )
73{}
74
75Reference< XPropertySet > User::createDataDescriptor( )
76{
77 rtl::Reference<UserDescriptor> pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings );
78 pUser->copyValuesFrom( this );
79
80 return Reference< XPropertySet > ( pUser );
81}
82
83
84Sequence<Type > User::getTypes()
85{
86 static cppu::OTypeCollection collection(
88 ReflectionBase::getTypes());
89
90 return collection.getTypes();
91}
92
93Sequence< sal_Int8> User::getImplementationId()
94{
95 return css::uno::Sequence<sal_Int8>();
96}
97
98Any User::queryInterface( const Type & reqType )
99{
100 Any ret = ReflectionBase::queryInterface( reqType );
101 if( ! ret.hasValue() )
102 ret = ::cppu::queryInterface(
103 reqType,
104 static_cast< css::sdbcx::XUser * > ( this ) );
105 return ret;
106}
107
108
109void User::changePassword(
110 const OUString&, const OUString& newPassword )
111{
112 OUStringBuffer buf(128);
113 buf.append( "ALTER USER " );
114 bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ), m_pSettings );
115 buf.append( " PASSWORD " );
116 bufferQuoteConstant( buf, newPassword, m_pSettings );
117 Reference< XStatement > stmt = m_conn->createStatement();
118 DisposeGuard guard( stmt );
119 stmt->executeUpdate( buf.makeStringAndClear() );
120}
121
122sal_Int32 User::getPrivileges( const OUString& objName, sal_Int32 objType )
123{
124 SAL_INFO("connectivity.postgresql", "User::getPrivileges[\"Name\"] got called for " << objName << "(type=" << objType << ")");
125 // all privileges
126 return 0xffffffff;
127}
128
129sal_Int32 User::getGrantablePrivileges( const OUString&, sal_Int32 )
130{
131 // all privileges
132 return 0xffffffff;
133}
134
135void User::grantPrivileges( const OUString&, sal_Int32, sal_Int32 )
136{
137 throw css::sdbc::SQLException("pq_driver: privilege change not implemented yet",
138 *this, OUString(), 1, Any() );
139}
140
141void User::revokePrivileges( const OUString&, sal_Int32, sal_Int32 )
142{
143 throw css::sdbc::SQLException("pq_driver: privilege change not implemented yet",
144 *this, OUString(), 1, Any() );
145}
146
147
148UserDescriptor::UserDescriptor(
149 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
150 const Reference< css::sdbc::XConnection > & connection,
151 ConnectionSettings *pSettings )
153 getStatics().refl.userDescriptor.implName,
154 getStatics().refl.userDescriptor.serviceNames,
155 refMutex,
156 connection,
157 pSettings,
158 * getStatics().refl.userDescriptor.pProps )
159{}
160
162{
164 pUser->copyValuesFrom( this );
165
166 return Reference< XPropertySet > ( pUser );
167}
168
169
170}
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
NAME
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Reference< css::sdbc::XConnection > m_conn
Definition: pq_xbase.hxx:62
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
Definition: pq_xbase.hxx:61
ConnectionSettings * m_pSettings
Definition: pq_xbase.hxx:63
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
Definition: pq_xuser.cxx:161
UserDescriptor(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &connection, ConnectionSettings *pSettings)
Definition: pq_xuser.cxx:148
User(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &connection, ConnectionSettings *pSettings)
#define SAL_INFO(area, stream)
class SAL_NO_VTABLE XPropertySet
Type
void bufferQuoteConstant(OUStringBuffer &buf, std::u16string_view value, ConnectionSettings *settings)
Definition: pq_tools.cxx:138
Statics & getStatics()
Definition: pq_statics.cxx:112
OUString extractStringProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
Definition: pq_tools.cxx:204
void bufferQuoteIdentifier(OUStringBuffer &buf, std::u16string_view toQuote, ConnectionSettings *settings)
Definition: pq_tools.cxx:175
rtl::Reference< Connection > m_conn
const char * implName