xref: /AOO41X/main/connectivity/source/drivers/hsqldb/HUsers.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "hsqldb/HUsers.hxx"
27 #include "hsqldb/HUser.hxx"
28 #include "hsqldb/HTable.hxx"
29 #include <com/sun/star/sdbc/XRow.hpp>
30 #include <com/sun/star/sdbc/XResultSet.hpp>
31 #include "connectivity/sdbcx/IRefreshable.hxx"
32 #include <comphelper/types.hxx>
33 #include "connectivity/dbexception.hxx"
34 #include "connectivity/dbtools.hxx"
35 #include "TConnection.hxx"
36 
37 using namespace ::comphelper;
38 using namespace connectivity;
39 using namespace connectivity::hsqldb;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 //  using namespace ::com::sun::star::sdbcx;
43 using namespace ::com::sun::star::sdbc;
44 using namespace ::com::sun::star::container;
45 using namespace ::com::sun::star::lang;
46 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
47 
OUsers(::cppu::OWeakObject & _rParent,::osl::Mutex & _rMutex,const TStringVector & _rVector,const::com::sun::star::uno::Reference<::com::sun::star::sdbc::XConnection> & _xConnection,connectivity::sdbcx::IRefreshableUsers * _pParent)48 OUsers::OUsers( ::cppu::OWeakObject& _rParent,
49                 ::osl::Mutex& _rMutex,
50                 const TStringVector &_rVector,
51                 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
52                 connectivity::sdbcx::IRefreshableUsers* _pParent)
53     : sdbcx::OCollection(_rParent,sal_True,_rMutex,_rVector)
54     ,m_xConnection(_xConnection)
55     ,m_pParent(_pParent)
56 {
57 }
58 // -----------------------------------------------------------------------------
59 
createObject(const::rtl::OUString & _rName)60 sdbcx::ObjectType OUsers::createObject(const ::rtl::OUString& _rName)
61 {
62     return new OHSQLUser(m_xConnection,_rName);
63 }
64 // -------------------------------------------------------------------------
impl_refresh()65 void OUsers::impl_refresh() throw(RuntimeException)
66 {
67     m_pParent->refreshUsers();
68 }
69 // -------------------------------------------------------------------------
createDescriptor()70 Reference< XPropertySet > OUsers::createDescriptor()
71 {
72     OUserExtend* pNew = new OUserExtend(m_xConnection);
73     return pNew;
74 }
75 // -------------------------------------------------------------------------
76 // XAppend
appendObject(const::rtl::OUString & _rForName,const Reference<XPropertySet> & descriptor)77 sdbcx::ObjectType OUsers::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
78 {
79     ::rtl::OUString aSql    = ::rtl::OUString::createFromAscii("GRANT USAGE ON * TO ");
80     ::rtl::OUString aQuote  = m_xConnection->getMetaData()->getIdentifierQuoteString(  );
81     ::rtl::OUString sUserName( _rForName );
82     aSql += ::dbtools::quoteName(aQuote,sUserName)
83                 + ::rtl::OUString::createFromAscii(" @\"%\" ");
84     ::rtl::OUString sPassword;
85     descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPassword;
86     if ( sPassword.getLength() )
87     {
88         aSql += ::rtl::OUString::createFromAscii(" IDENTIFIED BY '");
89         aSql += sPassword;
90         aSql += ::rtl::OUString::createFromAscii("'");
91     }
92 
93     Reference< XStatement > xStmt = m_xConnection->createStatement(  );
94     if(xStmt.is())
95         xStmt->execute(aSql);
96     ::comphelper::disposeComponent(xStmt);
97 
98     return createObject( _rForName );
99 }
100 // -------------------------------------------------------------------------
101 // XDrop
dropObject(sal_Int32,const::rtl::OUString _sElementName)102 void OUsers::dropObject(sal_Int32 /*nPos*/,const ::rtl::OUString _sElementName)
103 {
104     {
105         ::rtl::OUString aSql    = ::rtl::OUString::createFromAscii("REVOKE ALL ON * FROM ");
106         ::rtl::OUString aQuote  = m_xConnection->getMetaData()->getIdentifierQuoteString(  );
107         aSql += ::dbtools::quoteName(aQuote,_sElementName);
108 
109         Reference< XStatement > xStmt = m_xConnection->createStatement(  );
110         if(xStmt.is())
111             xStmt->execute(aSql);
112         ::comphelper::disposeComponent(xStmt);
113     }
114 }
115 
116 // -------------------------------------------------------------------------
117