1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir #include "TPrivilegesResultSet.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir using namespace connectivity; 33*cdf0e10cSrcweir //------------------------------------------------------------------------------ 34*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 35*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 36*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 37*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 38*cdf0e10cSrcweir using namespace ::com::sun::star::container; 39*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 40*cdf0e10cSrcweir //------------------------------------------------------------------------------ 41*cdf0e10cSrcweir OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta 42*cdf0e10cSrcweir , const Any& catalog 43*cdf0e10cSrcweir , const ::rtl::OUString& schemaPattern 44*cdf0e10cSrcweir , const ::rtl::OUString& tableNamePattern) 45*cdf0e10cSrcweir : ODatabaseMetaDataResultSet(eTablePrivileges) 46*cdf0e10cSrcweir , m_bResetValues(sal_True) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir ::rtl::OUString sUserWorkingFor; 51*cdf0e10cSrcweir static Sequence< ::rtl::OUString > sTableTypes; 52*cdf0e10cSrcweir if ( sTableTypes.getLength() == 0 ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir // we want all catalogues, all schemas, all tables 55*cdf0e10cSrcweir sTableTypes.realloc(3); 56*cdf0e10cSrcweir sTableTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW")); 57*cdf0e10cSrcweir sTableTypes[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TABLE")); 58*cdf0e10cSrcweir sTableTypes[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")); // just to be sure to include anything else .... 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir try 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes); 63*cdf0e10cSrcweir m_xRow = Reference< XRow>(m_xTables,UNO_QUERY); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir sUserWorkingFor = _rxMeta->getUserName(); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir catch(Exception&) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir ODatabaseMetaDataResultSet::ORows aRows; 72*cdf0e10cSrcweir static ODatabaseMetaDataResultSet::ORow aRow(8); 73*cdf0e10cSrcweir aRow[5] = new ORowSetValueDecorator(sUserWorkingFor); 74*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getSelectValue(); 75*cdf0e10cSrcweir aRow[7] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YES"))); 76*cdf0e10cSrcweir aRows.push_back(aRow); 77*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getInsertValue(); 78*cdf0e10cSrcweir aRows.push_back(aRow); 79*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue(); 80*cdf0e10cSrcweir aRows.push_back(aRow); 81*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue(); 82*cdf0e10cSrcweir aRows.push_back(aRow); 83*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getCreateValue(); 84*cdf0e10cSrcweir aRows.push_back(aRow); 85*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getReadValue(); 86*cdf0e10cSrcweir aRows.push_back(aRow); 87*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getAlterValue(); 88*cdf0e10cSrcweir aRows.push_back(aRow); 89*cdf0e10cSrcweir aRow[6] = ODatabaseMetaDataResultSet::getDropValue(); 90*cdf0e10cSrcweir aRows.push_back(aRow); 91*cdf0e10cSrcweir aRow[6] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REFERENCE"))); 92*cdf0e10cSrcweir aRows.push_back(aRow); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir setRows(aRows); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir //------------------------------------------------------------------------------ 99*cdf0e10cSrcweir const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir switch(columnIndex) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir case 1: 104*cdf0e10cSrcweir case 2: 105*cdf0e10cSrcweir case 3: 106*cdf0e10cSrcweir if ( m_xRow.is() && m_bResetValues ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir (*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1)); 109*cdf0e10cSrcweir if ( m_xRow->wasNull() ) 110*cdf0e10cSrcweir (*m_aRowsIter)[1]->setNull(); 111*cdf0e10cSrcweir (*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2)); 112*cdf0e10cSrcweir if ( m_xRow->wasNull() ) 113*cdf0e10cSrcweir (*m_aRowsIter)[2]->setNull(); 114*cdf0e10cSrcweir (*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3)); 115*cdf0e10cSrcweir if ( m_xRow->wasNull() ) 116*cdf0e10cSrcweir (*m_aRowsIter)[3]->setNull(); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir m_bResetValues = sal_False; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir return ODatabaseMetaDataResultSet::getValue(columnIndex); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 124*cdf0e10cSrcweir void SAL_CALL OResultSetPrivileges::disposing(void) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir ODatabaseMetaDataResultSet::disposing(); 127*cdf0e10cSrcweir m_xTables.clear(); 128*cdf0e10cSrcweir m_xRow.clear(); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 131*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetPrivileges::next( ) throw(SQLException, RuntimeException) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 134*cdf0e10cSrcweir checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir sal_Bool bReturn = sal_False; 137*cdf0e10cSrcweir if ( m_xTables.is() ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir if ( m_bBOF ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir m_bResetValues = sal_True; 142*cdf0e10cSrcweir if ( !m_xTables->next() ) 143*cdf0e10cSrcweir return sal_False; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir bReturn = ODatabaseMetaDataResultSet::next(); 147*cdf0e10cSrcweir if ( !bReturn ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir m_bBOF = sal_False; 150*cdf0e10cSrcweir m_bResetValues = bReturn = m_xTables->next(); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir return bReturn; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 156