merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / postgresql / pq_xuser.cxx
blob0fe46f6d8f9bbadda4676ac29e0af3d74bd18b64
1 /*************************************************************************
3 * $RCSfile: pq_xuser.cxx,v $
5 * $Revision: 1.1.2.3 $
7 * last change: $Author: jbu $ $Date: 2006/01/22 15:14:40 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 * MA 02111-1307 USA
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Joerg Budischewski
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): Joerg Budischewski
60 ************************************************************************/
62 #include <rtl/ustrbuf.hxx>
64 #include <cppuhelper/typeprovider.hxx>
65 #include <cppuhelper/queryinterface.hxx>
67 #include <com/sun/star/beans/PropertyAttribute.hpp>
69 #include <com/sun/star/sdbc/XRow.hpp>
70 #include <com/sun/star/sdbc/XParameters.hpp>
72 #include "pq_xuser.hxx"
73 #include "pq_tools.hxx"
74 #include "pq_statics.hxx"
76 using osl::MutexGuard;
77 using osl::Mutex;
79 using rtl::OUString;
80 using rtl::OUStringBuffer;
82 using com::sun::star::container::XNameAccess;
83 using com::sun::star::container::XIndexAccess;
84 using com::sun::star::container::ElementExistException;
85 using com::sun::star::container::NoSuchElementException;
87 using com::sun::star::uno::Reference;
88 using com::sun::star::uno::Exception;
89 using com::sun::star::uno::UNO_QUERY;
90 using com::sun::star::uno::XInterface;
91 using com::sun::star::uno::Sequence;
92 using com::sun::star::uno::Any;
93 using com::sun::star::uno::makeAny;
94 using com::sun::star::uno::Type;
95 using com::sun::star::uno::RuntimeException;
97 using com::sun::star::lang::IllegalArgumentException;
98 using com::sun::star::lang::IndexOutOfBoundsException;
100 using com::sun::star::beans::XPropertySetInfo;
101 using com::sun::star::beans::XFastPropertySet;
102 using com::sun::star::beans::XMultiPropertySet;
103 using com::sun::star::beans::XPropertySet;
104 using com::sun::star::beans::Property;
106 using com::sun::star::sdbc::XResultSet;
107 using com::sun::star::sdbc::XPreparedStatement;
108 using com::sun::star::sdbc::XStatement;
109 using com::sun::star::sdbc::XParameters;
110 using com::sun::star::sdbc::XRow;
111 using com::sun::star::sdbc::SQLException;
113 namespace pq_sdbc_driver
116 #define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
118 User::User( const ::rtl::Reference< RefCountedMutex > & refMutex,
119 const Reference< com::sun::star::sdbc::XConnection > & connection,
120 ConnectionSettings *pSettings )
121 : ReflectionBase(
122 getStatics().refl.user.implName,
123 getStatics().refl.user.serviceNames,
124 refMutex,
125 connection,
126 pSettings,
127 * getStatics().refl.user.pProps )
130 Reference< XPropertySet > User::createDataDescriptor( ) throw (RuntimeException)
132 UserDescriptor * pUser = new UserDescriptor( m_refMutex, m_conn, m_pSettings );
133 pUser->copyValuesFrom( this );
135 return Reference< XPropertySet > ( pUser );
139 Sequence<Type > User::getTypes() throw( RuntimeException )
141 static cppu::OTypeCollection *pCollection;
142 if( ! pCollection )
144 MutexGuard guard( osl::Mutex::getGlobalMutex() );
145 if( !pCollection )
147 static cppu::OTypeCollection collection(
148 getCppuType( (Reference< com::sun::star::sdbcx::XUser> *) 0 ),
149 ReflectionBase::getTypes());
150 pCollection = &collection;
153 return pCollection->getTypes();
156 Sequence< sal_Int8> User::getImplementationId() throw( RuntimeException )
158 return getStatics().refl.user.implementationId;
161 Any User::queryInterface( const Type & reqType ) throw (RuntimeException)
163 Any ret;
165 ret = ReflectionBase::queryInterface( reqType );
166 if( ! ret.hasValue() )
167 ret = ::cppu::queryInterface(
168 reqType,
169 static_cast< com::sun::star::sdbcx::XUser * > ( this ) );
170 return ret;
174 void User::changePassword(
175 const ::rtl::OUString& oldPassword, const ::rtl::OUString& newPassword )
176 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
178 rtl::OUStringBuffer buf(128);
179 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER USER " ) );
180 bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ) );
181 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) );
182 bufferQuoteConstant( buf, newPassword, m_pSettings->encoding );
183 Reference< XStatement > stmt = m_conn->createStatement();
184 DisposeGuard guard( stmt );
185 stmt->executeUpdate( buf.makeStringAndClear() );
188 sal_Int32 User::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType )
189 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
191 sal_Int32 ret = 0xffffffff;
192 if( isLog( m_pSettings, LogLevel::INFO ) )
194 Statics & st = getStatics();
195 rtl::OUString user = extractStringProperty( this, st.NAME );
197 rtl::OUStringBuffer buf( 128 );
198 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("User::getPrivileges[") );
199 buf.append( extractStringProperty( this, st.NAME ) );
200 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "] got called for " ) );
201 buf.append( objName );
202 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(type=" ) );
203 buf.append( objType );
204 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
205 log( m_pSettings, LogLevel::INFO, buf.makeStringAndClear() );
207 // all privileges
208 return ret;
211 sal_Int32 User::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType )
212 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
214 // all privileges
215 return 0xffffffff;
218 void User::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
219 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
221 throw com::sun::star::sdbc::SQLException(
222 ASCII_STR( "pq_driver: privilege change not implemented yet" ),
223 *this, OUString(), 1, Any() );
226 void User::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
227 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
229 throw com::sun::star::sdbc::SQLException(
230 ASCII_STR( "pq_driver: privilege change not implemented yet" ),
231 *this, OUString(), 1, Any() );
234 //______________________________________________________________________________________
235 UserDescriptor::UserDescriptor(
236 const ::rtl::Reference< RefCountedMutex > & refMutex,
237 const Reference< com::sun::star::sdbc::XConnection > & connection,
238 ConnectionSettings *pSettings )
239 : ReflectionBase(
240 getStatics().refl.userDescriptor.implName,
241 getStatics().refl.userDescriptor.serviceNames,
242 refMutex,
243 connection,
244 pSettings,
245 * getStatics().refl.userDescriptor.pProps )
248 Reference< XPropertySet > UserDescriptor::createDataDescriptor( ) throw (RuntimeException)
250 UserDescriptor * pUser = new UserDescriptor( m_refMutex, m_conn, m_pSettings );
251 pUser->copyValuesFrom( this );
253 return Reference< XPropertySet > ( pUser );