LibreOffice Module dbaccess (master) 1
querycomposer.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 <com/sun/star/lang/DisposedException.hpp>
21#include <com/sun/star/lang/XMultiServiceFactory.hpp>
22#include <com/sun/star/sdbc/ColumnSearch.hpp>
23#include <com/sun/star/sdbc/XConnection.hpp>
27#include <comphelper/types.hxx>
28#include <com/sun/star/sdb/SQLFilterOperator.hpp>
29#include <querycomposer.hxx>
30#include <strings.hxx>
31#include <composertools.hxx>
32#include <algorithm>
33
34using namespace dbaccess;
35using namespace comphelper;
36using namespace connectivity;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::beans;
39using namespace ::com::sun::star::sdbc;
40using namespace ::com::sun::star::sdb;
41using namespace ::com::sun::star::sdbcx;
42using namespace ::com::sun::star::container;
43using namespace ::com::sun::star::lang;
44using namespace ::cppu;
45using namespace ::osl;
46using namespace ::utl;
47
48
49OQueryComposer::OQueryComposer(const Reference< XConnection>& _xConnection)
50 : OSubComponent(m_aMutex,_xConnection)
51{
52 OSL_ENSURE(_xConnection.is()," Connection can't be null!");
53
54 Reference<XMultiServiceFactory> xFac( _xConnection, UNO_QUERY_THROW );
55 m_xComposer.set( xFac->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
56 m_xComposerHelper.set( xFac->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
57}
58
60{
61}
62
64{
65 ::comphelper::disposeComponent(m_xComposerHelper);
66 ::comphelper::disposeComponent(m_xComposer);
67}
68
69// css::lang::XTypeProvider
70Sequence< Type > SAL_CALL OQueryComposer::getTypes()
71{
72 return ::comphelper::concatSequences(OSubComponent::getTypes(),OQueryComposer_BASE::getTypes());
73}
74
75Sequence< sal_Int8 > SAL_CALL OQueryComposer::getImplementationId()
76{
77 return css::uno::Sequence<sal_Int8>();
78}
79
80Any SAL_CALL OQueryComposer::queryInterface( const Type & rType )
81{
82 Any aRet = OSubComponent::queryInterface(rType);
83 if(!aRet.hasValue())
85 return aRet;
86}
87
88// XServiceInfo
90{
91 return "com.sun.star.sdb.dbaccess.OQueryComposer";
92}
93
94sal_Bool OQueryComposer::supportsService( const OUString& _rServiceName )
95{
96 return cppu::supportsService(this, _rServiceName);
97}
98
100{
102}
103
104// XSQLQueryComposer
105OUString SAL_CALL OQueryComposer::getQuery( )
106{
107 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
108
109 ::osl::MutexGuard aGuard( m_aMutex );
110 Reference<XPropertySet> xProp(m_xComposer,UNO_QUERY);
111 OUString sQuery;
112 if ( xProp.is() )
113 xProp->getPropertyValue(PROPERTY_ORIGINAL) >>= sQuery;
114 return sQuery;
115}
116
117void SAL_CALL OQueryComposer::setQuery( const OUString& command )
118{
119 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
120
121 ::osl::MutexGuard aGuard( m_aMutex );
122 m_aFilters.clear();
123 m_xComposer->setQuery(command);
124 m_sOrgFilter = m_xComposer->getFilter();
125 m_sOrgOrder = m_xComposer->getOrder();
126}
127
129{
130 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
131
132 MutexGuard aGuard(m_aMutex);
133
134 return m_xComposer->getQuery();
135}
136
137OUString SAL_CALL OQueryComposer::getFilter( )
138{
139 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
140 MutexGuard aGuard(m_aMutex);
141 FilterCreator aFilterCreator;
142 aFilterCreator = std::for_each(m_aFilters.begin(),m_aFilters.end(),aFilterCreator);
143 return aFilterCreator.getComposedAndClear();
144}
145
146Sequence< Sequence< PropertyValue > > SAL_CALL OQueryComposer::getStructuredFilter( )
147{
148 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
149
150 MutexGuard aGuard(m_aMutex);
151 return m_xComposer->getStructuredFilter();
152}
153
154OUString SAL_CALL OQueryComposer::getOrder( )
155{
156 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
157
158 ::osl::MutexGuard aGuard( m_aMutex );
159 OrderCreator aOrderCreator;
160 aOrderCreator = std::for_each(m_aOrders.begin(),m_aOrders.end(),aOrderCreator);
161 return aOrderCreator.getComposedAndClear();
162}
163
164void SAL_CALL OQueryComposer::appendFilterByColumn( const Reference< XPropertySet >& column )
165{
166 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
167 ::osl::MutexGuard aGuard( m_aMutex );
168
169 m_xComposerHelper->setQuery(getQuery());
170 m_xComposerHelper->setFilter(OUString());
171 m_xComposerHelper->appendFilterByColumn(column, true, SQLFilterOperator::EQUAL);
172
173 FilterCreator aFilterCreator;
174 aFilterCreator.append(getFilter());
175 aFilterCreator.append(m_xComposerHelper->getFilter());
176
177 setFilter( aFilterCreator.getComposedAndClear() );
178}
179
180void SAL_CALL OQueryComposer::appendOrderByColumn( const Reference< XPropertySet >& column, sal_Bool ascending )
181{
182 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
183 ::osl::MutexGuard aGuard( m_aMutex );
184
185 m_xComposerHelper->setQuery(getQuery());
186 m_xComposerHelper->setOrder(OUString());
187 m_xComposerHelper->appendOrderByColumn(column,ascending);
188
189 OrderCreator aOrderCreator;
190 aOrderCreator.append(getOrder());
191 aOrderCreator.append(m_xComposerHelper->getOrder());
192
193 setOrder(aOrderCreator.getComposedAndClear());
194}
195
196void SAL_CALL OQueryComposer::setFilter( const OUString& filter )
197{
198 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
199
200 ::osl::MutexGuard aGuard( m_aMutex );
201 FilterCreator aFilterCreator;
202 aFilterCreator.append(m_sOrgFilter);
203 aFilterCreator.append(filter);
204
205 m_aFilters.clear();
206 if ( !filter.isEmpty() )
207 m_aFilters.push_back(filter);
208
209 m_xComposer->setFilter( aFilterCreator.getComposedAndClear() );
210}
211
212void SAL_CALL OQueryComposer::setOrder( const OUString& order )
213{
214 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
215
216 ::osl::MutexGuard aGuard( m_aMutex );
217
218 OrderCreator aOrderCreator;
219 aOrderCreator.append(m_sOrgOrder);
220 aOrderCreator.append(order);
221
222 m_aOrders.clear();
223 if ( !order.isEmpty() )
224 m_aOrders.push_back(order);
225
226 m_xComposer->setOrder(aOrderCreator.getComposedAndClear());
227}
228
229// XTablesSupplier
230Reference< XNameAccess > SAL_CALL OQueryComposer::getTables( )
231{
232 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
233
234 ::osl::MutexGuard aGuard( m_aMutex );
235 return Reference<XTablesSupplier>(m_xComposer,UNO_QUERY_THROW)->getTables();
236}
237
238// XColumnsSupplier
239Reference< XNameAccess > SAL_CALL OQueryComposer::getColumns( )
240{
241 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
242
243 ::osl::MutexGuard aGuard( m_aMutex );
244 return Reference<XColumnsSupplier>(m_xComposer,UNO_QUERY_THROW)->getColumns();
245}
246
247Reference< XIndexAccess > SAL_CALL OQueryComposer::getParameters( )
248{
249 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
250
251 ::osl::MutexGuard aGuard( m_aMutex );
252 return Reference<XParametersSupplier>(m_xComposer,UNO_QUERY_THROW)->getParameters();
253}
254
255void SAL_CALL OQueryComposer::acquire() noexcept
256{
257 OSubComponent::acquire();
258}
259
260void SAL_CALL OQueryComposer::release() noexcept
261{
263}
264
265/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL release() noexcept override
Definition: apitools.cxx:46
mutable::osl::Mutex m_aMutex
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
std::vector< OUString > m_aFilters
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xComposerHelper
virtual OUString SAL_CALL getQuery() override
virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getStructuredFilter() override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL setQuery(const OUString &command) override
virtual void SAL_CALL setFilter(const OUString &filter) override
virtual OUString SAL_CALL getFilter() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getColumns() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL acquire() noexcept override
virtual ~OQueryComposer() override
css::uno::Reference< css::sdb::XSingleSelectQueryComposer > m_xComposer
virtual OUString SAL_CALL getComposedQuery() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL setOrder(const OUString &order) override
std::vector< OUString > m_aOrders
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL appendOrderByColumn(const css::uno::Reference< css::beans::XPropertySet > &column, sal_Bool ascending) override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL appendFilterByColumn(const css::uno::Reference< css::beans::XPropertySet > &column) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getParameters() override
virtual OUString SAL_CALL getOrder() override
virtual void SAL_CALL disposing() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
std::mutex m_aMutex
Type
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral PROPERTY_ORIGINAL(u"Original")
constexpr OUStringLiteral SERVICE_NAME_SINGLESELECTQUERYCOMPOSER
Definition: strings.hxx:201
constexpr OUStringLiteral SERVICE_SDB_SQLQUERYCOMPOSER
Definition: strings.hxx:189
void append(const OUString &lhs)
unsigned char sal_Bool