LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mork - MDatabaseMetaDataHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 49 87.8 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.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             : 
      10             : #include "MDatabaseMetaDataHelper.hxx"
      11             : #include "FDatabaseMetaDataResultSet.hxx"
      12             : #include <connectivity/dbexception.hxx>
      13             : #include <comphelper/uno3.hxx>
      14             : #include <comphelper/sequence.hxx>
      15             : #include <osl/mutex.hxx>
      16             : #include <osl/conditn.hxx>
      17             : 
      18             : // do we need it?
      19           2 : static ::osl::Mutex m_aMetaMutex;
      20             : 
      21             : #include <osl/diagnose.h>
      22             : #include <com/sun/star/uno/Reference.hxx>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <com/sun/star/uno/XInterface.hpp>
      25             : #include <com/sun/star/uno/Exception.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include <com/sun/star/beans/Property.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      30             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      31             : #include <com/sun/star/sdb/ErrorCondition.hpp>
      32             : #include <comphelper/processfactory.hxx>
      33             : 
      34             : #include "MorkParser.hxx"
      35             : 
      36             : using namespace connectivity;
      37             : using namespace connectivity::mork;
      38             : 
      39             : 
      40           3 : MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()
      41             : {
      42             :     SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()" );
      43           3 : }
      44             : 
      45             : 
      46           3 : MDatabaseMetaDataHelper::~MDatabaseMetaDataHelper()
      47             : {
      48           3 : }
      49             : 
      50          81 : bool MDatabaseMetaDataHelper::getTableStrings( OConnection* _pCon,
      51             :                                                    ::std::vector< OUString >& _rStrings)
      52             : {
      53             :     SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTableStrings()");
      54             : 
      55             :     /* add default tables */
      56          81 :     _rStrings.push_back("AddressBook");
      57          81 :     _rStrings.push_back("CollectedAddressBook");
      58             : 
      59             :     /* retrieve list table names (not from collected ab) */
      60          81 :     std::set<std::string> lists;
      61          81 :     MorkParser* pMork = _pCon->getMorkParser("AddressBook");
      62          81 :     pMork->retrieveLists(lists);
      63         243 :     for (::std::set<std::string>::iterator iter = lists.begin(); iter != lists.end(); ++iter) {
      64         162 :         OUString groupTableName = OStringToOUString((*iter).c_str(), RTL_TEXTENCODING_UTF8);
      65             :         SAL_INFO("connectivity.mork", "add Table " << groupTableName);
      66             : 
      67         162 :         _rStrings.push_back(groupTableName);
      68             :         // remember the list in the mork parser, we'll use it later
      69         162 :         pMork->lists_.push_back(groupTableName);
      70         162 :     }
      71             : 
      72         162 :     std::set<std::string> lists_history;
      73          81 :     pMork = _pCon->getMorkParser("CollectedAddressBook");
      74          81 :     pMork->retrieveLists(lists_history);
      75          81 :     for (::std::set<std::string>::iterator iter = lists_history.begin(); iter != lists_history.end(); ++iter) {
      76           0 :         OUString groupTableName = OStringToOUString((*iter).c_str(), RTL_TEXTENCODING_UTF8);
      77             :         SAL_INFO("connectivity.mork", "add Table " << groupTableName);
      78             : 
      79           0 :         _rStrings.push_back(groupTableName);
      80             :         // remember the list in the mork parser, we'll use it later
      81           0 :         pMork->lists_.push_back(groupTableName);
      82           0 :     }
      83             : 
      84         162 :     return true;
      85             : }
      86             : 
      87           5 : bool MDatabaseMetaDataHelper::getTables( OConnection* _pCon,
      88             :                                              const OUString& tableNamePattern,
      89             :                                              ODatabaseMetaDataResultSet::ORows& _rRows)
      90             : {
      91             : 
      92             :     SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()");
      93             : 
      94           5 :     static ODatabaseMetaDataResultSet::ORows    aRows;
      95             : 
      96             :     SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()" );
      97             :     SAL_INFO("connectivity.mork", "tableNamePattern : " << tableNamePattern);
      98           5 :     ::osl::MutexGuard aGuard( m_aMetaMutex );
      99             : 
     100           5 :     ODatabaseMetaDataResultSet::ORows().swap(aRows); // this makes real clear where memory is freed as well
     101           5 :     aRows.clear();
     102             : 
     103          10 :     ::std::vector< OUString > tables;
     104             : 
     105           5 :     if ( !getTableStrings( _pCon, tables ) )
     106           0 :         return false;
     107             : 
     108          25 :     for ( size_t i = 0; i < tables.size(); i++ ) {
     109          20 :         ODatabaseMetaDataResultSet::ORow aRow(3);
     110             : 
     111          40 :         OUString aTableName  = tables[i];
     112             :         SAL_INFO("connectivity.mork", "TableName: " << aTableName );
     113             : 
     114             : 
     115             :         // return tables to caller
     116          20 :         if (match( tableNamePattern, aTableName, '\0' ))
     117             :         {
     118          14 :             if ( aTableName.isEmpty() ) {
     119           0 :                 aTableName = "AddressBook";
     120             :             }
     121             : 
     122             :             SAL_INFO("connectivity.mork", "TableName: " << aTableName);
     123             : 
     124          14 :             aRow.push_back( new ORowSetValueDecorator( aTableName ) ); // Table/View name
     125          14 :             if ((aTableName == "AddressBook") || (aTableName == "CollectedAddressBook"))
     126             :             {
     127           7 :                 aRow.push_back( new ORowSetValueDecorator( OUString("TABLE") ) ); // Table type
     128             :             }
     129             :             else
     130             :             {
     131           7 :                 aRow.push_back( new ORowSetValueDecorator( OUString("VIEW") ) ); // View type
     132             :             }
     133          14 :             aRow.push_back( ODatabaseMetaDataResultSet::getEmptyValue() ); // Remarks
     134          14 :             aRows.push_back(aRow);
     135             :         }
     136          20 :     }
     137             : 
     138           5 :     _rRows = aRows;
     139          10 :     return true;
     140           6 : }
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11