LCOV - code coverage report
Current view: top level - dbaccess/source/sdbtools/connection - tablename.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 81 0.0 %
Date: 2015-06-13 12:38:46 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             : #include "tablename.hxx"
      21             : #include "sdbt_resource.hrc"
      22             : #include "module_sdbt.hxx"
      23             : #include "sdbtstrings.hrc"
      24             : 
      25             : #include <com/sun/star/lang/NullPointerException.hpp>
      26             : #include <com/sun/star/sdb/tools/CompositionType.hpp>
      27             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      28             : 
      29             : #include <connectivity/dbtools.hxx>
      30             : #include <tools/diagnose_ex.h>
      31             : 
      32             : namespace sdbtools
      33             : {
      34             : 
      35             :     using ::com::sun::star::uno::Reference;
      36             :     using ::com::sun::star::sdbc::XConnection;
      37             :     using ::com::sun::star::lang::NullPointerException;
      38             :     using ::com::sun::star::uno::RuntimeException;
      39             :     using ::com::sun::star::lang::IllegalArgumentException;
      40             :     using ::com::sun::star::beans::XPropertySet;
      41             :     using ::com::sun::star::container::NoSuchElementException;
      42             :     using ::com::sun::star::sdbcx::XTablesSupplier;
      43             :     using ::com::sun::star::container::XNameAccess;
      44             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      45             :     using ::com::sun::star::lang::WrappedTargetException;
      46             :     using ::com::sun::star::uno::Exception;
      47             :     using ::com::sun::star::uno::UNO_QUERY;
      48             :     using ::com::sun::star::beans::XPropertySetInfo;
      49             :     using ::com::sun::star::uno::XComponentContext;
      50             : 
      51             :     namespace CompositionType = ::com::sun::star::sdb::tools::CompositionType;
      52             : 
      53             :     using namespace ::dbtools;
      54             : 
      55             :     // TableName
      56           0 :     struct TableName_Impl
      57             :     {
      58             :         SdbtClient      m_aModuleClient;    // keep the module alive as long as this instance lives
      59             : 
      60             :         OUString sCatalog;
      61             :         OUString sSchema;
      62             :         OUString sName;
      63             :     };
      64             : 
      65             :     // TableName
      66           0 :     TableName::TableName( const Reference<XComponentContext>& _rContext, const Reference< XConnection >& _rxConnection )
      67             :         :ConnectionDependentComponent( _rContext )
      68           0 :         ,m_pImpl( new TableName_Impl )
      69             :     {
      70           0 :         setWeakConnection( _rxConnection );
      71           0 :     }
      72             : 
      73           0 :     TableName::~TableName()
      74             :     {
      75           0 :     }
      76             : 
      77           0 :     OUString SAL_CALL TableName::getCatalogName() throw (RuntimeException, std::exception)
      78             :     {
      79           0 :         EntryGuard aGuard( *this );
      80           0 :         return m_pImpl->sCatalog;
      81             :     }
      82             : 
      83           0 :     void SAL_CALL TableName::setCatalogName( const OUString& _catalogName ) throw (RuntimeException, std::exception)
      84             :     {
      85           0 :         EntryGuard aGuard( *this );
      86           0 :         m_pImpl->sCatalog = _catalogName;
      87           0 :     }
      88             : 
      89           0 :     OUString SAL_CALL TableName::getSchemaName() throw (RuntimeException, std::exception)
      90             :     {
      91           0 :         EntryGuard aGuard( *this );
      92           0 :         return m_pImpl->sSchema;
      93             :     }
      94             : 
      95           0 :     void SAL_CALL TableName::setSchemaName( const OUString& _schemaName ) throw (RuntimeException, std::exception)
      96             :     {
      97           0 :         EntryGuard aGuard( *this );
      98           0 :         m_pImpl->sSchema = _schemaName;
      99           0 :     }
     100             : 
     101           0 :     OUString SAL_CALL TableName::getTableName() throw (RuntimeException, std::exception)
     102             :     {
     103           0 :         EntryGuard aGuard( *this );
     104           0 :         return m_pImpl->sName;
     105             :     }
     106             : 
     107           0 :     void SAL_CALL TableName::setTableName( const OUString& _tableName ) throw (RuntimeException, std::exception)
     108             :     {
     109           0 :         EntryGuard aGuard( *this );
     110           0 :         m_pImpl->sName = _tableName;
     111           0 :     }
     112             : 
     113           0 :     OUString SAL_CALL TableName::getNameForSelect() throw (RuntimeException, std::exception)
     114             :     {
     115           0 :         EntryGuard aGuard( *this );
     116           0 :         return composeTableNameForSelect( getConnection(), m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName );
     117             :     }
     118             : 
     119           0 :     Reference< XPropertySet > SAL_CALL TableName::getTable() throw (NoSuchElementException, RuntimeException, std::exception)
     120             :     {
     121           0 :         EntryGuard aGuard( *this );
     122             : 
     123           0 :         Reference< XTablesSupplier > xSuppTables( getConnection(), UNO_QUERY_THROW );
     124           0 :         Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW );
     125             : 
     126           0 :         Reference< XPropertySet > xTable;
     127             :         try
     128             :         {
     129           0 :             xTable.set( xTables->getByName( getComposedName( CompositionType::Complete, sal_False ) ), UNO_QUERY_THROW );
     130             :         }
     131           0 :         catch( const WrappedTargetException& )
     132             :         {
     133           0 :             throw NoSuchElementException();
     134             :         }
     135           0 :         catch( const RuntimeException& ) { throw; }
     136           0 :         catch( const NoSuchElementException& ) { throw; }
     137           0 :         catch( const Exception& )
     138             :         {
     139             :             DBG_UNHANDLED_EXCEPTION();
     140           0 :             throw NoSuchElementException();
     141             :         }
     142             : 
     143           0 :         return xTable;
     144             :     }
     145             : 
     146           0 :     void SAL_CALL TableName::setTable( const Reference< XPropertySet >& _table ) throw (IllegalArgumentException, RuntimeException, std::exception)
     147             :     {
     148           0 :         EntryGuard aGuard( *this );
     149             : 
     150           0 :         Reference< XPropertySetInfo > xPSI( _table, UNO_QUERY );
     151           0 :         if  (   !xPSI.is()
     152           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_CATALOGNAME )
     153           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_SCHEMANAME )
     154           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_NAME )
     155             :             )
     156             :             throw IllegalArgumentException(
     157             :                 OUString( SdbtRes( STR_NO_TABLE_OBJECT ) ),
     158             :                 *this,
     159             :                 0
     160           0 :             );
     161             : 
     162             :         try
     163             :         {
     164           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_CATALOGNAME ) >>= m_pImpl->sCatalog );
     165           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_SCHEMANAME ) >>= m_pImpl->sSchema );
     166           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_NAME ) >>= m_pImpl->sName );
     167             :         }
     168           0 :         catch( const RuntimeException& ) { throw; }
     169           0 :         catch( const Exception& e )
     170             :         {
     171           0 :             throw IllegalArgumentException( e.Message, e.Context, 0 );
     172           0 :         }
     173           0 :     }
     174             : 
     175             :     namespace
     176             :     {
     177             :         /** translates a CompositionType into a EComposeRule
     178             :             @throws IllegalArgumentException
     179             :                 if the given value does not denote a valid CompositionType
     180             :         */
     181           0 :         EComposeRule lcl_translateCompositionType_throw( sal_Int32 _nType )
     182             :         {
     183             :             struct
     184             :             {
     185             :                 sal_Int32       nCompositionType;
     186             :                 EComposeRule    eComposeRule;
     187             :             }   TypeTable[] =
     188             :             {
     189             :                 { CompositionType::ForTableDefinitions,      eInTableDefinitions },
     190             :                 { CompositionType::ForIndexDefinitions,      eInIndexDefinitions },
     191             :                 { CompositionType::ForDataManipulation,      eInDataManipulation },
     192             :                 { CompositionType::ForProcedureCalls,        eInProcedureCalls },
     193             :                 { CompositionType::ForPrivilegeDefinitions,  eInPrivilegeDefinitions },
     194             :                 { CompositionType::ForPrivilegeDefinitions,  eComplete }
     195           0 :             };
     196             : 
     197           0 :             bool found = false;
     198           0 :             size_t i = 0;
     199           0 :             for ( ; ( i < sizeof( TypeTable ) / sizeof( TypeTable[0] ) ) && !found; ++i )
     200           0 :                 if ( TypeTable[i].nCompositionType == _nType )
     201           0 :                     found = true;
     202           0 :             if ( !found )
     203             :                 throw IllegalArgumentException(
     204             :                     OUString( SdbtRes( STR_INVALID_COMPOSITION_TYPE ) ),
     205             :                     NULL,
     206             :                     0
     207           0 :                 );
     208             : 
     209           0 :             return TypeTable[i].eComposeRule;
     210             :         }
     211             :     }
     212             : 
     213           0 :     OUString SAL_CALL TableName::getComposedName( ::sal_Int32 _Type, sal_Bool _Quote ) throw (IllegalArgumentException, RuntimeException, std::exception)
     214             :     {
     215           0 :         EntryGuard aGuard( *this );
     216             : 
     217             :         return composeTableName(
     218           0 :             getConnection()->getMetaData(),
     219           0 :             m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName, _Quote,
     220           0 :             lcl_translateCompositionType_throw( _Type ) );
     221             :     }
     222             : 
     223           0 :     void SAL_CALL TableName::setComposedName( const OUString& _ComposedName, ::sal_Int32 _Type ) throw (RuntimeException, std::exception)
     224             :     {
     225           0 :         EntryGuard aGuard( *this );
     226             : 
     227             :         qualifiedNameComponents(
     228           0 :             getConnection()->getMetaData(),
     229             :             _ComposedName,
     230           0 :             m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName,
     231           0 :             lcl_translateCompositionType_throw( _Type ) );
     232           0 :     }
     233             : 
     234             : } // namespace sdbtools
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11