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_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "browserids.hxx" 32*cdf0e10cSrcweir #include "commontypes.hxx" 33*cdf0e10cSrcweir #include "dataview.hxx" 34*cdf0e10cSrcweir #include "dbu_misc.hrc" 35*cdf0e10cSrcweir #include "dbustrings.hrc" 36*cdf0e10cSrcweir #include "moduledbu.hxx" 37*cdf0e10cSrcweir #include "dbsubcomponentcontroller.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** === begin UNO includes === **/ 40*cdf0e10cSrcweir #include <com/sun/star/frame/XUntitledNumbers.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/frame/XUntitledNumbers.hpp> 49*cdf0e10cSrcweir /** === end UNO includes === **/ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 52*cdf0e10cSrcweir #include <comphelper/types.hxx> 53*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 54*cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 55*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 56*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 57*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 58*cdf0e10cSrcweir #include <tools/debug.hxx> 59*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 60*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //........................................................................ 63*cdf0e10cSrcweir namespace dbaui 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir //........................................................................ 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir /** === begin UNO using === **/ 68*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 69*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 70*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 71*cdf0e10cSrcweir using ::com::sun::star::util::XNumberFormatter; 72*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 73*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 74*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 75*cdf0e10cSrcweir using ::com::sun::star::uno::Type; 76*cdf0e10cSrcweir using ::com::sun::star::sdbc::XConnection; 77*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 78*cdf0e10cSrcweir using ::com::sun::star::container::XChild; 79*cdf0e10cSrcweir using ::com::sun::star::sdbc::XDataSource; 80*cdf0e10cSrcweir using ::com::sun::star::util::XNumberFormatter; 81*cdf0e10cSrcweir using ::com::sun::star::util::XNumberFormatsSupplier; 82*cdf0e10cSrcweir using ::com::sun::star::frame::XFrame; 83*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 84*cdf0e10cSrcweir using ::com::sun::star::sdbc::SQLException; 85*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 86*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue; 87*cdf0e10cSrcweir using ::com::sun::star::frame::XModel; 88*cdf0e10cSrcweir using ::com::sun::star::sdb::XOfficeDatabaseDocument; 89*cdf0e10cSrcweir using ::com::sun::star::awt::XWindow; 90*cdf0e10cSrcweir using ::com::sun::star::sdbc::XDatabaseMetaData; 91*cdf0e10cSrcweir using ::com::sun::star::sdb::XDocumentDataSource; 92*cdf0e10cSrcweir using ::com::sun::star::document::XEmbeddedScripts; 93*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 94*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 95*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 96*cdf0e10cSrcweir using ::com::sun::star::frame::XUntitledNumbers; 97*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyVetoException; 98*cdf0e10cSrcweir /** === end UNO using === **/ 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir class DataSourceHolder 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir public: 103*cdf0e10cSrcweir DataSourceHolder() 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir DataSourceHolder( const Reference< XDataSource >& _rxDataSource ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir m_xDataSource = _rxDataSource; 110*cdf0e10cSrcweir Reference< XDocumentDataSource > xDocDS( m_xDataSource, UNO_QUERY ); 111*cdf0e10cSrcweir if ( xDocDS.is() ) 112*cdf0e10cSrcweir m_xDocument = xDocDS->getDatabaseDocument(); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir m_xDataSourceProps.set( m_xDataSource, UNO_QUERY ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir const Reference< XDataSource >& getDataSource() const { return m_xDataSource; } 118*cdf0e10cSrcweir const Reference< XPropertySet >& getDataSourceProps() const { return m_xDataSourceProps; } 119*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument > getDatabaseDocument() const { return m_xDocument; } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir bool is() const { return m_xDataSource.is(); } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir void clear() 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir m_xDataSource.clear(); 126*cdf0e10cSrcweir m_xDocument.clear(); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir private: 130*cdf0e10cSrcweir Reference< XDataSource > m_xDataSource; 131*cdf0e10cSrcweir Reference< XPropertySet > m_xDataSourceProps; 132*cdf0e10cSrcweir Reference< XOfficeDatabaseDocument > m_xDocument; 133*cdf0e10cSrcweir }; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir struct DBSubComponentController_Impl 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir private: 138*cdf0e10cSrcweir ::boost::optional< bool > m_aDocScriptSupport; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir public: 141*cdf0e10cSrcweir OModuleClient m_aModuleClient; 142*cdf0e10cSrcweir ::dbtools::SQLExceptionInfo m_aCurrentError; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper 145*cdf0e10cSrcweir m_aModifyListeners; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // <properties> 148*cdf0e10cSrcweir SharedConnection m_xConnection; 149*cdf0e10cSrcweir ::dbtools::DatabaseMetaData m_aSdbMetaData; 150*cdf0e10cSrcweir // </properties> 151*cdf0e10cSrcweir ::rtl::OUString m_sDataSourceName; // the data source we're working for 152*cdf0e10cSrcweir DataSourceHolder m_aDataSource; 153*cdf0e10cSrcweir Reference< XModel > m_xDocument; 154*cdf0e10cSrcweir Reference< XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier 155*cdf0e10cSrcweir sal_Int32 m_nDocStartNumber; 156*cdf0e10cSrcweir sal_Bool m_bSuspended; // is true when the controller was already suspended 157*cdf0e10cSrcweir sal_Bool m_bEditable; // is the control readonly or not 158*cdf0e10cSrcweir sal_Bool m_bModified; // is the data modified 159*cdf0e10cSrcweir bool m_bNotAttached; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir DBSubComponentController_Impl( ::osl::Mutex& i_rMutex ) 162*cdf0e10cSrcweir :m_aDocScriptSupport() 163*cdf0e10cSrcweir ,m_aModifyListeners( i_rMutex ) 164*cdf0e10cSrcweir ,m_nDocStartNumber(0) 165*cdf0e10cSrcweir ,m_bSuspended( sal_False ) 166*cdf0e10cSrcweir ,m_bEditable(sal_True) 167*cdf0e10cSrcweir ,m_bModified(sal_False) 168*cdf0e10cSrcweir ,m_bNotAttached(true) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir bool documentHasScriptSupport() const 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir OSL_PRECOND( !!m_aDocScriptSupport, 175*cdf0e10cSrcweir "DBSubComponentController_Impl::documentHasScriptSupport: not completely initialized, yet - don't know!?" ); 176*cdf0e10cSrcweir return !!m_aDocScriptSupport && *m_aDocScriptSupport; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir void setDocumentScriptSupport( const bool _bSupport ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir OSL_PRECOND( !m_aDocScriptSupport, 182*cdf0e10cSrcweir "DBSubComponentController_Impl::setDocumentScriptSupport: already initialized!" ); 183*cdf0e10cSrcweir m_aDocScriptSupport = ::boost::optional< bool >( _bSupport ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir }; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //==================================================================== 188*cdf0e10cSrcweir //= DBSubComponentController 189*cdf0e10cSrcweir //==================================================================== 190*cdf0e10cSrcweir //-------------------------------------------------------------------- 191*cdf0e10cSrcweir DBSubComponentController::DBSubComponentController(const Reference< XMultiServiceFactory >& _rxORB) 192*cdf0e10cSrcweir :DBSubComponentController_Base( _rxORB ) 193*cdf0e10cSrcweir ,m_pImpl( new DBSubComponentController_Impl( getMutex() ) ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir //-------------------------------------------------------------------- 198*cdf0e10cSrcweir DBSubComponentController::~DBSubComponentController() 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //-------------------------------------------------------------------- 203*cdf0e10cSrcweir void DBSubComponentController::impl_initialize() 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir OGenericUnoController::impl_initialize(); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir const ::comphelper::NamedValueCollection& rArguments( getInitParams() ); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir Reference< XConnection > xConnection; 210*cdf0e10cSrcweir xConnection = rArguments.getOrDefault( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xConnection ); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir if ( !xConnection.is() ) 213*cdf0e10cSrcweir ::dbtools::isEmbeddedInDatabase( getModel(), xConnection ); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir if ( xConnection.is() ) 216*cdf0e10cSrcweir initializeConnection( xConnection ); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir bool bShowError = true; 219*cdf0e10cSrcweir if ( !isConnected() ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir reconnect( sal_False ); 222*cdf0e10cSrcweir bShowError = false; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir if ( !isConnected() ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir if ( bShowError ) 227*cdf0e10cSrcweir connectionLostMessage(); 228*cdf0e10cSrcweir throw IllegalArgumentException(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir //-------------------------------------------------------------------- 233*cdf0e10cSrcweir Any SAL_CALL DBSubComponentController::queryInterface(const Type& _rType) throw (RuntimeException) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir if ( _rType.equals( XScriptInvocationContext::static_type() ) ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir if ( m_pImpl->documentHasScriptSupport() ) 238*cdf0e10cSrcweir return makeAny( Reference< XScriptInvocationContext >( this ) ); 239*cdf0e10cSrcweir return Any(); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir return DBSubComponentController_Base::queryInterface( _rType ); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir //-------------------------------------------------------------------- 246*cdf0e10cSrcweir Sequence< Type > SAL_CALL DBSubComponentController::getTypes( ) throw (RuntimeException) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir Sequence< Type > aTypes( DBSubComponentController_Base::getTypes() ); 249*cdf0e10cSrcweir if ( !m_pImpl->documentHasScriptSupport() ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir Sequence< Type > aStrippedTypes( aTypes.getLength() - 1 ); 252*cdf0e10cSrcweir ::std::remove_copy_if( 253*cdf0e10cSrcweir aTypes.getConstArray(), 254*cdf0e10cSrcweir aTypes.getConstArray() + aTypes.getLength(), 255*cdf0e10cSrcweir aStrippedTypes.getArray(), 256*cdf0e10cSrcweir ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() ) 257*cdf0e10cSrcweir ); 258*cdf0e10cSrcweir aTypes = aStrippedTypes; 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir return aTypes; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir //-------------------------------------------------------------------- 264*cdf0e10cSrcweir void DBSubComponentController::initializeConnection( const Reference< XConnection >& _rxForeignConn ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir DBG_ASSERT( !isConnected(), "DBSubComponentController::initializeConnection: not to be called when already connected!" ); 267*cdf0e10cSrcweir // usually this gets called from within initialize of derived classes ... 268*cdf0e10cSrcweir if ( isConnected() ) 269*cdf0e10cSrcweir disconnect(); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir m_pImpl->m_xConnection.reset( _rxForeignConn, SharedConnection::NoTakeOwnership ); 272*cdf0e10cSrcweir m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection ); 273*cdf0e10cSrcweir startConnectionListening( m_pImpl->m_xConnection ); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // get the data source the connection belongs to 276*cdf0e10cSrcweir try 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir // determine our data source 279*cdf0e10cSrcweir OSL_PRECOND( !m_pImpl->m_aDataSource.is(), "DBSubComponentController::initializeConnection: already a data source in this phase?" ); 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir Reference< XChild > xConnAsChild( m_pImpl->m_xConnection, UNO_QUERY ); 282*cdf0e10cSrcweir Reference< XDataSource > xDS; 283*cdf0e10cSrcweir if ( xConnAsChild.is() ) 284*cdf0e10cSrcweir xDS = Reference< XDataSource >( xConnAsChild->getParent(), UNO_QUERY ); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // (take the indirection through XDataSource to ensure we have a correct object ....) 287*cdf0e10cSrcweir m_pImpl->m_aDataSource = xDS; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir OSL_POSTCOND( m_pImpl->m_aDataSource.is(), "DBSubComponentController::initializeConnection: unable to obtain the data source object!" ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir if ( m_pImpl->m_bNotAttached ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir Reference< XUntitledNumbers > xUntitledProvider( getDatabaseDocument(), UNO_QUERY ); 294*cdf0e10cSrcweir m_pImpl->m_nDocStartNumber = 1; 295*cdf0e10cSrcweir if ( xUntitledProvider.is() ) 296*cdf0e10cSrcweir m_pImpl->m_nDocStartNumber = xUntitledProvider->leaseNumber( static_cast< XWeak* >( this ) ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir // determine the availability of script support in our document. Our own XScriptInvocationContext 300*cdf0e10cSrcweir // interface depends on this 301*cdf0e10cSrcweir m_pImpl->setDocumentScriptSupport( Reference< XEmbeddedScripts >( getDatabaseDocument(), UNO_QUERY ).is() ); 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir // get a number formatter 304*cdf0e10cSrcweir Reference< XPropertySet > xDataSourceProps( m_pImpl->m_aDataSource.getDataSourceProps(), UNO_SET_THROW ); 305*cdf0e10cSrcweir xDataSourceProps->getPropertyValue( PROPERTY_NAME ) >>= m_pImpl->m_sDataSourceName; 306*cdf0e10cSrcweir DBG_ASSERT( m_pImpl->m_sDataSourceName.getLength(), "DBSubComponentController::initializeConnection: invalid data source name!" ); 307*cdf0e10cSrcweir Reference< XNumberFormatsSupplier> xSupplier = ::dbtools::getNumberFormats(m_pImpl->m_xConnection); 308*cdf0e10cSrcweir if(xSupplier.is()) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir m_pImpl->m_xFormatter = Reference< XNumberFormatter >(getORB() 311*cdf0e10cSrcweir ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")), UNO_QUERY); 312*cdf0e10cSrcweir m_pImpl->m_xFormatter->attachNumberFormatsSupplier(xSupplier); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir OSL_ENSURE(m_pImpl->m_xFormatter.is(),"No NumberFormatter!"); 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir catch( const Exception& ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //-------------------------------------------------------------------- 323*cdf0e10cSrcweir void DBSubComponentController::reconnect( sal_Bool _bUI ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir OSL_ENSURE(!m_pImpl->m_bSuspended, "Cannot reconnect while suspended!"); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir stopConnectionListening( m_pImpl->m_xConnection ); 328*cdf0e10cSrcweir m_pImpl->m_aSdbMetaData.reset( NULL ); 329*cdf0e10cSrcweir m_pImpl->m_xConnection.clear(); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir // reconnect 332*cdf0e10cSrcweir sal_Bool bReConnect = sal_True; 333*cdf0e10cSrcweir if ( _bUI ) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir QueryBox aQuery( getView(), ModuleRes(QUERY_CONNECTION_LOST) ); 336*cdf0e10cSrcweir bReConnect = ( RET_YES == aQuery.Execute() ); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir // now really reconnect ... 340*cdf0e10cSrcweir if ( bReConnect ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir m_pImpl->m_xConnection.reset( connect( m_pImpl->m_aDataSource.getDataSource(), NULL ), SharedConnection::TakeOwnership ); 343*cdf0e10cSrcweir m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection ); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir // invalidate all slots 347*cdf0e10cSrcweir InvalidateAll(); 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir //-------------------------------------------------------------------- 351*cdf0e10cSrcweir void DBSubComponentController::disconnect() 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir stopConnectionListening(m_pImpl->m_xConnection); 354*cdf0e10cSrcweir m_pImpl->m_aSdbMetaData.reset( NULL ); 355*cdf0e10cSrcweir m_pImpl->m_xConnection.clear(); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir InvalidateAll(); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir //-------------------------------------------------------------------- 361*cdf0e10cSrcweir void DBSubComponentController::losingConnection() 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir // our connection was disposed so we need a new one 364*cdf0e10cSrcweir reconnect( sal_True ); 365*cdf0e10cSrcweir InvalidateAll(); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir //-------------------------------------------------------------------- 369*cdf0e10cSrcweir void SAL_CALL DBSubComponentController::disposing() 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir DBSubComponentController_Base::disposing(); 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir disconnect(); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir attachFrame( Reference < XFrame >() ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir m_pImpl->m_aDataSource.clear(); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir //-------------------------------------------------------------------- 381*cdf0e10cSrcweir void SAL_CALL DBSubComponentController::disposing(const EventObject& _rSource) throw( RuntimeException ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir if ( _rSource.Source == getConnection() ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir if ( !m_pImpl->m_bSuspended // when already suspended then we don't have to reconnect 386*cdf0e10cSrcweir && !getBroadcastHelper().bInDispose 387*cdf0e10cSrcweir && !getBroadcastHelper().bDisposed 388*cdf0e10cSrcweir && isConnected() 389*cdf0e10cSrcweir ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir losingConnection(); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir else 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir m_pImpl->m_xConnection.reset( m_pImpl->m_xConnection, SharedConnection::NoTakeOwnership ); 396*cdf0e10cSrcweir // this prevents the "disposeComponent" call in disconnect 397*cdf0e10cSrcweir disconnect(); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir else 401*cdf0e10cSrcweir DBSubComponentController_Base::disposing( _rSource ); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir //-------------------------------------------------------------------- 405*cdf0e10cSrcweir void DBSubComponentController::appendError( const ::rtl::OUString& _rErrorMessage, const ::dbtools::StandardSQLState _eSQLState, 406*cdf0e10cSrcweir const sal_Int32 _nErrorCode ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir m_pImpl->m_aCurrentError.append( ::dbtools::SQLExceptionInfo::SQL_EXCEPTION, _rErrorMessage, getStandardSQLStateAscii( _eSQLState ), 409*cdf0e10cSrcweir _nErrorCode ); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir //-------------------------------------------------------------------- 412*cdf0e10cSrcweir void DBSubComponentController::clearError() 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir m_pImpl->m_aCurrentError = ::dbtools::SQLExceptionInfo(); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir //-------------------------------------------------------------------- 418*cdf0e10cSrcweir sal_Bool DBSubComponentController::hasError() const 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir return m_pImpl->m_aCurrentError.isValid(); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //-------------------------------------------------------------------- 424*cdf0e10cSrcweir const ::dbtools::SQLExceptionInfo& DBSubComponentController::getError() const 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir return m_pImpl->m_aCurrentError; 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir //-------------------------------------------------------------------- 430*cdf0e10cSrcweir void DBSubComponentController::displayError() 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir showError( m_pImpl->m_aCurrentError ); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //-------------------------------------------------------------------- 436*cdf0e10cSrcweir sal_Bool SAL_CALL DBSubComponentController::suspend(sal_Bool bSuspend) throw( RuntimeException ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir m_pImpl->m_bSuspended = bSuspend; 439*cdf0e10cSrcweir if ( !bSuspend && !isConnected() ) 440*cdf0e10cSrcweir reconnect(sal_True); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir return sal_True; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 447*cdf0e10cSrcweir sal_Bool SAL_CALL DBSubComponentController::attachModel( const Reference< XModel > & _rxModel) throw( RuntimeException ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir if ( !_rxModel.is() ) 450*cdf0e10cSrcweir return sal_False; 451*cdf0e10cSrcweir if ( !DBSubComponentController_Base::attachModel( _rxModel ) ) 452*cdf0e10cSrcweir return sal_False; 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir m_pImpl->m_bNotAttached = false; 455*cdf0e10cSrcweir if ( m_pImpl->m_nDocStartNumber == 1 ) 456*cdf0e10cSrcweir releaseNumberForComponent(); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir Reference< XUntitledNumbers > xUntitledProvider( _rxModel, UNO_QUERY ); 459*cdf0e10cSrcweir m_pImpl->m_nDocStartNumber = 1; 460*cdf0e10cSrcweir if ( xUntitledProvider.is() ) 461*cdf0e10cSrcweir m_pImpl->m_nDocStartNumber = xUntitledProvider->leaseNumber( static_cast< XWeak* >( this ) ); 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir return sal_True; 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 467*cdf0e10cSrcweir void DBSubComponentController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& _rArgs) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir if ( _nId == ID_BROWSER_CLOSE ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir closeTask(); 472*cdf0e10cSrcweir return; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir DBSubComponentController_Base::Execute( _nId, _rArgs ); 476*cdf0e10cSrcweir InvalidateFeature( _nId ); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 480*cdf0e10cSrcweir ::rtl::OUString DBSubComponentController::getDataSourceName() const 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir ::rtl::OUString sName; 483*cdf0e10cSrcweir Reference< XPropertySet > xDataSourceProps( m_pImpl->m_aDataSource.getDataSourceProps() ); 484*cdf0e10cSrcweir if ( xDataSourceProps.is() ) 485*cdf0e10cSrcweir xDataSourceProps->getPropertyValue(PROPERTY_NAME) >>= sName; 486*cdf0e10cSrcweir return sName; 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 489*cdf0e10cSrcweir void DBSubComponentController::connectionLostMessage() const 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir String aMessage(ModuleRes(RID_STR_CONNECTION_LOST)); 492*cdf0e10cSrcweir Reference< XWindow > xWindow = getTopMostContainerWindow(); 493*cdf0e10cSrcweir Window* pWin = NULL; 494*cdf0e10cSrcweir if ( xWindow.is() ) 495*cdf0e10cSrcweir pWin = VCLUnoHelper::GetWindow(xWindow); 496*cdf0e10cSrcweir if ( !pWin ) 497*cdf0e10cSrcweir pWin = getView()->Window::GetParent(); 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir InfoBox(pWin, aMessage).Execute(); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 502*cdf0e10cSrcweir const Reference< XConnection >& DBSubComponentController::getConnection() const 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir return m_pImpl->m_xConnection; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 508*cdf0e10cSrcweir sal_Bool DBSubComponentController::isReadOnly() const 509*cdf0e10cSrcweir { 510*cdf0e10cSrcweir return !m_pImpl->m_bEditable; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 514*cdf0e10cSrcweir sal_Bool DBSubComponentController::isEditable() const 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir return m_pImpl->m_bEditable; 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 520*cdf0e10cSrcweir void DBSubComponentController::setEditable(sal_Bool _bEditable) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir m_pImpl->m_bEditable = _bEditable; 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 526*cdf0e10cSrcweir const ::dbtools::DatabaseMetaData& DBSubComponentController::getSdbMetaData() const 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir return m_pImpl->m_aSdbMetaData; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 532*cdf0e10cSrcweir sal_Bool DBSubComponentController::isConnected() const 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir return m_pImpl->m_xConnection.is(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 538*cdf0e10cSrcweir Reference< XDatabaseMetaData > DBSubComponentController::getMetaData( ) const 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir Reference< XDatabaseMetaData > xMeta; 541*cdf0e10cSrcweir try 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir if ( isConnected() ) 544*cdf0e10cSrcweir xMeta.set( m_pImpl->m_xConnection->getMetaData(), UNO_SET_THROW ); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir catch( const Exception& ) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir return xMeta; 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 554*cdf0e10cSrcweir const Reference< XPropertySet >& DBSubComponentController::getDataSource() const 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir return m_pImpl->m_aDataSource.getDataSourceProps(); 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 560*cdf0e10cSrcweir sal_Bool DBSubComponentController::haveDataSource() const 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir return m_pImpl->m_aDataSource.is(); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 566*cdf0e10cSrcweir Reference< XModel > DBSubComponentController::getDatabaseDocument() const 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir return Reference< XModel >( m_pImpl->m_aDataSource.getDatabaseDocument(), UNO_QUERY ); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 572*cdf0e10cSrcweir Reference< XNumberFormatter > DBSubComponentController::getNumberFormatter() const 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir return m_pImpl->m_xFormatter; 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 578*cdf0e10cSrcweir Reference< XModel > DBSubComponentController::getPrivateModel() const 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir return getDatabaseDocument(); 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 583*cdf0e10cSrcweir // XTitle 584*cdf0e10cSrcweir ::rtl::OUString SAL_CALL DBSubComponentController::getTitle() 585*cdf0e10cSrcweir throw (RuntimeException) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 588*cdf0e10cSrcweir if ( m_bExternalTitle ) 589*cdf0e10cSrcweir return impl_getTitleHelper_throw()->getTitle (); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir ::rtl::OUStringBuffer sTitle; 592*cdf0e10cSrcweir Reference< XTitle > xTitle(getPrivateModel(),UNO_QUERY); 593*cdf0e10cSrcweir if ( xTitle.is() ) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir sTitle.append( xTitle->getTitle() ); 596*cdf0e10cSrcweir sTitle.appendAscii(" : "); 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir sTitle.append( getPrivateTitle() ); 599*cdf0e10cSrcweir return sTitle.makeStringAndClear(); 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 603*cdf0e10cSrcweir sal_Int32 DBSubComponentController::getCurrentStartNumber() const 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir return m_pImpl->m_nDocStartNumber; 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 609*cdf0e10cSrcweir Reference< XEmbeddedScripts > SAL_CALL DBSubComponentController::getScriptContainer() throw (RuntimeException) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 612*cdf0e10cSrcweir if ( !m_pImpl->documentHasScriptSupport() ) 613*cdf0e10cSrcweir return NULL; 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir return Reference< XEmbeddedScripts >( getDatabaseDocument(), UNO_QUERY_THROW ); 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 619*cdf0e10cSrcweir void SAL_CALL DBSubComponentController::addModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 622*cdf0e10cSrcweir m_pImpl->m_aModifyListeners.addInterface( i_Listener ); 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 626*cdf0e10cSrcweir void SAL_CALL DBSubComponentController::removeModifyListener( const Reference< XModifyListener >& i_Listener ) throw (RuntimeException) 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 629*cdf0e10cSrcweir m_pImpl->m_aModifyListeners.removeInterface( i_Listener ); 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 633*cdf0e10cSrcweir ::sal_Bool SAL_CALL DBSubComponentController::isModified( ) throw (RuntimeException) 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 636*cdf0e10cSrcweir return impl_isModified(); 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 640*cdf0e10cSrcweir void SAL_CALL DBSubComponentController::setModified( ::sal_Bool i_bModified ) throw (PropertyVetoException, RuntimeException) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( getMutex() ); 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir if ( m_pImpl->m_bModified == i_bModified ) 645*cdf0e10cSrcweir return; 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir m_pImpl->m_bModified = i_bModified; 648*cdf0e10cSrcweir impl_onModifyChanged(); 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir EventObject aEvent( *this ); 651*cdf0e10cSrcweir aGuard.clear(); 652*cdf0e10cSrcweir m_pImpl->m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent ); 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 656*cdf0e10cSrcweir sal_Bool DBSubComponentController::impl_isModified() const 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir return m_pImpl->m_bModified; 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 662*cdf0e10cSrcweir void DBSubComponentController::impl_onModifyChanged() 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_SAVEDOC ); 665*cdf0e10cSrcweir if ( isFeatureSupported( ID_BROWSER_SAVEASDOC ) ) 666*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_SAVEASDOC ); 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir //........................................................................ 670*cdf0e10cSrcweir } // namespace dbaui 671*cdf0e10cSrcweir //........................................................................ 672*cdf0e10cSrcweir 673