Tag: cws_src680_qiq
User: fs      
Date: 06/05/23 23:46:57

Modified:
 /dba/dbaccess/source/ui/misc/
  defaultobjectnamecheck.cxx

Log:
 parts of this now implemented using XObjectNames from the connection

File Changes:

Directory: /dba/dbaccess/source/ui/misc/
========================================

File [changed]: defaultobjectnamecheck.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/misc/defaultobjectnamecheck.cxx?r1=1.1.2.2&r2=1.1.2.3
Delta lines:  +26 -134
----------------------
--- defaultobjectnamecheck.cxx  18 May 2006 09:17:37 -0000      1.1.2.2
+++ defaultobjectnamecheck.cxx  24 May 2006 06:46:54 -0000      1.1.2.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: defaultobjectnamecheck.cxx,v $
  *
- *  $Revision: 1.1.2.2 $
+ *  $Revision: 1.1.2.3 $
  *
- *  last change: $Author: fs $ $Date: 2006/05/18 09:17:37 $
+ *  last change: $Author: fs $ $Date: 2006/05/24 06:46:54 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -58,6 +58,9 @@
 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
 #include <com/sun/star/sdb/CommandType.hpp>
 #endif
+#ifndef _COM_SUN_STAR_SDB_TOOLS_XCONNECTIONTOOLS_HPP_
+#include <com/sun/star/sdb/tools/XConnectionTools.hpp>
+#endif
 /** === end UNO includes === **/
 
 #ifndef _DBHELPER_DBEXCEPTION_HXX_
@@ -99,6 +102,9 @@
     using ::com::sun::star::uno::UNO_QUERY_THROW;
     using ::com::sun::star::uno::makeAny;
     using ::com::sun::star::uno::Any;
+    using ::com::sun::star::sdb::tools::XObjectNames;
+    using ::com::sun::star::sdb::tools::XConnectionTools;
+    using ::com::sun::star::uno::UNO_QUERY;
        /** === end UNO using === **/
 
     using namespace dbtools;
@@ -157,49 +163,6 @@
 
             return xContainer;
         }
-
-    }
-
-       //====================================================================
-       //= PlainNameCheck_Impl
-       //====================================================================
-       struct PlainNameCheck_Impl
-    {
-        Reference< XNameAccess >    xNames;
-    };
-
-    //====================================================================
-       //= PlainNameCheck
-       //====================================================================
-       //--------------------------------------------------------------------
-    PlainNameCheck::PlainNameCheck( const Reference< XNameAccess >& 
_rxContainer )
-        :m_pImpl( new PlainNameCheck_Impl )
-    {
-        m_pImpl->xNames = _rxContainer;
-        if ( !m_pImpl->xNames.is() )
-            throw IllegalArgumentException();
-    }
-
-       //--------------------------------------------------------------------
-    PlainNameCheck::~PlainNameCheck()
-    {
-    }
-
-    //--------------------------------------------------------------------
-    bool PlainNameCheck::isNameValid( const ::rtl::OUString& _rObjectName, 
SQLExceptionInfo& _out_rErrorToDisplay ) const
-    {
-        try
-        {
-            if ( !m_pImpl->xNames->hasByName( _rObjectName ) )
-                return true;
-        }
-        catch( const Exception& )
-        {
-               DBG_UNHANDLED_EXCEPTION();
-        }
-
-        lcl_fillNameExistsError( _rObjectName, _out_rErrorToDisplay );
-        return false;
     }
 
        //====================================================================
@@ -257,81 +220,12 @@
     }
 
     //====================================================================
-    //= TablesAndQueriesNameCheck_Impl
-    //====================================================================
-    typedef ::std::vector< ::boost::shared_ptr< IObjectNameCheck > >    
CheckerPtrArray;
-    struct TablesAndQueriesNameCheck_Impl
-    {
-        CheckerPtrArray aSlaveChecks;
-    };
-
-    namespace
-    {
-        /** constructs a TablesAndQueriesNameCheck instance
-        */
-        void    lcl_construct( TablesAndQueriesNameCheck_Impl& _rImpl, const 
Reference< XConnection >& _rxSdbLevelConnection )
-        {
-            try
-            {
-                _rImpl.aSlaveChecks.push_back( ::boost::shared_ptr< 
IObjectNameCheck >( new PlainNameCheck( 
-                    lcl_getObjectContainer( _rxSdbLevelConnection, 
CommandType::TABLE ) ) ) );
-
-                _rImpl.aSlaveChecks.push_back( ::boost::shared_ptr< 
IObjectNameCheck >( new PlainNameCheck( 
-                    lcl_getObjectContainer( _rxSdbLevelConnection, 
CommandType::QUERY ) ) ) );
-            }
-            catch( const Exception& )
-            {
-               DBG_UNHANDLED_EXCEPTION();
-            }
-        }
-    }
-
-    //====================================================================
-    //= TablesAndQueriesNameCheck
-    //====================================================================
-    //--------------------------------------------------------------------
-    TablesAndQueriesNameCheck::TablesAndQueriesNameCheck( const Reference< 
XConnection >& _rxSdbLevelConnection )
-        :m_pImpl( new TablesAndQueriesNameCheck_Impl )
-    {
-        lcl_construct( *m_pImpl, _rxSdbLevelConnection );
-    }
-
-    //--------------------------------------------------------------------
-    TablesAndQueriesNameCheck::~TablesAndQueriesNameCheck()
-    {
-    }
-
-    //--------------------------------------------------------------------
-    bool TablesAndQueriesNameCheck::isNameValid( const ::rtl::OUString& 
_rObjectName, ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay ) const
-    {
-        bool bIsValid = true;
-        for (   CheckerPtrArray::const_iterator loop = 
m_pImpl->aSlaveChecks.begin();
-                ( loop != m_pImpl->aSlaveChecks.end() ) && bIsValid;
-                ++loop
-            )
-        {
-            bIsValid &= (*loop)->isNameValid( _rObjectName, 
_out_rErrorToDisplay );
-        }
-
-        if ( bIsValid )
-            return true;
-
-        // adjust the error message
-        String sNameIsUsed( ModuleRes( STR_NAME_ALREADY_USED_IN_DB ) );
-        sNameIsUsed.SearchAndReplaceAllAscii( "$name$", _rObjectName );
-        String sNeedDistinctNames( ModuleRes( 
STR_QUERY_AND_TABLE_DISTINCT_NAMES ) );
-        _out_rErrorToDisplay = SQLException(
-            sNameIsUsed, NULL, ::rtl::OUString(), 0, makeAny( SQLException(
-                sNeedDistinctNames, NULL, ::rtl::OUString(), 0, Any() ) ) );
-        return false;
-    }
-
-    //====================================================================
     //= DynamicTableOrQueryNameCheck_Impl
     //====================================================================
     struct DynamicTableOrQueryNameCheck_Impl
     {
-        ::boost::shared_ptr< IObjectNameCheck > pDelegateeCheck;
+        sal_Int32                   nCommandType;
+        Reference< XObjectNames >   xObjectNames;
     };
 
     //====================================================================
@@ -341,26 +235,15 @@
     DynamicTableOrQueryNameCheck::DynamicTableOrQueryNameCheck( const 
Reference< XConnection >& _rxSdbLevelConnection, sal_Int32 _nCommandType )
         :m_pImpl( new DynamicTableOrQueryNameCheck_Impl )
     {
-        if ( !_rxSdbLevelConnection.is() )
+        Reference< XConnectionTools > xConnTools( _rxSdbLevelConnection, 
UNO_QUERY );
+        if ( xConnTools.is() )
+            m_pImpl->xObjectNames.set( xConnTools->createObjectNames() );
+        if ( !m_pImpl->xObjectNames.is() )
             throw IllegalArgumentException();
+
         if ( ( _nCommandType != CommandType::QUERY ) && ( _nCommandType != 
CommandType::TABLE ) )
             throw IllegalArgumentException();
-
-        bool bSupportsQueriesInFrom = false;
-        try
-        {
-            DatabaseMetaData aMeta( _rxSdbLevelConnection );
-            bSupportsQueriesInFrom = aMeta.supportsSubqueriesInFrom();
-        }
-        catch( const Exception& )
-        {
-               DBG_UNHANDLED_EXCEPTION();
-        }
-
-        if ( bSupportsQueriesInFrom )
-            m_pImpl->pDelegateeCheck.reset( new TablesAndQueriesNameCheck( 
_rxSdbLevelConnection ) );
-        else
-            m_pImpl->pDelegateeCheck.reset( new PlainNameCheck( 
lcl_getObjectContainer( _rxSdbLevelConnection, _nCommandType ) ) );
+        m_pImpl->nCommandType = _nCommandType;
     }
 
     //--------------------------------------------------------------------
@@ -371,7 +254,16 @@
     //--------------------------------------------------------------------
     bool DynamicTableOrQueryNameCheck::isNameValid( const ::rtl::OUString& 
_rObjectName, ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay ) const
     {
-        return m_pImpl->pDelegateeCheck->isNameValid( _rObjectName, 
_out_rErrorToDisplay );
+        try
+        {
+            m_pImpl->xObjectNames->checkNameIsUsed( m_pImpl->nCommandType, 
_rObjectName );
+            return true;
+        }
+        catch( const SQLException& )
+        {
+            _out_rErrorToDisplay = ::dbtools::SQLExceptionInfo( 
::cppu::getCaughtException() );
+        }
+        return false;
     }
 
 //........................................................................




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

Reply via email to