LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - resultcolumn.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 60 137 43.8 %
Date: 2014-04-11 Functions: 8 14 57.1 %
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 "resultcolumn.hxx"
      21             : #include <com/sun/star/lang/DisposedException.hpp>
      22             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      23             : #include <com/sun/star/sdbc/DataType.hpp>
      24             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      25             : #include <cppuhelper/typeprovider.hxx>
      26             : #include <tools/debug.hxx>
      27             : #include <tools/diagnose_ex.h>
      28             : #include "dbastrings.hrc"
      29             : #include "apitools.hxx"
      30             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      31             : #include <cppuhelper/exc_hlp.hxx>
      32             : #include <osl/thread.h>
      33             : 
      34             : using namespace ::com::sun::star::sdbc;
      35             : using namespace ::com::sun::star::beans;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::lang;
      38             : using namespace ::com::sun::star::container;
      39             : using namespace ::osl;
      40             : using namespace ::comphelper;
      41             : using namespace ::cppu;
      42             : using namespace dbaccess;
      43             : 
      44             : 
      45         260 : OResultColumn::OResultColumn( const Reference < XResultSetMetaData >& _xMetaData, sal_Int32 _nPos,
      46             :         const Reference< XDatabaseMetaData >& _rxDBMeta )
      47             :     :OColumn( true )
      48             :     ,m_xMetaData( _xMetaData )
      49             :     ,m_xDBMetaData( _rxDBMeta )
      50         260 :     ,m_nPos( _nPos )
      51             : {
      52         260 : }
      53             : 
      54          31 : void OResultColumn::impl_determineIsRowVersion_nothrow()
      55             : {
      56          31 :     if ( m_aIsRowVersion.hasValue() )
      57           0 :         return;
      58          31 :     m_aIsRowVersion <<= (sal_Bool)(sal_False);
      59             : 
      60             :     OSL_ENSURE( m_xDBMetaData.is(), "OResultColumn::impl_determineIsRowVersion_nothrow: no DBMetaData!" );
      61          31 :     if ( !m_xDBMetaData.is() )
      62           0 :         return;
      63             : 
      64             :     try
      65             :     {
      66          62 :         OUString sCatalog, sSchema, sTable, sColumnName;
      67          31 :         getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog;
      68          31 :         getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema;
      69          31 :         getPropertyValue( PROPERTY_TABLENAME ) >>= sTable;
      70          31 :         getPropertyValue( PROPERTY_NAME ) >>= sColumnName;
      71             : 
      72             :         try
      73             :         {
      74          31 :             Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns(
      75          31 :                 makeAny( sCatalog ), sSchema, sTable );
      76          31 :             if ( xVersionColumns.is() ) // allowed to be NULL
      77             :             {
      78          31 :                 Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW );
      79          62 :                 while ( xVersionColumns->next() )
      80             :                 {
      81           0 :                     if ( xResultRow->getString( 2 ) == sColumnName )
      82             :                     {
      83           0 :                         m_aIsRowVersion <<= (sal_Bool)(sal_True);
      84           0 :                         break;
      85             :                     }
      86          31 :                 }
      87          31 :             }
      88             :         }
      89           0 :         catch(const SQLException&)
      90             :         {
      91          31 :         }
      92             :     }
      93           0 :     catch( const Exception& )
      94             :     {
      95             :         DBG_UNHANDLED_EXCEPTION();
      96             :     }
      97             : }
      98             : 
      99         260 : OResultColumn::~OResultColumn()
     100             : {
     101         260 : }
     102             : 
     103             : // com::sun::star::lang::XTypeProvider
     104           0 : Sequence< sal_Int8 > OResultColumn::getImplementationId() throw (RuntimeException, std::exception)
     105             : {
     106           0 :     return css::uno::Sequence<sal_Int8>();
     107             : }
     108             : 
     109             : // XServiceInfo
     110           0 : OUString OResultColumn::getImplementationName(  ) throw(RuntimeException, std::exception)
     111             : {
     112           0 :     return OUString("com.sun.star.sdb.OResultColumn");
     113             : }
     114             : 
     115           0 : Sequence< OUString > OResultColumn::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     116             : {
     117           0 :     Sequence< OUString > aSNS( 2 );
     118           0 :     aSNS[0] = SERVICE_SDBCX_COLUMN;
     119           0 :     aSNS[1] = SERVICE_SDB_RESULTCOLUMN;
     120           0 :     return aSNS;
     121             : }
     122             : 
     123             : // OComponentHelper
     124         260 : void OResultColumn::disposing()
     125             : {
     126         260 :     OColumn::disposing();
     127             : 
     128         260 :     MutexGuard aGuard(m_aMutex);
     129         260 :     m_xMetaData = NULL;
     130         260 : }
     131             : 
     132             : // comphelper::OPropertyArrayUsageHelper
     133           0 : ::cppu::IPropertyArrayHelper* OResultColumn::createArrayHelper( ) const
     134             : {
     135           0 :     BEGIN_PROPERTY_HELPER(21)
     136           0 :         DECL_PROP1(CATALOGNAME,             OUString,    READONLY);
     137           0 :         DECL_PROP1(DISPLAYSIZE,             sal_Int32,          READONLY);
     138           0 :         DECL_PROP1_BOOL(ISAUTOINCREMENT,                        READONLY);
     139           0 :         DECL_PROP1_BOOL(ISCASESENSITIVE,                        READONLY);
     140           0 :         DECL_PROP1_BOOL(ISCURRENCY,                             READONLY);
     141           0 :         DECL_PROP1_BOOL(ISDEFINITELYWRITABLE,                   READONLY);
     142           0 :         DECL_PROP1(ISNULLABLE,              sal_Int32,          READONLY);
     143           0 :         DECL_PROP1_BOOL(ISREADONLY,                             READONLY);
     144           0 :         DECL_PROP1_BOOL(ISROWVERSION,                           READONLY);
     145           0 :         DECL_PROP1_BOOL(ISSEARCHABLE,                           READONLY);
     146           0 :         DECL_PROP1_BOOL(ISSIGNED,                               READONLY);
     147           0 :         DECL_PROP1_BOOL(ISWRITABLE,                             READONLY);
     148           0 :         DECL_PROP1(LABEL,                   OUString,    READONLY);
     149           0 :         DECL_PROP1(NAME,                    OUString,    READONLY);
     150           0 :         DECL_PROP1(PRECISION,               sal_Int32,          READONLY);
     151           0 :         DECL_PROP1(SCALE,                   sal_Int32,          READONLY);
     152           0 :         DECL_PROP1(SCHEMANAME,              OUString,    READONLY);
     153           0 :         DECL_PROP1(SERVICENAME,             OUString,    READONLY);
     154           0 :         DECL_PROP1(TABLENAME,               OUString,    READONLY);
     155           0 :         DECL_PROP1(TYPE,                    sal_Int32,          READONLY);
     156           0 :         DECL_PROP1(TYPENAME,                OUString,    READONLY);
     157           0 :     END_PROPERTY_HELPER();
     158             : }
     159             : 
     160             : // cppu::OPropertySetHelper
     161           0 : ::cppu::IPropertyArrayHelper& OResultColumn::getInfoHelper()
     162             : {
     163           0 :     return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OResultColumn >* >(this)->getArrayHelper();
     164             : }
     165             : 
     166             : namespace
     167             : {
     168             :     template< typename TYPE >
     169         449 :     void obtain( Any& _out_rValue, ::boost::optional< TYPE > _rCache, const sal_Int32 _nPos, const Reference < XResultSetMetaData >& _rxResultMeta, TYPE (SAL_CALL XResultSetMetaData::*Getter)( sal_Int32 ) )
     170             :     {
     171         449 :         if ( !_rCache )
     172         325 :             _rCache.reset( (_rxResultMeta.get()->*Getter)( _nPos ) );
     173         449 :         _out_rValue <<= *_rCache;
     174         449 :     }
     175             : }
     176             : 
     177        2263 : void OResultColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     178             : {
     179             :     try
     180             :     {
     181        2263 :         if ( OColumn::isRegisteredProperty( nHandle ) )
     182             :         {
     183        1690 :             OColumn::getFastPropertyValue( rValue, nHandle );
     184             :         }
     185             :         else
     186             :         {
     187         573 :             switch (nHandle)
     188             :             {
     189             :                 case PROPERTY_ID_ISROWVERSION:
     190          31 :                     const_cast< OResultColumn* >( this )->impl_determineIsRowVersion_nothrow();
     191          31 :                     rValue = m_aIsRowVersion;
     192          31 :                     break;
     193             :                 case PROPERTY_ID_TABLENAME:
     194          31 :                     rValue <<= m_xMetaData->getTableName(m_nPos);
     195          31 :                     break;
     196             :                 case PROPERTY_ID_SCHEMANAME:
     197          31 :                     rValue <<= m_xMetaData->getSchemaName(m_nPos);
     198          31 :                     break;
     199             :                 case PROPERTY_ID_CATALOGNAME:
     200          31 :                     rValue <<= m_xMetaData->getCatalogName(m_nPos);
     201          31 :                     break;
     202             :                 case PROPERTY_ID_ISSIGNED:
     203           0 :                     obtain( rValue, m_isSigned, m_nPos, m_xMetaData, &XResultSetMetaData::isSigned );
     204           0 :                     break;
     205             :                 case PROPERTY_ID_ISCURRENCY:
     206           0 :                     obtain( rValue, m_isCurrency, m_nPos, m_xMetaData, &XResultSetMetaData::isCurrency );
     207           0 :                     break;
     208             :                 case PROPERTY_ID_ISSEARCHABLE:
     209          15 :                     obtain( rValue, m_bSearchable, m_nPos, m_xMetaData, &XResultSetMetaData::isSearchable );
     210          15 :                     break;
     211             :                 case PROPERTY_ID_ISCASESENSITIVE:
     212           0 :                     obtain( rValue, m_isCaseSensitive, m_nPos, m_xMetaData, &XResultSetMetaData::isCaseSensitive );
     213           0 :                     break;
     214             :                 case PROPERTY_ID_ISREADONLY:
     215         124 :                     obtain( rValue, m_isReadOnly, m_nPos, m_xMetaData, &XResultSetMetaData::isReadOnly );
     216         124 :                     break;
     217             :                 case PROPERTY_ID_ISWRITABLE:
     218           0 :                     obtain( rValue, m_isWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isWritable );
     219           0 :                     break;
     220             :                 case PROPERTY_ID_ISDEFINITELYWRITABLE:
     221           0 :                     obtain( rValue, m_isDefinitelyWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isDefinitelyWritable );
     222           0 :                     break;
     223             :                 case PROPERTY_ID_ISAUTOINCREMENT:
     224          31 :                     obtain( rValue, m_isAutoIncrement, m_nPos, m_xMetaData, &XResultSetMetaData::isAutoIncrement );
     225          31 :                     break;
     226             :                 case PROPERTY_ID_SERVICENAME:
     227           0 :                     rValue <<= m_xMetaData->getColumnServiceName(m_nPos);
     228           0 :                     break;
     229             :                 case PROPERTY_ID_LABEL:
     230          73 :                     obtain( rValue, m_sColumnLabel, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnLabel );
     231          73 :                     break;
     232             :                 case PROPERTY_ID_DISPLAYSIZE:
     233           0 :                     obtain( rValue, m_nColumnDisplaySize, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnDisplaySize );
     234           0 :                     break;
     235             :                 case PROPERTY_ID_TYPE:
     236         158 :                     obtain( rValue, m_nColumnType, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnType );
     237         158 :                     break;
     238             :                 case PROPERTY_ID_PRECISION:
     239          17 :                     obtain( rValue, m_nPrecision, m_nPos, m_xMetaData, &XResultSetMetaData::getPrecision );
     240          17 :                     break;
     241             :                 case PROPERTY_ID_SCALE:
     242           0 :                     obtain( rValue, m_nScale, m_nPos, m_xMetaData, &XResultSetMetaData::getScale );
     243           0 :                     break;
     244             :                 case PROPERTY_ID_ISNULLABLE:
     245          31 :                     obtain( rValue, m_isNullable, m_nPos, m_xMetaData, &XResultSetMetaData::isNullable );
     246          31 :                     break;
     247             :                 case PROPERTY_ID_TYPENAME:
     248           0 :                     rValue <<= m_xMetaData->getColumnTypeName(m_nPos);
     249           0 :                     break;
     250             :                 default:
     251             :                     OSL_FAIL( "OResultColumn::getFastPropertyValue: unknown property handle!" );
     252           0 :                     break;
     253             :             }
     254             :         }
     255             :     }
     256           0 :     catch (SQLException& )
     257             :     {
     258             :         // default handling if we caught an exception
     259           0 :         switch (nHandle)
     260             :         {
     261             :             case PROPERTY_ID_LABEL:
     262             :             case PROPERTY_ID_TYPENAME:
     263             :             case PROPERTY_ID_SERVICENAME:
     264             :             case PROPERTY_ID_TABLENAME:
     265             :             case PROPERTY_ID_SCHEMANAME:
     266             :             case PROPERTY_ID_CATALOGNAME:
     267             :                 // empty string'S
     268           0 :                 rValue <<= OUString();
     269           0 :                 break;
     270             :             case PROPERTY_ID_ISROWVERSION:
     271             :             case PROPERTY_ID_ISAUTOINCREMENT:
     272             :             case PROPERTY_ID_ISWRITABLE:
     273             :             case PROPERTY_ID_ISDEFINITELYWRITABLE:
     274             :             case PROPERTY_ID_ISCASESENSITIVE:
     275             :             case PROPERTY_ID_ISSEARCHABLE:
     276             :             case PROPERTY_ID_ISCURRENCY:
     277             :             case PROPERTY_ID_ISSIGNED:
     278             :             {
     279           0 :                 sal_Bool bVal = sal_False;
     280           0 :                 rValue.setValue(&bVal, getBooleanCppuType());
     281           0 :             }   break;
     282             :             case PROPERTY_ID_ISREADONLY:
     283             :             {
     284           0 :                 sal_Bool bVal = sal_True;
     285           0 :                 rValue.setValue(&bVal, getBooleanCppuType());
     286           0 :             }   break;
     287             :             case PROPERTY_ID_SCALE:
     288             :             case PROPERTY_ID_PRECISION:
     289             :             case PROPERTY_ID_DISPLAYSIZE:
     290           0 :                 rValue <<= sal_Int32(0);
     291           0 :                 break;
     292             :             case PROPERTY_ID_TYPE:
     293           0 :                 rValue <<= sal_Int32(DataType::SQLNULL);
     294           0 :                 break;
     295             :             case PROPERTY_ID_ISNULLABLE:
     296           0 :                 rValue <<= ColumnValue::NULLABLE_UNKNOWN;
     297           0 :                 break;
     298             :         }
     299             :     }
     300        2263 : }
     301             : 
     302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10