LCOV - code coverage report
Current view: top level - dbaccess/source/sdbtools/connection - tablename.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 83 0.0 %
Date: 2014-04-14 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 :         if ( !_rxConnection.is() )
      71           0 :             throw NullPointerException();
      72             : 
      73           0 :         setWeakConnection( _rxConnection );
      74           0 :     }
      75             : 
      76           0 :     TableName::~TableName()
      77             :     {
      78           0 :     }
      79             : 
      80           0 :     OUString SAL_CALL TableName::getCatalogName() throw (RuntimeException, std::exception)
      81             :     {
      82           0 :         EntryGuard aGuard( *this );
      83           0 :         return m_pImpl->sCatalog;
      84             :     }
      85             : 
      86           0 :     void SAL_CALL TableName::setCatalogName( const OUString& _catalogName ) throw (RuntimeException, std::exception)
      87             :     {
      88           0 :         EntryGuard aGuard( *this );
      89           0 :         m_pImpl->sCatalog = _catalogName;
      90           0 :     }
      91             : 
      92           0 :     OUString SAL_CALL TableName::getSchemaName() throw (RuntimeException, std::exception)
      93             :     {
      94           0 :         EntryGuard aGuard( *this );
      95           0 :         return m_pImpl->sSchema;
      96             :     }
      97             : 
      98           0 :     void SAL_CALL TableName::setSchemaName( const OUString& _schemaName ) throw (RuntimeException, std::exception)
      99             :     {
     100           0 :         EntryGuard aGuard( *this );
     101           0 :         m_pImpl->sSchema = _schemaName;
     102           0 :     }
     103             : 
     104           0 :     OUString SAL_CALL TableName::getTableName() throw (RuntimeException, std::exception)
     105             :     {
     106           0 :         EntryGuard aGuard( *this );
     107           0 :         return m_pImpl->sName;
     108             :     }
     109             : 
     110           0 :     void SAL_CALL TableName::setTableName( const OUString& _tableName ) throw (RuntimeException, std::exception)
     111             :     {
     112           0 :         EntryGuard aGuard( *this );
     113           0 :         m_pImpl->sName = _tableName;
     114           0 :     }
     115             : 
     116           0 :     OUString SAL_CALL TableName::getNameForSelect() throw (RuntimeException, std::exception)
     117             :     {
     118           0 :         EntryGuard aGuard( *this );
     119           0 :         return composeTableNameForSelect( getConnection(), m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName );
     120             :     }
     121             : 
     122           0 :     Reference< XPropertySet > SAL_CALL TableName::getTable() throw (NoSuchElementException, RuntimeException, std::exception)
     123             :     {
     124           0 :         EntryGuard aGuard( *this );
     125             : 
     126           0 :         Reference< XTablesSupplier > xSuppTables( getConnection(), UNO_QUERY_THROW );
     127           0 :         Reference< XNameAccess > xTables( xSuppTables->getTables(), UNO_QUERY_THROW );
     128             : 
     129           0 :         Reference< XPropertySet > xTable;
     130             :         try
     131             :         {
     132           0 :             xTable.set( xTables->getByName( getComposedName( CompositionType::Complete, sal_False ) ), UNO_QUERY_THROW );
     133             :         }
     134           0 :         catch( const WrappedTargetException& )
     135             :         {
     136           0 :             throw NoSuchElementException();
     137             :         }
     138           0 :         catch( const RuntimeException& ) { throw; }
     139           0 :         catch( const NoSuchElementException& ) { throw; }
     140           0 :         catch( const Exception& )
     141             :         {
     142             :             DBG_UNHANDLED_EXCEPTION();
     143           0 :             throw NoSuchElementException();
     144             :         }
     145             : 
     146           0 :         return xTable;
     147             :     }
     148             : 
     149           0 :     void SAL_CALL TableName::setTable( const Reference< XPropertySet >& _table ) throw (IllegalArgumentException, RuntimeException, std::exception)
     150             :     {
     151           0 :         EntryGuard aGuard( *this );
     152             : 
     153           0 :         Reference< XPropertySetInfo > xPSI( _table, UNO_QUERY );
     154           0 :         if  (   !xPSI.is()
     155           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_CATALOGNAME )
     156           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_SCHEMANAME )
     157           0 :             ||  !xPSI->hasPropertyByName( PROPERTY_NAME )
     158             :             )
     159             :             throw IllegalArgumentException(
     160             :                 OUString( SdbtRes( STR_NO_TABLE_OBJECT ) ),
     161             :                 *this,
     162             :                 0
     163           0 :             );
     164             : 
     165             :         try
     166             :         {
     167           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_CATALOGNAME ) >>= m_pImpl->sCatalog );
     168           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_SCHEMANAME ) >>= m_pImpl->sSchema );
     169           0 :             OSL_VERIFY( _table->getPropertyValue( PROPERTY_NAME ) >>= m_pImpl->sName );
     170             :         }
     171           0 :         catch( const RuntimeException& ) { throw; }
     172           0 :         catch( const Exception& e )
     173             :         {
     174           0 :             throw IllegalArgumentException( e.Message, e.Context, 0 );
     175           0 :         }
     176           0 :     }
     177             : 
     178             :     namespace
     179             :     {
     180             :         /** translates a CompositionType into a EComposeRule
     181             :             @throws IllegalArgumentException
     182             :                 if the given value does not denote a valid CompositionType
     183             :         */
     184           0 :         EComposeRule lcl_translateCompositionType_throw( sal_Int32 _nType )
     185             :         {
     186             :             struct
     187             :             {
     188             :                 sal_Int32       nCompositionType;
     189             :                 EComposeRule    eComposeRule;
     190             :             }   TypeTable[] =
     191             :             {
     192             :                 { CompositionType::ForTableDefinitions,      eInTableDefinitions },
     193             :                 { CompositionType::ForIndexDefinitions,      eInIndexDefinitions },
     194             :                 { CompositionType::ForDataManipulation,      eInDataManipulation },
     195             :                 { CompositionType::ForProcedureCalls,        eInProcedureCalls },
     196             :                 { CompositionType::ForPrivilegeDefinitions,  eInPrivilegeDefinitions },
     197             :                 { CompositionType::ForPrivilegeDefinitions,  eComplete }
     198           0 :             };
     199             : 
     200           0 :             bool found = false;
     201           0 :             size_t i = 0;
     202           0 :             for ( ; ( i < sizeof( TypeTable ) / sizeof( TypeTable[0] ) ) && !found; ++i )
     203           0 :                 if ( TypeTable[i].nCompositionType == _nType )
     204           0 :                     found = true;
     205           0 :             if ( !found )
     206             :                 throw IllegalArgumentException(
     207             :                     OUString( SdbtRes( STR_INVALID_COMPOSITION_TYPE ) ),
     208             :                     NULL,
     209             :                     0
     210           0 :                 );
     211             : 
     212           0 :             return TypeTable[i].eComposeRule;
     213             :         }
     214             :     }
     215             : 
     216           0 :     OUString SAL_CALL TableName::getComposedName( ::sal_Int32 _Type, sal_Bool _Quote ) throw (IllegalArgumentException, RuntimeException, std::exception)
     217             :     {
     218           0 :         EntryGuard aGuard( *this );
     219             : 
     220             :         return composeTableName(
     221           0 :             getConnection()->getMetaData(),
     222           0 :             m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName, _Quote,
     223           0 :             lcl_translateCompositionType_throw( _Type ) );
     224             :     }
     225             : 
     226           0 :     void SAL_CALL TableName::setComposedName( const OUString& _ComposedName, ::sal_Int32 _Type ) throw (RuntimeException, std::exception)
     227             :     {
     228           0 :         EntryGuard aGuard( *this );
     229             : 
     230             :         qualifiedNameComponents(
     231           0 :             getConnection()->getMetaData(),
     232             :             _ComposedName,
     233           0 :             m_pImpl->sCatalog, m_pImpl->sSchema, m_pImpl->sName,
     234           0 :             lcl_translateCompositionType_throw( _Type ) );
     235           0 :     }
     236             : 
     237             : } // namespace sdbtools
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10