Tag: cws_src680_sdblogging
User: fs      
Date: 2007/04/05 02:14:45

Modified:
   dba/connectivity/source/manager/mdrivermanager.cxx

Log:
 #i76119# added logging calls

File Changes:

Directory: /dba/connectivity/source/manager/
============================================

File [changed]: mdrivermanager.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/manager/mdrivermanager.cxx?r1=1.16&r2=1.16.84.1
Delta lines:  +143 -66
----------------------
--- mdrivermanager.cxx  17 Sep 2006 03:08:25 -0000      1.16
+++ mdrivermanager.cxx  5 Apr 2007 09:14:42 -0000       1.16.84.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: mdrivermanager.cxx,v $
  *
- *  $Revision: 1.16 $
+ *  $Revision: 1.16.84.1 $
  *
- *  last change: $Author: obo $ $Date: 2006/09/17 03:08:25 $
+ *  last change: $Author: fs $ $Date: 2007/04/05 09:14:42 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -38,9 +38,7 @@
 
 #include <stdio.h>
 
-#ifndef _CONNECTIVITY_DRIVERMANAGER_HXX_
-#include "drivermanager.hxx"
-#endif
+#include "mdrivermanager.hxx"
 
 #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_
 #include <com/sun/star/sdbc/XDriver.hpp>
@@ -51,29 +49,24 @@
 #ifndef _COM_SUN_STAR_CONTAINER_ELEMENTEXISTEXCEPTION_HPP_
 #include <com/sun/star/container/ElementExistException.hpp>
 #endif
+#ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
+#include <com/sun/star/beans/NamedValue.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_SERVICENOTREGISTEREDEXCEPTION_HPP_
+#include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
+#endif
 
-#ifndef _COMPHELPER_EXTRACT_HXX_
+#include <tools/diagnose_ex.h>
 #include <comphelper/extract.hxx>
-#endif
-#ifndef _COMPHELPER_STLTYPES_HXX_
 #include <comphelper/stl_types.hxx>
-#endif
-#ifndef _CPPUHELPER_IMPLBASE1_HXX_
 #include <cppuhelper/implbase1.hxx>
-#endif
-#ifndef _OSL_DIAGNOSE_H_
+#include <cppuhelper/weakref.hxx>
 #include <osl/diagnose.h>
-#endif
-#ifndef CONNECTIVITY_DIAGNOSE_EX_H
-#include "diagnose_ex.h"
-#endif
 
 #include <algorithm>
 #include <functional>
 
-namespace connectivity
-{
-namespace sdbc
+namespace drivermanager
 {
 
 using namespace ::com::sun::star::uno;
@@ -81,6 +74,7 @@
 using namespace ::com::sun::star::sdbc;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::logging;
 using namespace ::osl;
 
 #define SERVICE_SDBC_DRIVER            
::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver")
@@ -220,7 +214,7 @@
        //---------------------------------------------------------------------
        //--- 24.08.01 12:51:54 -----------------------------------------------
 
-       static sal_Int32 lcl_getDriverPrecedence( const Reference< 
XMultiServiceFactory >&      _rxFactory, Sequence< ::rtl::OUString >& 
_rPrecedence )
+    static sal_Int32 lcl_getDriverPrecedence( const 
::comphelper::ComponentContext& _rContext, Sequence< ::rtl::OUString >& 
_rPrecedence )
        {
                _rPrecedence.realloc( 0 );
                try
@@ -238,15 +232,13 @@
                                
::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess");
 
                        // create a configuration provider
-                       Reference< XMultiServiceFactory > 
xConfigurationProvider(
-                               
_rxFactory->createInstance(sConfigurationProviderServiceName),
-                               UNO_QUERY);
-                       OSL_ENSURE(xConfigurationProvider.is(), 
"lcl_getDriverPrecedence: could not instantiate the configuration provider!");
-                       if (xConfigurationProvider.is())
-                       {
+                       Reference< XMultiServiceFactory > 
xConfigurationProvider;
+            if ( !_rContext.createComponent( 
sConfigurationProviderServiceName, xConfigurationProvider ) )
+                throw ServiceNotRegisteredException( 
sConfigurationProviderServiceName, NULL );
+
                                // one argument for creating the node access: 
the path to the configuration node
                                Sequence< Any > aCreationArgs(1);
-                               aCreationArgs[0] <<= 
PropertyValue(sNodePathArgumentName, 0, makeAny(sDriverManagerConfigLocation), 
PropertyState_DIRECT_VALUE);
+                       aCreationArgs[0] <<= NamedValue( sNodePathArgumentName, 
makeAny( sDriverManagerConfigLocation ) );
 
                                // create the node access
                                Reference< XNameAccess > 
xDriverManagerNode(xConfigurationProvider->createInstanceWithArguments(sNodeAccessServiceName,
 aCreationArgs), UNO_QUERY);
@@ -256,18 +248,16 @@
                                {
                                        // obtain the preference list
                                        Any aPreferences = 
xDriverManagerNode->getByName(sDriverPreferenceLocation);
-    #if OSL_DEBUG_LEVEL > 0
+#if OSL_DEBUG_LEVEL > 0
                                        sal_Bool bSuccess =
-       #endif
+#endif
                                        aPreferences >>= _rPrecedence;
                                        OSL_ENSURE(bSuccess || 
!aPreferences.hasValue(), "lcl_getDriverPrecedence: invalid value for the 
preferences node (no string sequence but not NULL)!");
                                }
                        }
-               }
-               catch( const Exception& e)
+               catch( const Exception& )
                {
-                       OSL_UNUSED( e );
-                       OSL_ENSURE( sal_False, "lcl_getDriverPrecedence: caught 
an exception!" );
+            DBG_UNHANDLED_EXCEPTION();
                }
 
                return _rPrecedence.getLength();
@@ -308,8 +298,9 @@
 //= OSDBCDriverManager
 //==========================================================================
 //--------------------------------------------------------------------------
-OSDBCDriverManager::OSDBCDriverManager(const Reference< XMultiServiceFactory 
>&        _rxFactory)
-       :m_xServiceFactory(_rxFactory)
+    OSDBCDriverManager::OSDBCDriverManager( const Reference< XComponentContext 
>& _rxContext )
+       :m_aContext( _rxContext )
+    ,m_aEventLogger( _rxContext, "org.openoffice.logging.sdbc.DriverManager" )
        ,m_nLoginTimeout(0)
 {
        // bootstrap all objects supporting the .sdb.Driver service
@@ -320,11 +311,16 @@
 }
 
 //---------------------------------------------------------------------
+OSDBCDriverManager::~OSDBCDriverManager()
+{
+}
+
+//---------------------------------------------------------------------
 //--- 24.08.01 11:15:32 -----------------------------------------------
 
 void OSDBCDriverManager::bootstrapDrivers()
 {
-       Reference< XContentEnumerationAccess > xEnumAccess(m_xServiceFactory, 
UNO_QUERY);
+       Reference< XContentEnumerationAccess > xEnumAccess( 
m_aContext.getLegacyServiceFactory(), UNO_QUERY );
        Reference< XEnumeration > xEnumDrivers;
        if (xEnumAccess.is())
                xEnumDrivers = 
xEnumAccess->createContentEnumeration(SERVICE_SDBC_DRIVER);
@@ -352,6 +348,11 @@
                                        aDriverDescriptor.sImplementationName = 
xSI->getImplementationName();
                                        aDriverDescriptor.xComponentFactory = 
xFactory;
                                        bValidDescriptor = sal_True;
+
+                    m_aEventLogger.log( LogLevel::CONFIG,
+                        "found SDBC driver $1$, no need to load it",
+                        aDriverDescriptor.sImplementationName
+                    );
                                }
                                else
                                {
@@ -369,6 +370,11 @@
                                                {
                                                        
aDriverDescriptor.sImplementationName = xSI->getImplementationName();
                                                        bValidDescriptor = 
sal_True;
+
+                            m_aEventLogger.log( LogLevel::CONFIG,
+                                "found SDBC driver $1$, needed to load it",
+                                aDriverDescriptor.sImplementationName
+                            );
                                                }
                                        }
                                }
@@ -393,12 +399,22 @@
        {
                // get the precedence of the drivers from the configuration
                Sequence< ::rtl::OUString > aDriverOrder;
-               if ( 0 == lcl_getDriverPrecedence( m_xServiceFactory, 
aDriverOrder ) )
+               if ( 0 == lcl_getDriverPrecedence( m_aContext, aDriverOrder ) )
                        // nothing to do
                        return;
 
                // aDriverOrder now is the list of driver implementation names 
in the order they should be used
 
+        if ( m_aEventLogger.isLoggable( LogLevel::CONFIG ) )
+        {
+            sal_Int32 nOrderedCount = aDriverOrder.getLength();
+            for ( sal_Int32 i=0; i<nOrderedCount; ++i )
+            m_aEventLogger.log( LogLevel::CONFIG,
+                "configuration's driver order: driver $1$ of $2$: $3$",
+                (sal_Int32)(i + 1), nOrderedCount, aDriverOrder[i]
+            );
+        }
+
                // sort our bootstrapped drivers
                ::std::sort( m_aDriversBS.begin(), m_aDriversBS.end(), 
CompareDriverAccessByName() );
 
@@ -446,12 +462,23 @@
 {
        MutexGuard aGuard(m_aMutex);
 
+    m_aEventLogger.log( LogLevel::INFO,
+        "connection requested for URL $1$",
+        _rURL
+    );
+
        Reference< XConnection > xConnection;
        Reference< XDriver > xDriver = implGetDriverForURL(_rURL);
        if (xDriver.is())
+    {
                // TODO : handle the login timeout
                xConnection = xDriver->connect(_rURL, Sequence< PropertyValue 
>());
                // may throw an exception
+        m_aEventLogger.log( LogLevel::INFO,
+            "connection retrieved for URL $1$",
+            _rURL
+        );
+    }
 
        return xConnection;
 }
@@ -461,12 +488,23 @@
 {
        MutexGuard aGuard(m_aMutex);
 
+    m_aEventLogger.log( LogLevel::INFO,
+        "connection with info requested for URL $1$",
+        _rURL
+    );
+
        Reference< XConnection > xConnection;
        Reference< XDriver > xDriver = implGetDriverForURL(_rURL);
        if (xDriver.is())
+    {
                // TODO : handle the login timeout
                xConnection = xDriver->connect(_rURL, _rInfo);
                // may throw an exception
+        m_aEventLogger.log( LogLevel::INFO,
+            "connection with info retrieved for URL $1$",
+            _rURL
+        );
+    }
 
        return xConnection;
 }
@@ -530,7 +568,7 @@
 //--------------------------------------------------------------------------
 ::rtl::OUString SAL_CALL OSDBCDriverManager::getImplementationName(  ) 
throw(RuntimeException)
 {
-       return getImplementationName_Static();
+       return getImplementationName_static();
 }
 
 //--------------------------------------------------------------------------
@@ -548,30 +586,37 @@
 //--------------------------------------------------------------------------
 Sequence< ::rtl::OUString > SAL_CALL 
OSDBCDriverManager::getSupportedServiceNames(  ) throw(RuntimeException)
 {
-       return getSupportedServiceNames_Static();
+       return getSupportedServiceNames_static();
 }
 
 //--------------------------------------------------------------------------
-Reference< XInterface > SAL_CALL OSDBCDriverManager::CreateInstance(const 
Reference< XMultiServiceFactory >& _rxFactory)
+Reference< XInterface > SAL_CALL OSDBCDriverManager::Create( const Reference< 
XMultiServiceFactory >& _rxFactory )
 {
-       return static_cast<XDriverManager*>(new OSDBCDriverManager(_rxFactory));
+    ::comphelper::ComponentContext aContext( _rxFactory );
+    return *( new OSDBCDriverManager( aContext.getUNOContext() ) );
 }
 
 //--------------------------------------------------------------------------
-::rtl::OUString SAL_CALL OSDBCDriverManager::getImplementationName_Static(  ) 
throw(RuntimeException)
+::rtl::OUString SAL_CALL OSDBCDriverManager::getImplementationName_static(  ) 
throw(RuntimeException)
 {
-       return 
::rtl::OUString::createFromAscii("com.sun.star.sdbc.OSDBCDriverManager");
+       return 
::rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.OSDBCDriverManager");
 }
 
 //--------------------------------------------------------------------------
-Sequence< ::rtl::OUString > SAL_CALL 
OSDBCDriverManager::getSupportedServiceNames_Static(  ) throw(RuntimeException)
+Sequence< ::rtl::OUString > SAL_CALL 
OSDBCDriverManager::getSupportedServiceNames_static(  ) throw(RuntimeException)
 {
        Sequence< ::rtl::OUString > aSupported(1);
-       aSupported[0] = 
::rtl::OUString::createFromAscii("com.sun.star.sdbc.DriverManager");
+       aSupported[0] = getSingletonName_static();
        return aSupported;
 }
 
 //--------------------------------------------------------------------------
+::rtl::OUString SAL_CALL OSDBCDriverManager::getSingletonName_static(  ) 
throw(RuntimeException)
+{
+    return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"com.sun.star.sdbc.DriverManager" ) );
+}
+
+//--------------------------------------------------------------------------
 Reference< XInterface > SAL_CALL OSDBCDriverManager::getRegisteredObject( 
const ::rtl::OUString& _rName ) throw(Exception, RuntimeException)
 {
        MutexGuard aGuard(m_aMutex);
@@ -586,6 +631,12 @@
 void SAL_CALL OSDBCDriverManager::registerObject( const ::rtl::OUString& 
_rName, const Reference< XInterface >& _rxObject ) throw(Exception, 
RuntimeException)
 {
        MutexGuard aGuard(m_aMutex);
+
+    m_aEventLogger.log( LogLevel::INFO,
+        "attempt to register new driver for name $1$",
+        _rName
+    );
+
        ConstDriverCollectionIterator aSearch = m_aDriversRT.find(_rName);
        if (aSearch == m_aDriversRT.end())
        {
@@ -597,23 +648,52 @@
        }
        else
                throw ElementExistException();
+
+    m_aEventLogger.log( LogLevel::INFO,
+        "new driver registered for name $1$",
+        _rName
+    );
 }
 
 //--------------------------------------------------------------------------
 void SAL_CALL OSDBCDriverManager::revokeObject( const ::rtl::OUString& _rName 
) throw(Exception, RuntimeException)
 {
        MutexGuard aGuard(m_aMutex);
+
+    m_aEventLogger.log( LogLevel::INFO,
+        "attempt to revoke driver for name $1$",
+        _rName
+    );
+
        DriverCollectionIterator aSearch = m_aDriversRT.find(_rName);
        if (aSearch == m_aDriversRT.end())
                throwNoSuchElementException();
 
        m_aDriversRT.erase(aSearch); // we already have the iterator so we 
could use it
+
+    m_aEventLogger.log( LogLevel::INFO,
+        "driver revoked for name $1$",
+        _rName
+    );
 }
 
 //--------------------------------------------------------------------------
 Reference< XDriver > SAL_CALL OSDBCDriverManager::getDriverByURL( const 
::rtl::OUString& _rURL ) throw(RuntimeException)
 {
-       return implGetDriverForURL(_rURL);
+    m_aEventLogger.log( LogLevel::INFO,
+        "driver requested for URL $1$",
+        _rURL
+    );
+
+    Reference< XDriver > xDriver( implGetDriverForURL( _rURL ) );
+
+    if ( xDriver.is() )
+        m_aEventLogger.log( LogLevel::INFO,
+            "driver obtained for URL $1$",
+            _rURL
+        );
+
+    return xDriver;
 }
 
 //--------------------------------------------------------------------------
@@ -652,7 +732,4 @@
        return xReturn;
 }
 
-}      // namespace connectivity
-}      // namespace sdbc
-
-
+}      // namespace drivermanager




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to