LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - TableWindowData.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 50 0.0 %
Date: 2014-11-03 Functions: 0 8 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 "TableWindowData.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      23             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      24             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      25             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      26             : #include <com/sun/star/container/XNameAccess.hpp>
      27             : #include <com/sun/star/container/XIndexAccess.hpp>
      28             : 
      29             : using namespace dbaui;
      30             : using namespace ::com::sun::star::lang;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::sdb;
      33             : using namespace ::com::sun::star::sdbc;
      34             : using namespace ::com::sun::star::sdbcx;
      35             : using namespace ::com::sun::star::beans;
      36             : using namespace ::com::sun::star::container;
      37             : 
      38             : // class OTableWindowData
      39           0 : OTableWindowData::OTableWindowData( const Reference< XPropertySet>& _xTable
      40             :                                    ,const OUString& _rComposedName
      41             :                                    ,const OUString& rTableName
      42             :                                    ,const OUString& rWinName )
      43             :     :m_xTable(_xTable)
      44             :     ,m_aTableName( rTableName )
      45             :     ,m_aWinName( rWinName )
      46             :     ,m_sComposedName(_rComposedName)
      47             :     ,m_aPosition( Point(-1,-1) )
      48             :     ,m_aSize( Size(-1,-1) )
      49             :     ,m_bShowAll( true )
      50             :     ,m_bIsQuery(false)
      51           0 :     ,m_bIsValid(true)
      52             : {
      53           0 :     if( m_aWinName.isEmpty() )
      54           0 :         m_aWinName = m_aTableName;
      55             : 
      56           0 :     listen();
      57           0 : }
      58             : 
      59           0 : OTableWindowData::~OTableWindowData()
      60             : {
      61           0 :     Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
      62           0 :     if ( xComponent.is() )
      63           0 :         stopComponentListening( xComponent );
      64           0 : }
      65             : 
      66           0 : bool OTableWindowData::HasPosition() const
      67             : {
      68           0 :     return ( (m_aPosition.X() != -1) && (m_aPosition.Y() != -1) );
      69             : }
      70             : 
      71           0 : bool OTableWindowData::HasSize() const
      72             : {
      73           0 :     return ( (m_aSize.Width() != -1) && (m_aSize.Height() !=-1) );
      74             : }
      75             : 
      76           0 : void OTableWindowData::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
      77             : {
      78           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      79             :     // it doesn't matter which one was disposed
      80           0 :     m_xColumns.clear();
      81           0 :     m_xKeys.clear();
      82           0 :     m_xTable.clear();
      83           0 : }
      84             : 
      85           0 : bool OTableWindowData::init(const Reference< XConnection  >& _xConnection,bool _bAllowQueries)
      86             : {
      87             :     OSL_ENSURE(!m_xTable.is(),"We are already connected to a table!");
      88             : 
      89           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      90             : 
      91           0 :     Reference< XQueriesSupplier > xSupQueries( _xConnection, UNO_QUERY_THROW );
      92           0 :     Reference< XNameAccess > xQueries( xSupQueries->getQueries(), UNO_QUERY_THROW );
      93           0 :     bool bIsKnownQuery = _bAllowQueries && xQueries->hasByName( m_sComposedName );
      94             : 
      95           0 :     Reference< XTablesSupplier > xSupTables( _xConnection, UNO_QUERY_THROW );
      96           0 :     Reference< XNameAccess > xTables( xSupTables->getTables(), UNO_QUERY_THROW );
      97           0 :     bool bIsKnownTable = xTables->hasByName( m_sComposedName );
      98             : 
      99           0 :     if ( bIsKnownQuery )
     100           0 :         m_xTable.set( xQueries->getByName( m_sComposedName ), UNO_QUERY );
     101           0 :     else if ( bIsKnownTable )
     102           0 :         m_xTable.set( xTables->getByName( m_sComposedName ), UNO_QUERY );
     103             :     else
     104           0 :         m_bIsValid = false;
     105             : 
     106             :     // if we survived so far, we know whether it's a query
     107           0 :     m_bIsQuery = bIsKnownQuery;
     108             : 
     109           0 :     listen();
     110             : 
     111           0 :     Reference< XIndexAccess > xColumnsAsIndex( m_xColumns,UNO_QUERY );
     112           0 :     return xColumnsAsIndex.is() && ( xColumnsAsIndex->getCount() > 0 );
     113             : }
     114             : 
     115           0 : void OTableWindowData::listen()
     116             : {
     117           0 :     if ( m_xTable.is() )
     118             :     {
     119             :         // listen for the object being disposed
     120           0 :         Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
     121           0 :         if ( xComponent.is() )
     122           0 :             startComponentListening( xComponent );
     123             : 
     124             :         // obtain the columns
     125           0 :         Reference< XColumnsSupplier > xColumnsSups( m_xTable, UNO_QUERY);
     126           0 :         if ( xColumnsSups.is() )
     127           0 :             m_xColumns = xColumnsSups->getColumns();
     128             : 
     129           0 :         Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
     130           0 :         if ( xKeySup.is() )
     131           0 :             m_xKeys = xKeySup->getKeys();
     132             :     }
     133           0 : }
     134             : 
     135             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10