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 "connectivity/sdbcx/VCatalog.hxx" 31*cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 33*cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx" 34*cdf0e10cSrcweir #include "connectivity/sdbcx/VDescriptor.hxx" 35*cdf0e10cSrcweir #include "TConnection.hxx" 36*cdf0e10cSrcweir #include <comphelper/uno3.hxx> 37*cdf0e10cSrcweir #include "connectivity/dbtools.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace connectivity; 40*cdf0e10cSrcweir using namespace connectivity::sdbcx; 41*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 44*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 45*cdf0e10cSrcweir using namespace ::com::sun::star::container; 46*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 47*cdf0e10cSrcweir //------------------------------------------------------------------------------ 48*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition") 49*cdf0e10cSrcweir //------------------------------------------------------------------------------ 50*cdf0e10cSrcweir OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex) 51*cdf0e10cSrcweir ,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this) 52*cdf0e10cSrcweir ,m_pTables(NULL) 53*cdf0e10cSrcweir ,m_pViews(NULL) 54*cdf0e10cSrcweir ,m_pGroups(NULL) 55*cdf0e10cSrcweir ,m_pUsers(NULL) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir try 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir m_xMetaData = _xConnection->getMetaData(); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir catch(const Exception&) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir OSL_ENSURE(0,"No Metadata available!"); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir //----------------------------------------------------------------------------- 67*cdf0e10cSrcweir OCatalog::~OCatalog() 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir delete m_pTables; 70*cdf0e10cSrcweir delete m_pViews; 71*cdf0e10cSrcweir delete m_pGroups; 72*cdf0e10cSrcweir delete m_pUsers; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir //----------------------------------------------------------------------------- 75*cdf0e10cSrcweir void SAL_CALL OCatalog::acquire() throw() 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir OCatalog_BASE::acquire(); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir //------------------------------------------------------------------------------ 80*cdf0e10cSrcweir void SAL_CALL OCatalog::release() throw() 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir relase_ChildImpl(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir //------------------------------------------------------------------------------ 86*cdf0e10cSrcweir void SAL_CALL OCatalog::disposing() 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir if(m_pTables) 91*cdf0e10cSrcweir m_pTables->disposing(); 92*cdf0e10cSrcweir if(m_pViews) 93*cdf0e10cSrcweir m_pViews->disposing(); 94*cdf0e10cSrcweir if(m_pGroups) 95*cdf0e10cSrcweir m_pGroups->disposing(); 96*cdf0e10cSrcweir if(m_pUsers) 97*cdf0e10cSrcweir m_pUsers->disposing(); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir dispose_ChildImpl(); 100*cdf0e10cSrcweir OCatalog_BASE::disposing(); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir //------------------------------------------------------------------------------ 103*cdf0e10cSrcweir // XTablesSupplier 104*cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getTables( ) throw(RuntimeException) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 107*cdf0e10cSrcweir checkDisposed(OCatalog_BASE::rBHelper.bDisposed); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir try 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir if(!m_pTables) 112*cdf0e10cSrcweir refreshTables(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir catch( const RuntimeException& ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir // allowed to leave this method 117*cdf0e10cSrcweir throw; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir catch( const Exception& ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir // allowed 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir return const_cast<OCatalog*>(this)->m_pTables; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir // ------------------------------------------------------------------------- 127*cdf0e10cSrcweir // XViewsSupplier 128*cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getViews( ) throw(RuntimeException) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 131*cdf0e10cSrcweir checkDisposed(OCatalog_BASE::rBHelper.bDisposed); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir try 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir if(!m_pViews) 136*cdf0e10cSrcweir refreshViews(); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir catch( const RuntimeException& ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir // allowed to leave this method 141*cdf0e10cSrcweir throw; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir catch( const Exception& ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir // allowed 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir return const_cast<OCatalog*>(this)->m_pViews; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir // ------------------------------------------------------------------------- 151*cdf0e10cSrcweir // XUsersSupplier 152*cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getUsers( ) throw(RuntimeException) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 155*cdf0e10cSrcweir checkDisposed(OCatalog_BASE::rBHelper.bDisposed); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir try 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir if(!m_pUsers) 160*cdf0e10cSrcweir refreshUsers(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir catch( const RuntimeException& ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir // allowed to leave this method 165*cdf0e10cSrcweir throw; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir catch( const Exception& ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir // allowed 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir return const_cast<OCatalog*>(this)->m_pUsers; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir // ------------------------------------------------------------------------- 175*cdf0e10cSrcweir // XGroupsSupplier 176*cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OCatalog::getGroups( ) throw(RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 179*cdf0e10cSrcweir checkDisposed(OCatalog_BASE::rBHelper.bDisposed); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir try 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if(!m_pGroups) 184*cdf0e10cSrcweir refreshGroups(); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir catch( const RuntimeException& ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir // allowed to leave this method 189*cdf0e10cSrcweir throw; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir catch( const Exception& ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir // allowed 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir return const_cast<OCatalog*>(this)->m_pGroups; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 199*cdf0e10cSrcweir ::rtl::OUString OCatalog::buildName(const Reference< XRow >& _xRow) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir ::rtl::OUString sCatalog = _xRow->getString(1); 202*cdf0e10cSrcweir if ( _xRow->wasNull() ) 203*cdf0e10cSrcweir sCatalog = ::rtl::OUString(); 204*cdf0e10cSrcweir ::rtl::OUString sSchema = _xRow->getString(2); 205*cdf0e10cSrcweir if ( _xRow->wasNull() ) 206*cdf0e10cSrcweir sSchema = ::rtl::OUString(); 207*cdf0e10cSrcweir ::rtl::OUString sTable = _xRow->getString(3); 208*cdf0e10cSrcweir if ( _xRow->wasNull() ) 209*cdf0e10cSrcweir sTable = ::rtl::OUString(); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir ::rtl::OUString sComposedName( 212*cdf0e10cSrcweir ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ) ); 213*cdf0e10cSrcweir return sComposedName; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 216*cdf0e10cSrcweir void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _rNames) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir if ( _xResult.is() ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir _rNames.reserve(20); 221*cdf0e10cSrcweir Reference< XRow > xRow(_xResult,UNO_QUERY); 222*cdf0e10cSrcweir while ( _xResult->next() ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir _rNames.push_back( buildName(xRow) ); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir xRow.clear(); 227*cdf0e10cSrcweir ::comphelper::disposeComponent(_xResult); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir // ------------------------------------------------------------------------- 231*cdf0e10cSrcweir void ODescriptor::construct() 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir sal_Int32 nAttrib = isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY; 234*cdf0e10cSrcweir registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir // ------------------------------------------------------------------------- 237*cdf0e10cSrcweir ODescriptor::~ODescriptor() 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 241*cdf0e10cSrcweir 242