LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - tablecontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 55 219 25.1 %
Date: 2012-08-25 Functions: 8 21 38.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 67 592 11.3 %

           Branch data     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 "tablecontainer.hxx"
      22                 :            : #include "dbastrings.hrc"
      23                 :            : #include "table.hxx"
      24                 :            : #include <comphelper/property.hxx>
      25                 :            : #include <comphelper/processfactory.hxx>
      26                 :            : #include <tools/debug.hxx>
      27                 :            : #include <comphelper/enumhelper.hxx>
      28                 :            : #include "core_resource.hxx"
      29                 :            : #include "core_resource.hrc"
      30                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      31                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      32                 :            : #include <com/sun/star/beans/PropertyState.hpp>
      33                 :            : #include <com/sun/star/beans/XPropertyState.hpp>
      34                 :            : #include <com/sun/star/sdbc/XConnection.hpp>
      35                 :            : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      36                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      37                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      38                 :            : #include <com/sun/star/sdbc/KeyRule.hpp>
      39                 :            : #include <com/sun/star/sdbcx/KeyType.hpp>
      40                 :            : #include <com/sun/star/sdbc/ColumnValue.hpp>
      41                 :            : #include <com/sun/star/sdbc/XRow.hpp>
      42                 :            : #include <comphelper/types.hxx>
      43                 :            : #include <connectivity/dbtools.hxx>
      44                 :            : #include <comphelper/extract.hxx>
      45                 :            : #include <connectivity/dbexception.hxx>
      46                 :            : #include "TableDeco.hxx"
      47                 :            : #include "sdbcoretools.hxx"
      48                 :            : #include "ContainerMediator.hxx"
      49                 :            : #include "definitioncolumn.hxx"
      50                 :            : #include "objectnameapproval.hxx"
      51                 :            : #include <tools/string.hxx>
      52                 :            : #include <rtl/logfile.hxx>
      53                 :            : #include <tools/diagnose_ex.h>
      54                 :            : 
      55                 :            : using namespace dbaccess;
      56                 :            : using namespace dbtools;
      57                 :            : using namespace ::com::sun::star::uno;
      58                 :            : using namespace ::com::sun::star::lang;
      59                 :            : using namespace ::com::sun::star::beans;
      60                 :            : using namespace ::com::sun::star::sdbc;
      61                 :            : using namespace ::com::sun::star::sdb;
      62                 :            : using namespace ::com::sun::star::sdbcx;
      63                 :            : using namespace ::com::sun::star::container;
      64                 :            : using namespace ::com::sun::star::util;
      65                 :            : using namespace ::osl;
      66                 :            : using namespace ::comphelper;
      67                 :            : using namespace ::cppu;
      68                 :            : using namespace ::connectivity::sdbcx;
      69                 :            : 
      70                 :            : namespace
      71                 :            : {
      72                 :          0 :     sal_Bool lcl_isPropertySetDefaulted(const Sequence< ::rtl::OUString>& _aNames,const Reference<XPropertySet>& _xProp)
      73                 :            :     {
      74         [ #  # ]:          0 :         Reference<XPropertyState> xState(_xProp,UNO_QUERY);
      75         [ #  # ]:          0 :         if ( xState.is() )
      76                 :            :         {
      77                 :          0 :             const ::rtl::OUString* pIter = _aNames.getConstArray();
      78                 :          0 :             const ::rtl::OUString* pEnd   = pIter + _aNames.getLength();
      79         [ #  # ]:          0 :             for(;pIter != pEnd;++pIter)
      80                 :            :             {
      81                 :            :                 try
      82                 :            :                 {
      83 [ #  # ][ #  # ]:          0 :                     PropertyState aState = xState->getPropertyState(*pIter);
      84         [ #  # ]:          0 :                     if ( aState != PropertyState_DEFAULT_VALUE )
      85                 :          0 :                         break;
      86                 :            :                 }
      87         [ #  # ]:          0 :                 catch(const Exception&)
      88                 :            :                 {
      89                 :            :                     OSL_FAIL( "lcl_isPropertySetDefaulted: Exception caught!" );
      90                 :            :                 }
      91                 :            :             }
      92                 :          0 :             return ( pIter == pEnd );
      93                 :            :         }
      94         [ #  # ]:          0 :         return sal_False;
      95                 :            :     }
      96                 :            : }
      97                 :            : //==========================================================================
      98                 :            : //= OTableContainer
      99                 :            : //==========================================================================
     100                 :            : DBG_NAME(OTableContainer)
     101                 :            : 
     102                 :         56 : OTableContainer::OTableContainer(::cppu::OWeakObject& _rParent,
     103                 :            :                                  ::osl::Mutex& _rMutex,
     104                 :            :                                  const Reference< XConnection >& _xCon,
     105                 :            :                                  sal_Bool _bCase,
     106                 :            :                                  const Reference< XNameContainer >& _xTableDefinitions,
     107                 :            :                                  IRefreshListener*  _pRefreshListener,
     108                 :            :                                  ::dbtools::IWarningsContainer* _pWarningsContainer
     109                 :            :                                  ,oslInterlockedCount& _nInAppend)
     110                 :            :     :OFilteredContainer(_rParent,_rMutex,_xCon,_bCase,_pRefreshListener,_pWarningsContainer,_nInAppend)
     111                 :            :     ,m_xTableDefinitions(_xTableDefinitions)
     112                 :            :     ,m_pTableMediator( NULL )
     113                 :         56 :     ,m_bInDrop(sal_False)
     114                 :            : {
     115                 :            :     DBG_CTOR(OTableContainer, NULL);
     116                 :         56 : }
     117                 :            : 
     118                 :         56 : OTableContainer::~OTableContainer()
     119                 :            : {
     120                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::OTableContainer" );
     121                 :            :     DBG_DTOR(OTableContainer, NULL);
     122         [ -  + ]:        112 : }
     123                 :            : 
     124                 :         50 : void OTableContainer::removeMasterContainerListener()
     125                 :            : {
     126                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::removeMasterContainerListener" );
     127                 :            :     try
     128                 :            :     {
     129         [ +  - ]:         50 :         Reference<XContainer> xCont( m_xMasterContainer, UNO_QUERY_THROW );
     130 [ +  - ][ +  - ]:         50 :         xCont->removeContainerListener( this );
         [ +  - ][ #  # ]
     131                 :            :     }
     132                 :          0 :     catch( const Exception& )
     133                 :            :     {
     134                 :            :         DBG_UNHANDLED_EXCEPTION();
     135                 :            :     }
     136                 :         50 : }
     137                 :            : 
     138                 :          0 : ::rtl::OUString OTableContainer::getTableTypeRestriction() const
     139                 :            : {
     140                 :            :     // no restriction at all (other than the ones provided externally)
     141                 :          0 :     return ::rtl::OUString();
     142                 :            : }
     143                 :            : 
     144                 :            : // XServiceInfo
     145 [ #  # ][ #  # ]:          0 : IMPLEMENT_SERVICE_INFO2(OTableContainer, "com.sun.star.sdb.dbaccess.OTableContainer", SERVICE_SDBCX_CONTAINER.ascii, SERVICE_SDBCX_TABLES.ascii)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     146                 :            : 
     147                 :            : namespace
     148                 :            : {
     149                 :         28 : void lcl_createDefintionObject(const ::rtl::OUString& _rName
     150                 :            :                            ,const Reference< XNameContainer >& _xTableDefinitions
     151                 :            :                            ,Reference<XPropertySet>& _xTableDefinition
     152                 :            :                            ,Reference<XNameAccess>& _xColumnDefinitions
     153                 :            :                            ,sal_Bool _bModified)
     154                 :            : {
     155         [ +  - ]:         28 :     if ( _xTableDefinitions.is() )
     156                 :            :     {
     157 [ +  - ][ +  - ]:         28 :         if ( _xTableDefinitions->hasByName(_rName) )
                 [ +  + ]
     158 [ +  - ][ +  - ]:         12 :             _xTableDefinition.set(_xTableDefinitions->getByName(_rName),UNO_QUERY);
                 [ +  - ]
     159                 :            :         else
     160                 :            :         {
     161         [ +  - ]:         16 :             Sequence< Any > aArguments(1);
     162                 :         16 :             PropertyValue aValue;
     163                 :            :             // set as folder
     164         [ +  - ]:         16 :             aValue.Name = PROPERTY_NAME;
     165         [ +  - ]:         16 :             aValue.Value <<= _rName;
     166 [ +  - ][ +  - ]:         16 :             aArguments[0] <<= aValue;
     167 [ +  - ][ +  - ]:         16 :             _xTableDefinition.set(::comphelper::getProcessServiceFactory()->createInstanceWithArguments(SERVICE_SDB_TABLEDEFINITION,aArguments),UNO_QUERY);
         [ +  - ][ +  - ]
                 [ +  - ]
     168 [ +  - ][ +  - ]:         16 :             _xTableDefinitions->insertByName(_rName,makeAny(_xTableDefinition));
                 [ +  - ]
     169 [ +  - ][ +  - ]:         16 :             ::dbaccess::notifyDataSourceModified(_xTableDefinitions,_bModified);
     170                 :            :         }
     171         [ +  - ]:         28 :         Reference<XColumnsSupplier> xColumnsSupplier(_xTableDefinition,UNO_QUERY);
     172         [ +  - ]:         28 :         if ( xColumnsSupplier.is() )
     173 [ +  - ][ +  - ]:         28 :             _xColumnDefinitions = xColumnsSupplier->getColumns();
                 [ +  - ]
     174                 :            :     }
     175                 :         28 : }
     176                 :            : 
     177                 :            : }
     178                 :            : 
     179                 :         28 : connectivity::sdbcx::ObjectType OTableContainer::createObject(const ::rtl::OUString& _rName)
     180                 :            : {
     181                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::createObject" );
     182                 :         28 :     Reference<XColumnsSupplier > xSup;
     183 [ +  - ][ +  - ]:         28 :     if(m_xMasterContainer.is() && m_xMasterContainer->hasByName(_rName))
         [ +  - ][ +  - ]
                 [ +  - ]
     184 [ +  - ][ +  - ]:         28 :         xSup.set(m_xMasterContainer->getByName(_rName),UNO_QUERY);
                 [ +  - ]
     185                 :            : 
     186                 :         28 :     connectivity::sdbcx::ObjectType xRet;
     187         [ +  - ]:         28 :     if ( m_xMetaData.is() )
     188                 :            :     {
     189                 :         28 :         Reference<XPropertySet> xTableDefinition;
     190                 :         28 :         Reference<XNameAccess> xColumnDefinitions;
     191         [ +  - ]:         28 :         lcl_createDefintionObject(_rName,m_xTableDefinitions,xTableDefinition,xColumnDefinitions,sal_False);
     192                 :            : 
     193         [ +  - ]:         28 :         if ( xSup.is() )
     194                 :            :         {
     195 [ +  - ][ +  - ]:         28 :             ODBTableDecorator* pTable = new ODBTableDecorator( m_xConnection, xSup, ::dbtools::getNumberFormats( m_xConnection ) ,xColumnDefinitions);
         [ +  - ][ +  - ]
     196 [ +  - ][ +  - ]:         28 :             xRet = pTable;
     197         [ +  - ]:         28 :             pTable->construct();
     198                 :            :         }
     199                 :            :         else
     200                 :            :         {
     201                 :          0 :             ::rtl::OUString sCatalog,sSchema,sTable;
     202                 :            :             ::dbtools::qualifiedNameComponents(m_xMetaData,
     203                 :            :                                                 _rName,
     204                 :            :                                                 sCatalog,
     205                 :            :                                                 sSchema,
     206                 :            :                                                 sTable,
     207         [ #  # ]:          0 :                                                 ::dbtools::eInDataManipulation);
     208                 :          0 :             Any aCatalog;
     209         [ #  # ]:          0 :             if(!sCatalog.isEmpty())
     210         [ #  # ]:          0 :                 aCatalog <<= sCatalog;
     211                 :          0 :             ::rtl::OUString sType,sDescription;
     212         [ #  # ]:          0 :             Sequence< ::rtl::OUString> aTypeFilter;
     213         [ #  # ]:          0 :             getAllTableTypeFilter( aTypeFilter );
     214                 :            : 
     215 [ #  # ][ #  # ]:          0 :             Reference< XResultSet > xRes =  m_xMetaData.is() ? m_xMetaData->getTables(aCatalog,sSchema,sTable,aTypeFilter) : Reference< XResultSet >();
                 [ #  # ]
     216 [ #  # ][ #  # ]:          0 :             if(xRes.is() && xRes->next())
         [ #  # ][ #  # ]
                 [ #  # ]
     217                 :            :             {
     218         [ #  # ]:          0 :                 Reference< XRow > xRow(xRes,UNO_QUERY);
     219         [ #  # ]:          0 :                 if(xRow.is())
     220                 :            :                 {
     221 [ #  # ][ #  # ]:          0 :                     sType           = xRow->getString(4);
     222 [ #  # ][ #  # ]:          0 :                     sDescription    = xRow->getString(5);
     223                 :          0 :                 }
     224                 :            :             }
     225         [ #  # ]:          0 :             ::comphelper::disposeComponent(xRes);
     226                 :            :             ODBTable* pTable = new ODBTable(this
     227                 :            :                                 ,m_xConnection
     228                 :            :                                 ,sCatalog
     229                 :            :                                 ,sSchema
     230                 :            :                                 ,sTable
     231                 :            :                                 ,sType
     232                 :            :                                 ,sDescription
     233 [ #  # ][ #  # ]:          0 :                                 ,xColumnDefinitions);
     234 [ #  # ][ #  # ]:          0 :             xRet = pTable;
     235 [ #  # ][ #  # ]:          0 :             pTable->construct();
     236                 :            :         }
     237         [ +  - ]:         28 :         Reference<XPropertySet> xDest(xRet,UNO_QUERY);
     238         [ +  - ]:         28 :         if ( xTableDefinition.is() )
     239         [ +  - ]:         28 :             ::comphelper::copyProperties(xTableDefinition,xDest);
     240                 :            : 
     241         [ +  - ]:         28 :         if ( !m_pTableMediator.is() )
     242                 :            :             m_pTableMediator = new OContainerMediator(
     243 [ +  - ][ +  - ]:         28 :                     this, m_xTableDefinitions.get(), m_xConnection, OContainerMediator::eTables );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     244         [ +  - ]:         28 :         if ( m_pTableMediator.is() )
     245         [ +  - ]:         28 :             m_pTableMediator->notifyElementCreated(_rName,xDest);
     246                 :            :     }
     247                 :            : 
     248                 :         28 :     return xRet;
     249                 :            : }
     250                 :            : 
     251                 :          0 : Reference< XPropertySet > OTableContainer::createDescriptor()
     252                 :            : {
     253                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::createDescriptor" );
     254                 :          0 :     Reference< XPropertySet > xRet;
     255                 :            : 
     256                 :            :     // first we have to look if the master tables support this
     257                 :            :     // and if so then create a table object as well with the master tables
     258                 :          0 :     Reference<XColumnsSupplier > xMasterColumnsSup;
     259         [ #  # ]:          0 :     Reference<XDataDescriptorFactory> xDataFactory(m_xMasterContainer,UNO_QUERY);
     260 [ #  # ][ #  # ]:          0 :     if ( xDataFactory.is() && m_xMetaData.is() )
                 [ #  # ]
     261                 :            :     {
     262 [ #  # ][ #  # ]:          0 :         xMasterColumnsSup = Reference< XColumnsSupplier >( xDataFactory->createDataDescriptor(), UNO_QUERY );
         [ #  # ][ #  # ]
     263 [ #  # ][ #  # ]:          0 :         ODBTableDecorator* pTable = new ODBTableDecorator( m_xConnection, xMasterColumnsSup, ::dbtools::getNumberFormats( m_xConnection ) ,NULL);
         [ #  # ][ #  # ]
                 [ #  # ]
     264 [ #  # ][ #  # ]:          0 :         xRet = pTable;
     265         [ #  # ]:          0 :         pTable->construct();
     266                 :            :     }
     267                 :            :     else
     268                 :            :     {
     269 [ #  # ][ #  # ]:          0 :         ODBTable* pTable = new ODBTable(this, m_xConnection);
     270 [ #  # ][ #  # ]:          0 :         xRet = pTable;
     271         [ #  # ]:          0 :         pTable->construct();
     272                 :            :     }
     273                 :          0 :     return xRet;
     274                 :            : }
     275                 :            : 
     276                 :            : // XAppend
     277                 :          0 : ObjectType OTableContainer::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
     278                 :            : {
     279                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::appendObject" );
     280                 :            :     // append the new table with a create stmt
     281 [ #  # ][ #  # ]:          0 :     ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME));
         [ #  # ][ #  # ]
     282 [ #  # ][ #  # ]:          0 :     if(m_xMasterContainer.is() && m_xMasterContainer->hasByName(aName))
         [ #  # ][ #  # ]
                 [ #  # ]
     283                 :            :     {
     284 [ #  # ][ #  # ]:          0 :         String sMessage(DBACORE_RESSTRING(RID_STR_TABLE_IS_FILTERED));
     285 [ #  # ][ #  # ]:          0 :         sMessage.SearchAndReplaceAscii("$name$", aName);
                 [ #  # ]
     286 [ #  # ][ #  # ]:          0 :         throw SQLException(sMessage,static_cast<XTypeProvider*>(static_cast<OFilteredContainer*>(this)),SQLSTATE_GENERAL,1000,Any());
         [ #  # ][ #  # ]
     287                 :            :     }
     288                 :            : 
     289 [ #  # ][ #  # ]:          0 :     Reference< XConnection > xConnection( m_xConnection.get(), UNO_QUERY );
     290 [ #  # ][ #  # ]:          0 :     PContainerApprove pApprove( new ObjectNameApproval( xConnection, ObjectNameApproval::TypeTable ) );
                 [ #  # ]
     291         [ #  # ]:          0 :     pApprove->approveElement( aName, descriptor );
     292                 :            : 
     293                 :            :     try
     294                 :            :     {
     295         [ #  # ]:          0 :         EnsureReset aReset(m_nInAppend);
     296         [ #  # ]:          0 :         Reference<XAppend> xAppend(m_xMasterContainer,UNO_QUERY);
     297         [ #  # ]:          0 :         if(xAppend.is())
     298                 :            :         {
     299 [ #  # ][ #  # ]:          0 :             xAppend->appendByDescriptor(descriptor);
     300                 :            :         }
     301                 :            :         else
     302                 :            :         {
     303 [ #  # ][ #  # ]:          0 :             ::rtl::OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor,m_xConnection);
     304                 :            : 
     305         [ #  # ]:          0 :             Reference<XConnection> xCon = m_xConnection;
     306                 :            :             OSL_ENSURE(xCon.is(),"Connection is null!");
     307         [ #  # ]:          0 :             if ( xCon.is() )
     308                 :            :             {
     309 [ #  # ][ #  # ]:          0 :                 Reference< XStatement > xStmt = xCon->createStatement(  );
     310         [ #  # ]:          0 :                 if ( xStmt.is() )
     311 [ #  # ][ #  # ]:          0 :                     xStmt->execute(aSql);
     312         [ #  # ]:          0 :                 ::comphelper::disposeComponent(xStmt);
     313                 :          0 :             }
     314         [ #  # ]:          0 :         }
     315                 :            :     }
     316         [ #  # ]:          0 :     catch(const Exception&)
     317                 :            :     {
     318                 :          0 :         throw;
     319                 :            :     }
     320                 :            : 
     321                 :          0 :     Reference<XPropertySet> xTableDefinition;
     322                 :          0 :     Reference<XNameAccess> xColumnDefinitions;
     323 [ #  # ][ #  # ]:          0 :     lcl_createDefintionObject(getNameForObject(descriptor),m_xTableDefinitions,xTableDefinition,xColumnDefinitions,sal_False);
     324         [ #  # ]:          0 :     Reference<XColumnsSupplier> xSup(descriptor,UNO_QUERY);
     325         [ #  # ]:          0 :     Reference<XDataDescriptorFactory> xFac(xColumnDefinitions,UNO_QUERY);
     326         [ #  # ]:          0 :     Reference<XAppend> xAppend(xColumnDefinitions,UNO_QUERY);
     327                 :          0 :     sal_Bool bModified = sal_False;
     328 [ #  # ][ #  # ]:          0 :     if ( xSup.is() && xColumnDefinitions.is() && xFac.is() && xAppend.is() )
         [ #  # ][ #  # ]
                 [ #  # ]
     329                 :            :     {
     330 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xNames = xSup->getColumns();
     331         [ #  # ]:          0 :         if ( xNames.is() )
     332                 :            :         {
     333 [ #  # ][ #  # ]:          0 :             Reference<XPropertySet> xProp = xFac->createDataDescriptor();
     334 [ #  # ][ #  # ]:          0 :             Sequence< ::rtl::OUString> aSeq = xNames->getElementNames();
     335                 :          0 :             const ::rtl::OUString* pIter = aSeq.getConstArray();
     336                 :          0 :             const ::rtl::OUString* pEnd   = pIter + aSeq.getLength();
     337         [ #  # ]:          0 :             for(;pIter != pEnd;++pIter)
     338                 :            :             {
     339 [ #  # ][ #  # ]:          0 :                 if ( !xColumnDefinitions->hasByName(*pIter) )
                 [ #  # ]
     340                 :            :                 {
     341 [ #  # ][ #  # ]:          0 :                     Reference<XPropertySet> xColumn(xNames->getByName(*pIter),UNO_QUERY);
                 [ #  # ]
     342 [ #  # ][ #  # ]:          0 :                     if ( !OColumnSettings::hasDefaultSettings( xColumn ) )
     343                 :            :                     {
     344         [ #  # ]:          0 :                         ::comphelper::copyProperties( xColumn, xProp );
     345 [ #  # ][ #  # ]:          0 :                         xAppend->appendByDescriptor( xProp );
     346                 :          0 :                         bModified = sal_True;
     347                 :          0 :                     }
     348                 :            :                 }
     349         [ #  # ]:          0 :             }
     350                 :          0 :         }
     351                 :            :     }
     352                 :            :     const static ::rtl::OUString s_pTableProps[] = {    ::rtl::OUString(PROPERTY_FILTER), ::rtl::OUString(PROPERTY_ORDER)
     353                 :            :                                                     , ::rtl::OUString(PROPERTY_APPLYFILTER), ::rtl::OUString(PROPERTY_FONT)
     354                 :            :                                                     , ::rtl::OUString(PROPERTY_ROW_HEIGHT), ::rtl::OUString(PROPERTY_TEXTCOLOR)
     355                 :            :                                                     , ::rtl::OUString(PROPERTY_TEXTLINECOLOR), ::rtl::OUString(PROPERTY_TEXTEMPHASIS)
     356 [ #  # ][ #  # ]:          0 :                                                     , ::rtl::OUString(PROPERTY_TEXTRELIEF) };
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
                 [ #  # ]
     357         [ #  # ]:          0 :     Sequence< ::rtl::OUString> aNames(s_pTableProps,sizeof(s_pTableProps)/sizeof(s_pTableProps[0]));
     358 [ #  # ][ #  # ]:          0 :     if ( bModified || !lcl_isPropertySetDefaulted(aNames,xTableDefinition) )
         [ #  # ][ #  # ]
     359         [ #  # ]:          0 :         ::dbaccess::notifyDataSourceModified(m_xTableDefinitions,sal_True);
     360                 :            : 
     361 [ #  # ][ #  # ]:          0 :     return createObject( _rForName );
                 [ #  # ]
     362                 :            : }
     363                 :            : 
     364                 :            : // XDrop
     365                 :          0 : void OTableContainer::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName)
     366                 :            : {
     367                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::dropObject" );
     368                 :          0 :     m_bInDrop = sal_True;
     369                 :            :     try
     370                 :            :     {
     371         [ #  # ]:          0 :         Reference< XDrop > xDrop(m_xMasterContainer,UNO_QUERY);
     372         [ #  # ]:          0 :         if(xDrop.is())
     373 [ #  # ][ #  # ]:          0 :             xDrop->dropByName(_sElementName);
     374                 :            :         else
     375                 :            :         {
     376                 :          0 :             ::rtl::OUString sCatalog,sSchema,sTable,sComposedName;
     377                 :            : 
     378                 :          0 :             sal_Bool bIsView = sal_False;
     379 [ #  # ][ #  # ]:          0 :             Reference<XPropertySet> xTable(getObject(_nPos),UNO_QUERY);
     380 [ #  # ][ #  # ]:          0 :             if ( xTable.is() && m_xMetaData.is() )
                 [ #  # ]
     381                 :            :             {
     382 [ #  # ][ #  # ]:          0 :                 if( m_xMetaData.is() && m_xMetaData->supportsCatalogsInTableDefinitions() )
         [ #  # ][ #  # ]
                 [ #  # ]
     383 [ #  # ][ #  # ]:          0 :                     xTable->getPropertyValue(PROPERTY_CATALOGNAME)  >>= sCatalog;
                 [ #  # ]
     384 [ #  # ][ #  # ]:          0 :                 if( m_xMetaData.is() && m_xMetaData->supportsSchemasInTableDefinitions() )
         [ #  # ][ #  # ]
                 [ #  # ]
     385 [ #  # ][ #  # ]:          0 :                     xTable->getPropertyValue(PROPERTY_SCHEMANAME)   >>= sSchema;
                 [ #  # ]
     386 [ #  # ][ #  # ]:          0 :                 xTable->getPropertyValue(PROPERTY_NAME)         >>= sTable;
                 [ #  # ]
     387                 :            : 
     388         [ #  # ]:          0 :                 sComposedName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_True, ::dbtools::eInTableDefinitions );
     389                 :            : 
     390                 :          0 :                 ::rtl::OUString sType;
     391 [ #  # ][ #  # ]:          0 :                 xTable->getPropertyValue(PROPERTY_TYPE)         >>= sType;
                 [ #  # ]
     392                 :          0 :                 bIsView = sType.equalsIgnoreAsciiCase(::rtl::OUString("VIEW"));
     393                 :            :             }
     394                 :            : 
     395         [ #  # ]:          0 :             if(sComposedName.isEmpty())
     396 [ #  # ][ #  # ]:          0 :                 ::dbtools::throwFunctionSequenceException(static_cast<XTypeProvider*>(static_cast<OFilteredContainer*>(this)));
     397                 :            : 
     398                 :          0 :             ::rtl::OUString aSql("DROP ");
     399                 :            : 
     400         [ #  # ]:          0 :             if ( bIsView ) // here we have a view
     401                 :          0 :                 aSql += ::rtl::OUString("VIEW ");
     402                 :            :             else
     403                 :          0 :                 aSql += ::rtl::OUString("TABLE ");
     404                 :          0 :             aSql += sComposedName;
     405         [ #  # ]:          0 :             Reference<XConnection> xCon = m_xConnection;
     406                 :            :             OSL_ENSURE(xCon.is(),"Connection is null!");
     407         [ #  # ]:          0 :             if ( xCon.is() )
     408                 :            :             {
     409 [ #  # ][ #  # ]:          0 :                 Reference< XStatement > xStmt = xCon->createStatement(  );
     410         [ #  # ]:          0 :                 if(xStmt.is())
     411 [ #  # ][ #  # ]:          0 :                     xStmt->execute(aSql);
     412         [ #  # ]:          0 :                 ::comphelper::disposeComponent(xStmt);
     413                 :          0 :             }
     414                 :            :         }
     415                 :            : 
     416 [ #  # ][ #  # ]:          0 :         if ( m_xTableDefinitions.is() && m_xTableDefinitions->hasByName(_sElementName) )
         [ #  # ][ #  # ]
                 [ #  # ]
     417                 :            :         {
     418 [ #  # ][ #  # ]:          0 :             m_xTableDefinitions->removeByName(_sElementName);
     419                 :          0 :         }
     420                 :            :     }
     421         [ #  # ]:          0 :     catch(const Exception&)
     422                 :            :     {
     423                 :          0 :         m_bInDrop = sal_False;
     424                 :          0 :         throw;
     425                 :            :     }
     426                 :          0 :     m_bInDrop = sal_False;
     427                 :          0 : }
     428                 :            : 
     429                 :          0 : void SAL_CALL OTableContainer::elementInserted( const ContainerEvent& Event ) throw (RuntimeException)
     430                 :            : {
     431                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::elementInserted" );
     432         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_rMutex);
     433                 :          0 :     ::rtl::OUString sName;
     434                 :          0 :     Event.Accessor >>= sName;
     435 [ #  # ][ #  # ]:          0 :     if ( !m_nInAppend && !hasByName(sName) )
         [ #  # ][ #  # ]
     436                 :            :     {
     437 [ #  # ][ #  # ]:          0 :         if(!m_xMasterContainer.is() || m_xMasterContainer->hasByName(sName))
         [ #  # ][ #  # ]
                 [ #  # ]
     438                 :            :         {
     439         [ #  # ]:          0 :             ObjectType xName = createObject(sName);
     440         [ #  # ]:          0 :             insertElement(sName,xName);
     441                 :            :             // and notify our listeners
     442 [ #  # ][ #  # ]:          0 :             ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(sName), makeAny(xName), Any());
         [ #  # ][ #  # ]
     443 [ #  # ][ #  # ]:          0 :             m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
     444                 :            :         }
     445         [ #  # ]:          0 :     }
     446                 :          0 : }
     447                 :            : 
     448                 :          0 : void SAL_CALL OTableContainer::elementRemoved( const ContainerEvent& /*Event*/ ) throw (RuntimeException)
     449                 :            : {
     450                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::elementRemoved" );
     451                 :          0 : }
     452                 :            : 
     453                 :          0 : void SAL_CALL OTableContainer::elementReplaced( const ContainerEvent& Event ) throw (RuntimeException)
     454                 :            : {
     455                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::elementReplaced" );
     456                 :            :     // create a new config entry
     457                 :            :     {
     458                 :          0 :         ::rtl::OUString sOldComposedName,sNewComposedName;
     459                 :          0 :         Event.ReplacedElement   >>= sOldComposedName;
     460                 :          0 :         Event.Accessor          >>= sNewComposedName;
     461                 :            : 
     462         [ #  # ]:          0 :         renameObject(sOldComposedName,sNewComposedName);
     463                 :            :     }
     464                 :          0 : }
     465                 :            : 
     466                 :         56 : void SAL_CALL OTableContainer::disposing()
     467                 :            : {
     468                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::disposing" );
     469                 :         56 :     OFilteredContainer::disposing();
     470                 :            :     // say goodbye to our listeners
     471                 :         56 :     m_xTableDefinitions = NULL;
     472                 :         56 :     m_pTableMediator = NULL;
     473                 :         56 : }
     474                 :            : 
     475                 :          0 : void SAL_CALL OTableContainer::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
     476                 :            : {
     477                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::disposing" );
     478                 :          0 : }
     479                 :            : 
     480                 :         50 : void OTableContainer::addMasterContainerListener()
     481                 :            : {
     482                 :            :     try
     483                 :            :     {
     484         [ +  - ]:         50 :         Reference< XContainer > xCont( m_xMasterContainer, UNO_QUERY_THROW );
     485 [ +  - ][ +  - ]:         50 :         xCont->addContainerListener( this );
         [ +  - ][ #  # ]
     486                 :            :     }
     487                 :          0 :     catch( const Exception& )
     488                 :            :     {
     489                 :            :         DBG_UNHANDLED_EXCEPTION();
     490                 :            :     }
     491                 :         50 : }
     492                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10