LibreOffice Module dbaccess (master) 1
HelperCollections.cxx
Go to the documentation of this file.
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 "HelperCollections.hxx"
21
22#include <strings.hxx>
23#include <utility>
24
25#include <osl/diagnose.h>
26
27namespace dbaccess
28{
29 using namespace dbtools;
30 using namespace comphelper;
31 using namespace connectivity;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::sdb;
36 using namespace ::com::sun::star::sdbcx;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::script;
40 using namespace ::cppu;
41 using namespace ::osl;
42
44 bool _bCase,
45 ::cppu::OWeakObject& _rParent,
46 ::osl::Mutex& _rMutex,
47 const std::vector< OUString> &_rVector,
48 bool _bUseAsIndex
49 ) : sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector,_bUseAsIndex)
50 ,m_aColumns(std::move(_xColumns))
51 {
52 }
53
54 std::unique_ptr<OPrivateColumns> OPrivateColumns::createWithIntrinsicNames( const ::rtl::Reference< ::connectivity::OSQLColumns >& _rColumns,
55 bool _bCase, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex )
56 {
57 std::vector< OUString > aNames; aNames.reserve( _rColumns->size() );
58
59 OUString sColumName;
60 for (auto const& column : *_rColumns)
61 {
62 Reference< XPropertySet > xColumn(column, UNO_SET_THROW);
63 xColumn->getPropertyValue( PROPERTY_NAME ) >>= sColumName;
64 aNames.push_back( sColumName );
65 }
66 return std::unique_ptr<OPrivateColumns>(new OPrivateColumns( _rColumns, _bCase, _rParent, _rMutex, aNames, false ));
67 }
68
70 {
71 m_aColumns = nullptr;
73 // we're not owner of the objects we're holding, instead the object we got in our ctor is
74 // So we're not allowed to dispose our elements.
76 }
77
79 {
80 if ( m_aColumns.is() )
81 {
82 ::connectivity::OSQLColumns::Vector::const_iterator aIter = find(m_aColumns->begin(),m_aColumns->end(),_rName,isCaseSensitive());
83 if(aIter == m_aColumns->end())
84 aIter = findRealName(m_aColumns->begin(),m_aColumns->end(),_rName,isCaseSensitive());
85
86 if(aIter != m_aColumns->end())
87 return connectivity::sdbcx::ObjectType(*aIter,UNO_QUERY);
88
89 OSL_FAIL("Column not found in collection!");
90 }
91 return nullptr;
92 }
93
95 {
96 if ( !m_aTables.empty() )
97 {
98 OSQLTables::iterator aIter = m_aTables.find(_rName);
99 OSL_ENSURE(aIter != m_aTables.end(),"Table not found!");
100 OSL_ENSURE(aIter->second.is(),"Table is null!");
101 return connectivity::sdbcx::ObjectType(m_aTables.find(_rName)->second,UNO_QUERY);
102 }
103 return nullptr;
104 }
105}
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OPrivateColumns(::rtl::Reference< ::connectivity::OSQLColumns > _xColumns, bool _bCase, ::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex, const std::vector< OUString > &_rVector, bool _bUseAsIndex=false)
virtual connectivity::sdbcx::ObjectType createObject(const OUString &_rName) override
virtual void disposing() override
static std::unique_ptr< OPrivateColumns > createWithIntrinsicNames(const ::rtl::Reference< ::connectivity::OSQLColumns > &_rColumns, bool _bCase, ::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex)
creates a columns instance as above, but taking the names from the columns itself
::rtl::Reference< ::connectivity::OSQLColumns > m_aColumns
virtual connectivity::sdbcx::ObjectType createObject(const OUString &_rName) override
Reference< XColumn > xColumn
css::uno::Reference< css::beans::XPropertySet > ObjectType
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
OSQLColumns::const_iterator findRealName(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
constexpr OUStringLiteral PROPERTY_NAME(u"Name")