Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / commontools / TPrivilegesResultSet.cxx
blobd52a1a0b7541f54d44a4e32c44c620002ac6797a
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::beans;
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star::sdbcx;
27 using namespace ::com::sun::star::sdbc;
28 using namespace ::com::sun::star::container;
29 using namespace ::com::sun::star::lang;
31 OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
32 , const Any& catalog
33 , const OUString& schemaPattern
34 , const OUString& tableNamePattern)
35 : ODatabaseMetaDataResultSet(eTablePrivileges)
36 , m_bResetValues(true)
38 osl_atomic_increment( &m_refCount );
40 OUString sUserWorkingFor;
41 Sequence< OUString > sTableTypes(3);
42 // we want all catalogues, all schemas, all tables
43 sTableTypes[0] = "VIEW";
44 sTableTypes[1] = "TABLE";
45 sTableTypes[2] = "%"; // just to be sure to include anything else ....
46 try
48 m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
49 m_xRow = Reference< XRow>(m_xTables,UNO_QUERY);
51 sUserWorkingFor = _rxMeta->getUserName();
53 catch(Exception&)
57 ODatabaseMetaDataResultSet::ORows aRows;
58 static ODatabaseMetaDataResultSet::ORow aRow(8);
59 aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
60 aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
61 aRow[7] = new ORowSetValueDecorator(OUString("YES"));
62 aRows.push_back(aRow);
63 aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
64 aRows.push_back(aRow);
65 aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
66 aRows.push_back(aRow);
67 aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
68 aRows.push_back(aRow);
69 aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
70 aRows.push_back(aRow);
71 aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
72 aRows.push_back(aRow);
73 aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
74 aRows.push_back(aRow);
75 aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
76 aRows.push_back(aRow);
77 aRow[6] = new ORowSetValueDecorator(OUString("REFERENCE"));
78 aRows.push_back(aRow);
80 setRows(aRows);
82 osl_atomic_decrement( &m_refCount );
85 const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
87 switch(columnIndex)
89 case 1:
90 case 2:
91 case 3:
92 if ( m_xRow.is() && m_bResetValues )
94 (*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
95 if ( m_xRow->wasNull() )
96 (*m_aRowsIter)[1]->setNull();
97 (*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
98 if ( m_xRow->wasNull() )
99 (*m_aRowsIter)[2]->setNull();
100 (*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
101 if ( m_xRow->wasNull() )
102 (*m_aRowsIter)[3]->setNull();
104 m_bResetValues = false;
107 return ODatabaseMetaDataResultSet::getValue(columnIndex);
110 void SAL_CALL OResultSetPrivileges::disposing(void)
112 ODatabaseMetaDataResultSet::disposing();
113 m_xTables.clear();
114 m_xRow.clear();
117 sal_Bool SAL_CALL OResultSetPrivileges::next( ) throw(SQLException, RuntimeException, std::exception)
119 ::osl::MutexGuard aGuard( m_aMutex );
120 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
122 bool bReturn = false;
123 if ( m_xTables.is() )
125 if ( m_bBOF )
127 m_bResetValues = true;
128 if ( !m_xTables->next() )
129 return sal_False;
132 bReturn = ODatabaseMetaDataResultSet::next();
133 if ( !bReturn )
135 m_bBOF = false;
136 m_bResetValues = bReturn = m_xTables->next();
139 return bReturn;
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */