1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
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.
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.
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,
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
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/.
35 ************************************************************************/
37 #include <rtl/ustrbuf.hxx>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <cppuhelper/queryinterface.hxx>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/sdbc/XRow.hpp>
45 #include <com/sun/star/sdbc/XParameters.hpp>
47 #include "pq_xuser.hxx"
48 #include "pq_tools.hxx"
49 #include "pq_statics.hxx"
51 using osl::MutexGuard
;
54 using com::sun::star::container::XNameAccess
;
55 using com::sun::star::container::XIndexAccess
;
56 using com::sun::star::container::ElementExistException
;
57 using com::sun::star::container::NoSuchElementException
;
59 using com::sun::star::uno::Reference
;
60 using com::sun::star::uno::Exception
;
61 using com::sun::star::uno::UNO_QUERY
;
62 using com::sun::star::uno::XInterface
;
63 using com::sun::star::uno::Sequence
;
64 using com::sun::star::uno::Any
;
65 using com::sun::star::uno::makeAny
;
66 using com::sun::star::uno::Type
;
67 using com::sun::star::uno::RuntimeException
;
69 using com::sun::star::lang::IllegalArgumentException
;
70 using com::sun::star::lang::IndexOutOfBoundsException
;
72 using com::sun::star::beans::XPropertySetInfo
;
73 using com::sun::star::beans::XFastPropertySet
;
74 using com::sun::star::beans::XMultiPropertySet
;
75 using com::sun::star::beans::XPropertySet
;
76 using com::sun::star::beans::Property
;
78 using com::sun::star::sdbc::XResultSet
;
79 using com::sun::star::sdbc::XPreparedStatement
;
80 using com::sun::star::sdbc::XStatement
;
81 using com::sun::star::sdbc::XParameters
;
82 using com::sun::star::sdbc::XRow
;
83 using com::sun::star::sdbc::SQLException
;
85 namespace pq_sdbc_driver
88 User::User( const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
89 const Reference
< com::sun::star::sdbc::XConnection
> & connection
,
90 ConnectionSettings
*pSettings
)
92 getStatics().refl
.user
.implName
,
93 getStatics().refl
.user
.serviceNames
,
97 * getStatics().refl
.user
.pProps
)
100 Reference
< XPropertySet
> User::createDataDescriptor( ) throw (RuntimeException
, std::exception
)
102 UserDescriptor
* pUser
= new UserDescriptor( m_refMutex
, m_conn
, m_pSettings
);
103 pUser
->copyValuesFrom( this );
105 return Reference
< XPropertySet
> ( pUser
);
109 Sequence
<Type
> User::getTypes() throw( RuntimeException
, std::exception
)
111 static cppu::OTypeCollection
*pCollection
;
114 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
117 static cppu::OTypeCollection
collection(
118 getCppuType( (Reference
< com::sun::star::sdbcx::XUser
> *) 0 ),
119 ReflectionBase::getTypes());
120 pCollection
= &collection
;
123 return pCollection
->getTypes();
126 Sequence
< sal_Int8
> User::getImplementationId() throw( RuntimeException
, std::exception
)
128 return css::uno::Sequence
<sal_Int8
>();
131 Any
User::queryInterface( const Type
& reqType
) throw (RuntimeException
, std::exception
)
135 ret
= ReflectionBase::queryInterface( reqType
);
136 if( ! ret
.hasValue() )
137 ret
= ::cppu::queryInterface(
139 static_cast< com::sun::star::sdbcx::XUser
* > ( this ) );
144 void User::changePassword(
145 const OUString
& oldPassword
, const OUString
& newPassword
)
146 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
149 OUStringBuffer
buf(128);
150 buf
.append( "ALTER USER " );
151 bufferQuoteIdentifier( buf
, extractStringProperty( this, getStatics().NAME
), m_pSettings
);
152 buf
.append( " PASSWORD " );
153 bufferQuoteConstant( buf
, newPassword
, m_pSettings
);
154 Reference
< XStatement
> stmt
= m_conn
->createStatement();
155 DisposeGuard
guard( stmt
);
156 stmt
->executeUpdate( buf
.makeStringAndClear() );
159 sal_Int32
User::getPrivileges( const OUString
& objName
, sal_Int32 objType
)
160 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
162 sal_Int32 ret
= 0xffffffff;
163 if( isLog( m_pSettings
, LogLevel::INFO
) )
165 Statics
& st
= getStatics();
167 OUStringBuffer
buf( 128 );
168 buf
.append( "User::getPrivileges[" + extractStringProperty( this, st
.NAME
) +
169 "] got called for " + objName
+ "(type=" +
170 OUString::number(objType
) + ")");
171 log( m_pSettings
, LogLevel::INFO
, buf
.makeStringAndClear() );
177 sal_Int32
User::getGrantablePrivileges( const OUString
& objName
, sal_Int32 objType
)
178 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
180 (void) objName
; (void) objType
;
185 void User::grantPrivileges( const OUString
& objName
, sal_Int32 objType
, sal_Int32 objPrivileges
)
186 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
188 (void) objName
; (void) objType
; (void) objPrivileges
;
189 throw com::sun::star::sdbc::SQLException("pq_driver: privilege change not implemented yet",
190 *this, OUString(), 1, Any() );
193 void User::revokePrivileges( const OUString
& objName
, sal_Int32 objType
, sal_Int32 objPrivileges
)
194 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
196 (void) objName
; (void) objType
; (void) objPrivileges
;
197 throw com::sun::star::sdbc::SQLException("pq_driver: privilege change not implemented yet",
198 *this, OUString(), 1, Any() );
202 UserDescriptor::UserDescriptor(
203 const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
204 const Reference
< com::sun::star::sdbc::XConnection
> & connection
,
205 ConnectionSettings
*pSettings
)
207 getStatics().refl
.userDescriptor
.implName
,
208 getStatics().refl
.userDescriptor
.serviceNames
,
212 * getStatics().refl
.userDescriptor
.pProps
)
215 Reference
< XPropertySet
> UserDescriptor::createDataDescriptor( ) throw (RuntimeException
, std::exception
)
217 UserDescriptor
* pUser
= new UserDescriptor( m_refMutex
, m_conn
, m_pSettings
);
218 pUser
->copyValuesFrom( this );
220 return Reference
< XPropertySet
> ( pUser
);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */