sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / connectivity / source / commontools / TPrivilegesResultSet.cxx
blob0003cedbcdbf506e8b429c59f1532a5de5adf385
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <TPrivilegesResultSet.hxx>
22 using namespace connectivity;
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::sdbc;
26 using namespace ::com::sun::star::container;
27 using namespace ::com::sun::star::lang;
29 OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
30 , const Any& catalog
31 , const OUString& schemaPattern
32 , const OUString& tableNamePattern)
33 : ODatabaseMetaDataResultSet(eTablePrivileges)
34 , m_bResetValues(true)
36 osl_atomic_increment( &m_refCount );
38 OUString sUserWorkingFor;
39 // we want all catalogues, all schemas, all tables
40 Sequence< OUString > sTableTypes {u"VIEW"_ustr, u"TABLE"_ustr, u"%"_ustr}; // this last one is just to be sure to include anything else...
41 try
43 m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
44 m_xRow.set(m_xTables,UNO_QUERY);
46 sUserWorkingFor = _rxMeta->getUserName();
48 catch(Exception&)
52 ODatabaseMetaDataResultSet::ORows aRows;
53 ODatabaseMetaDataResultSet::ORow aRow(8);
54 aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
55 aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
56 aRow[7] = new ORowSetValueDecorator(u"YES"_ustr);
57 aRows.push_back(aRow);
58 aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
59 aRows.push_back(aRow);
60 aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
61 aRows.push_back(aRow);
62 aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
63 aRows.push_back(aRow);
64 aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
65 aRows.push_back(aRow);
66 aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
67 aRows.push_back(aRow);
68 aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
69 aRows.push_back(aRow);
70 aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
71 aRows.push_back(aRow);
72 aRow[6] = new ORowSetValueDecorator(u"REFERENCE"_ustr);
73 aRows.push_back(aRow);
75 setRows(std::move(aRows));
77 osl_atomic_decrement( &m_refCount );
80 const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
82 switch(columnIndex)
84 case 1:
85 case 2:
86 case 3:
87 if ( m_xRow.is() && m_bResetValues )
89 (*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
90 if ( m_xRow->wasNull() )
91 (*m_aRowsIter)[1]->setNull();
92 (*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
93 if ( m_xRow->wasNull() )
94 (*m_aRowsIter)[2]->setNull();
95 (*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
96 if ( m_xRow->wasNull() )
97 (*m_aRowsIter)[3]->setNull();
99 m_bResetValues = false;
102 return ODatabaseMetaDataResultSet::getValue(columnIndex);
105 void OResultSetPrivileges::disposing(std::unique_lock<std::mutex>& rGuard)
107 ODatabaseMetaDataResultSet::disposing(rGuard);
108 m_xTables.clear();
109 m_xRow.clear();
112 sal_Bool SAL_CALL OResultSetPrivileges::next( )
114 std::unique_lock aGuard( m_aMutex );
115 throwIfDisposed(aGuard);
117 bool bReturn = false;
118 if ( m_xTables.is() )
120 if ( m_bBOF )
122 m_bResetValues = true;
123 if ( !m_xTables->next() )
124 return false;
127 bReturn = ODatabaseMetaDataResultSet::next(aGuard);
128 if ( !bReturn )
130 m_bBOF = false;
131 m_bResetValues = bReturn = m_xTables->next();
134 return bReturn;
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */