LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/sdbtools/connection - tablename.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 83 0.0 %
Date: 2012-12-27 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "tablename.hxx"
      22             : #include "sdbt_resource.hrc"
      23             : #include "module_sdbt.hxx"
      24             : #include "sdbtstrings.hrc"
      25             : 
      26             : #include <com/sun/star/lang/NullPointerException.hpp>
      27             : #include <com/sun/star/sdb/tools/CompositionType.hpp>
      28             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      29             : 
      30             : #include <connectivity/dbtools.hxx>
      31             : #include <tools/diagnose_ex.h>
      32             : #include <tools/string.hxx>
      33             : 
      34             : //........................................................................
      35             : namespace sdbtools
      36             : {
      37             : //........................................................................
      38             : 
      39             :     /** === begin UNO using === **/
      40             :     using ::com::sun::star::uno::Reference;
      41             :     using ::com::sun::star::sdbc::XConnection;
      42             :     using ::com::sun::star::lang::NullPointerException;
      43             :     using ::com::sun::star::uno::RuntimeException;
      44             :     using ::com::sun::star::lang::IllegalArgumentException;
      45             :     using ::com::sun::star::beans::XPropertySet;
      46             :     using ::com::sun::star::container::NoSuchElementException;
      47             :     using ::com::sun::star::sdbcx::XTablesSupplier;
      48             :     using ::com::sun::star::container::XNameAccess;
      49             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      50             :     using ::com::sun::star::lang::WrappedTargetException;
      51             :     using ::com::sun::star::uno::Exception;
      52             :     using ::com::sun::star::uno::UNO_QUERY;
      53             :     using ::com::sun::star::beans::XPropertySetInfo;
      54             :     /** === end UNO using === **/
      55             : 
      56             :     namespace CompositionType = ::com::sun::star::sdb::tools::CompositionType;
      57             : 
      58             :     using namespace ::dbtools;
      59             : 
      60             :     //====================================================================
      61             :     //= TableName
      62             :     //====================================================================
      63           0 :     struct TableName_Impl
      64             :     {
      65             :         SdbtClient      m_aModuleClient;    // keep the module alive as long as this instance lives
      66             : 
      67             :         ::rtl::OUString sCatalog;
      68             :         ::rtl::OUString sSchema;
      69             :         ::rtl::OUString sName;
      70             :     };
      71             : 
      72             :     //====================================================================
      73             :     //= TableName
      74             :     //====================================================================
      75             :     //--------------------------------------------------------------------
      76           0 :     TableName::TableName( const ::comphelper::ComponentContext& _rContext, const Reference< XConnection >& _rxConnection )
      77             :         :ConnectionDependentComponent( _rContext )
      78           0 :         ,m_pImpl( new TableName_Impl )
      79             :     {
      80           0 :         if ( !_rxConnection.is() )
      81           0 :             throw NullPointerException();
      82             : 
      83           0 :         setWeakConnection( _rxConnection );
      84           0 :     }
      85             : 
      86             :     //--------------------------------------------------------------------
      87           0 :     TableName::~TableName()
      88             :     {
      89           0 :     }
      90             : 
      91             :     //--------------------------------------------------------------------
      92           0 :     ::rtl::OUString SAL_CALL TableName::getCatalogName() throw (RuntimeException)
      93             :     {
      94           0 :         EntryGuard aGuard( *this );
      95           0 :         return m_pImpl->sCatalog;
      96             :     }
      97             : 
      98             :     //--------------------------------------------------------------------
      99           0 :     void SAL_CALL TableName::setCatalogName( const ::rtl::OUString& _catalogName ) throw (RuntimeException)
     100             :     {
     101           0 :         EntryGuard aGuard( *this );
     102           0 :         m_pImpl->sCatalog = _catalogName;
     103           0 :     }
     104             : 
     105             :     //--------------------------------------------------------------------
     106           0 :     ::rtl::OUString SAL_CALL TableName::getSchemaName() throw (RuntimeException)
     107             :     {
     108           0 :         EntryGuard aGuard( *this );
     109           0 :         return m_pImpl->sSchema;
     110             :     }
     111             : 
     112             :     //--------------------------------------------------------------------
     113           0 :     void SAL_CALL TableName::setSchemaName( const ::rtl::OUString& _schemaName ) throw (RuntimeException)
     114             :     {
     115           0 :         EntryGuard aGuard( *this );
     116           0 :         m_pImpl->sSchema = _schemaName;
     117           0 :     }
     118             : 
     119             :     //--------------------------------------------------------------------
     120           0 :     ::rtl::OUString SAL_CALL TableName::getTableName() throw (RuntimeException)
     121             :     {
     122           0 :         EntryGuard aGuard( *this );
     123           0 :         return m_pImpl->sName;
     124             :     }
     125             : 
     126             :     //--------------------------------------------------------------------
     127           0 :     void SAL_CALL TableName::setTableName( const ::rtl::OUString& _tableName ) throw (RuntimeException)
     128             :     {
     129           0 :         EntryGuard aGuard( *this );
     130           0 :         m_pImpl->sName = _tableName;
     131           0 :     }
     132             : 
     133             :     //--------------------------------------------------------------------
     134           0 :     ::rtl::OUString SAL_CALL TableName::getNameForSelect() throw (RuntimeException)
     135             :     {
     136           0 :         EntryGuard aGuard( *this );
     137           0 :         return composeTableNameForSelect( getConnection(), m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName );
     138             :     }
     139             : 
     140             :     //--------------------------------------------------------------------
     141           0 :     Reference< XPropertySet > SAL_CALL TableName::getTable() throw (NoSuchElementException, RuntimeException)
     142             :     {
     143           0 :         EntryGuard aGuard( *this );
     144             : 
     145           0 :         Reference< XTablesSupplier > xSuppTables( getConnection(), UNO_QUERY_THROW );
     146           0 :         Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW );
     147             : 
     148           0 :         Reference< XPropertySet > xTable;
     149             :         try
     150             :         {
     151           0 :             xTable.set( xTables->getByName( getComposedName( CompositionType::Complete, sal_False ) ), UNO_QUERY_THROW );
     152             :         }
     153           0 :         catch( const WrappedTargetException& )
     154             :         {
     155           0 :             throw NoSuchElementException();
     156             :         }
     157           0 :         catch( const RuntimeException& ) { throw; }
     158           0 :         catch( const NoSuchElementException& ) { throw; }
     159           0 :         catch( const Exception& )
     160             :         {
     161             :             DBG_UNHANDLED_EXCEPTION();
     162           0 :             throw NoSuchElementException();
     163             :         }
     164             : 
     165           0 :         return xTable;
     166             :     }
     167             : 
     168             :     //--------------------------------------------------------------------
     169           0 :     void SAL_CALL TableName::setTable( const Reference< XPropertySet >& _table ) throw (IllegalArgumentException, RuntimeException)
     170             :     {
     171           0 :         EntryGuard aGuard( *this );
     172             : 
     173           0 :         Reference< XPropertySetInfo > xPSI( _table, UNO_QUERY );
     174           0 :         if  (   !xPSI.is()
     175           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_CATALOGNAME )
     176           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_SCHEMANAME )
     177           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_NAME )
     178             :             )
     179             :             throw IllegalArgumentException(
     180             :                 String( SdbtRes( STR_NO_TABLE_OBJECT ) ),
     181             :                 *this,
     182             :                 0
     183           0 :             );
     184             : 
     185             :         try
     186             :         {
     187           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_CATALOGNAME ) >>= m_pImpl->sCatalog );
     188           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_SCHEMANAME ) >>= m_pImpl->sSchema );
     189           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_NAME ) >>= m_pImpl->sName );
     190             :         }
     191           0 :         catch( const RuntimeException& ) { throw; }
     192           0 :         catch( const Exception& e )
     193             :         {
     194           0 :             throw IllegalArgumentException( e.Message, e.Context, 0 );
     195           0 :         }
     196           0 :     }
     197             : 
     198             :     //--------------------------------------------------------------------
     199             :     namespace
     200             :     {
     201             :         /** translates a CompositionType into a EComposeRule
     202             :             @throws IllegalArgumentException
     203             :                 if the given value does not denote a valid CompositionType
     204             :         */
     205           0 :         EComposeRule lcl_translateCompositionType_throw( sal_Int32 _nType )
     206             :         {
     207             :             struct
     208             :             {
     209             :                 sal_Int32       nCompositionType;
     210             :                 EComposeRule    eComposeRule;
     211             :             }   TypeTable[] =
     212             :             {
     213             :                 { CompositionType::ForTableDefinitions,      eInTableDefinitions },
     214             :                 { CompositionType::ForIndexDefinitions,      eInIndexDefinitions },
     215             :                 { CompositionType::ForDataManipulation,      eInDataManipulation },
     216             :                 { CompositionType::ForProcedureCalls,        eInProcedureCalls },
     217             :                 { CompositionType::ForPrivilegeDefinitions,  eInPrivilegeDefinitions },
     218             :                 { CompositionType::ForPrivilegeDefinitions,  eComplete }
     219           0 :             };
     220             : 
     221           0 :             bool found = false;
     222           0 :             size_t i = 0;
     223           0 :             for ( ; ( i < sizeof( TypeTable ) / sizeof( TypeTable[0] ) ) && !found; ++i )
     224           0 :                 if ( TypeTable[i].nCompositionType == _nType )
     225           0 :                     found = true;
     226           0 :             if ( !found )
     227             :                 throw IllegalArgumentException(
     228             :                     String( SdbtRes( STR_INVALID_COMPOSITION_TYPE ) ),
     229             :                     NULL,
     230             :                     0
     231           0 :                 );
     232             : 
     233           0 :             return TypeTable[i].eComposeRule;
     234             :         }
     235             :     }
     236             : 
     237             :     //--------------------------------------------------------------------
     238           0 :     ::rtl::OUString SAL_CALL TableName::getComposedName( ::sal_Int32 _Type, ::sal_Bool _Quote ) throw (IllegalArgumentException, RuntimeException)
     239             :     {
     240           0 :         EntryGuard aGuard( *this );
     241             : 
     242             :         return composeTableName(
     243           0 :             getConnection()->getMetaData(),
     244           0 :             m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName, _Quote,
     245           0 :             lcl_translateCompositionType_throw( _Type ) );
     246             :     }
     247             : 
     248             :     //--------------------------------------------------------------------
     249           0 :     void SAL_CALL TableName::setComposedName( const ::rtl::OUString& _ComposedName, ::sal_Int32 _Type ) throw (RuntimeException)
     250             :     {
     251           0 :         EntryGuard aGuard( *this );
     252             : 
     253             :         qualifiedNameComponents(
     254           0 :             getConnection()->getMetaData(),
     255             :             _ComposedName,
     256           0 :             m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName,
     257           0 :             lcl_translateCompositionType_throw( _Type ) );
     258           0 :     }
     259             : 
     260             : //........................................................................
     261             : } // namespace sdbtools
     262             : //........................................................................
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10