Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mork / MDatabaseMetaDataHelper.cxx
blobc4a239ade7807c9847ab477bbff990057c96a9ab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
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>
18 // do we need it?
19 static ::osl::Mutex m_aMetaMutex;
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>
34 #include "MorkParser.hxx"
36 using namespace connectivity;
37 using namespace connectivity::mork;
40 MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()
42 SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()" );
46 MDatabaseMetaDataHelper::~MDatabaseMetaDataHelper()
50 bool MDatabaseMetaDataHelper::getTableStrings( OConnection* _pCon,
51 ::std::vector< OUString >& _rStrings)
53 SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTableStrings()");
55 /* add default tables */
56 _rStrings.push_back("AddressBook");
57 _rStrings.push_back("CollectedAddressBook");
59 /* retrieve list table names (not from collected ab) */
60 std::set<std::string> lists;
61 _pCon->getMorkParser("AddressBook")->retrieveLists(lists);
62 for (::std::set<std::string>::iterator iter = lists.begin(); iter != lists.end(); ++iter) {
63 OUString groupTableName = OStringToOUString((*iter).c_str(), RTL_TEXTENCODING_UTF8);
64 SAL_INFO("connectivity.mork", "add Table " << groupTableName);
66 _rStrings.push_back(groupTableName);
69 return true;
72 bool MDatabaseMetaDataHelper::getTables( OConnection* _pCon,
73 const OUString& tableNamePattern,
74 ODatabaseMetaDataResultSet::ORows& _rRows)
77 SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()");
79 static ODatabaseMetaDataResultSet::ORows aRows;
81 SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()" );
82 SAL_INFO("connectivity.mork", "tableNamePattern : " << tableNamePattern);
83 ::osl::MutexGuard aGuard( m_aMetaMutex );
85 ODatabaseMetaDataResultSet::ORows().swap(aRows); // this makes real clear where memory is freed as well
86 aRows.clear();
88 ::std::vector< OUString > tables;
90 if ( !getTableStrings( _pCon, tables ) )
91 return false;
93 for ( size_t i = 0; i < tables.size(); i++ ) {
94 ODatabaseMetaDataResultSet::ORow aRow(3);
96 OUString aTableName = tables[i];
97 SAL_INFO("connectivity.mork", "TableName: " << aTableName );
100 // return tables to caller
101 if (match( tableNamePattern, aTableName, '\0' ))
103 if ( aTableName.isEmpty() ) {
104 aTableName = "AddressBook";
107 SAL_INFO("connectivity.mork", "TableName: " << aTableName);
109 aRow.push_back( new ORowSetValueDecorator( aTableName ) ); // Table name
110 aRow.push_back( new ORowSetValueDecorator( OUString("TABLE") ) ); // Table type
111 aRow.push_back( ODatabaseMetaDataResultSet::getEmptyValue() ); // Remarks
112 aRows.push_back(aRow);
116 _rRows = aRows;
117 return true;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */