update dev300-m58
[ooovba.git] / connectivity / source / drivers / hsqldb / HUsers.cxx
bloba0501ba9ec67bb136fe5c1b9cdd1828400214226
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: HUsers.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "hsqldb/HUsers.hxx"
34 #include "hsqldb/HUser.hxx"
35 #include "hsqldb/HTable.hxx"
36 #include <com/sun/star/sdbc/XRow.hpp>
37 #include <com/sun/star/sdbc/XResultSet.hpp>
38 #include "connectivity/sdbcx/IRefreshable.hxx"
39 #include <comphelper/types.hxx>
40 #include "connectivity/dbexception.hxx"
41 #include "connectivity/dbtools.hxx"
42 #include "TConnection.hxx"
44 using namespace ::comphelper;
45 using namespace connectivity;
46 using namespace connectivity::hsqldb;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 // using namespace ::com::sun::star::sdbcx;
50 using namespace ::com::sun::star::sdbc;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::lang;
53 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
55 OUsers::OUsers( ::cppu::OWeakObject& _rParent,
56 ::osl::Mutex& _rMutex,
57 const TStringVector &_rVector,
58 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
59 connectivity::sdbcx::IRefreshableUsers* _pParent)
60 : sdbcx::OCollection(_rParent,sal_True,_rMutex,_rVector)
61 ,m_xConnection(_xConnection)
62 ,m_pParent(_pParent)
65 // -----------------------------------------------------------------------------
67 sdbcx::ObjectType OUsers::createObject(const ::rtl::OUString& _rName)
69 return new OHSQLUser(m_xConnection,_rName);
71 // -------------------------------------------------------------------------
72 void OUsers::impl_refresh() throw(RuntimeException)
74 m_pParent->refreshUsers();
76 // -------------------------------------------------------------------------
77 Reference< XPropertySet > OUsers::createDescriptor()
79 OUserExtend* pNew = new OUserExtend(m_xConnection);
80 return pNew;
82 // -------------------------------------------------------------------------
83 // XAppend
84 sdbcx::ObjectType OUsers::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
86 ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("GRANT USAGE ON * TO ");
87 ::rtl::OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
88 ::rtl::OUString sUserName( _rForName );
89 aSql += ::dbtools::quoteName(aQuote,sUserName)
90 + ::rtl::OUString::createFromAscii(" @\"%\" ");
91 ::rtl::OUString sPassword;
92 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPassword;
93 if ( sPassword.getLength() )
95 aSql += ::rtl::OUString::createFromAscii(" IDENTIFIED BY '");
96 aSql += sPassword;
97 aSql += ::rtl::OUString::createFromAscii("'");
100 Reference< XStatement > xStmt = m_xConnection->createStatement( );
101 if(xStmt.is())
102 xStmt->execute(aSql);
103 ::comphelper::disposeComponent(xStmt);
105 return createObject( _rForName );
107 // -------------------------------------------------------------------------
108 // XDrop
109 void OUsers::dropObject(sal_Int32 /*nPos*/,const ::rtl::OUString _sElementName)
112 ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("REVOKE ALL ON * FROM ");
113 ::rtl::OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
114 aSql += ::dbtools::quoteName(aQuote,_sElementName);
116 Reference< XStatement > xStmt = m_xConnection->createStatement( );
117 if(xStmt.is())
118 xStmt->execute(aSql);
119 ::comphelper::disposeComponent(xStmt);
123 // -------------------------------------------------------------------------