calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / dbaccess / source / core / api / querycomposer.cxx
blob8bab8718709b51fbb5bf255fa736e9798733197e
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
24 #include <comphelper/sequence.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <unotools/configmgr.hxx>
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>
34 using namespace dbaccess;
35 using namespace comphelper;
36 using namespace connectivity;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::sdb;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::lang;
44 using namespace ::cppu;
45 using namespace ::osl;
46 using namespace ::utl;
49 OQueryComposer::OQueryComposer(const Reference< XConnection>& _xConnection)
50 : OSubComponent(m_aMutex,_xConnection)
52 OSL_ENSURE(_xConnection.is()," Connection can't be null!");
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 );
59 OQueryComposer::~OQueryComposer()
63 void SAL_CALL OQueryComposer::disposing()
65 ::comphelper::disposeComponent(m_xComposerHelper);
66 ::comphelper::disposeComponent(m_xComposer);
69 // css::lang::XTypeProvider
70 Sequence< Type > SAL_CALL OQueryComposer::getTypes()
72 return ::comphelper::concatSequences(OSubComponent::getTypes(),OQueryComposer_BASE::getTypes());
75 Sequence< sal_Int8 > SAL_CALL OQueryComposer::getImplementationId()
77 return css::uno::Sequence<sal_Int8>();
80 Any SAL_CALL OQueryComposer::queryInterface( const Type & rType )
82 Any aRet = OSubComponent::queryInterface(rType);
83 if(!aRet.hasValue())
84 aRet = OQueryComposer_BASE::queryInterface(rType);
85 return aRet;
88 // XServiceInfo
89 OUString OQueryComposer::getImplementationName( )
91 return "com.sun.star.sdb.dbaccess.OQueryComposer";
94 sal_Bool OQueryComposer::supportsService( const OUString& _rServiceName )
96 return cppu::supportsService(this, _rServiceName);
99 Sequence< OUString > OQueryComposer::getSupportedServiceNames( )
101 return { SERVICE_SDB_SQLQUERYCOMPOSER };
104 // XSQLQueryComposer
105 OUString SAL_CALL OQueryComposer::getQuery( )
107 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
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;
117 void SAL_CALL OQueryComposer::setQuery( const OUString& command )
119 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
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();
128 OUString SAL_CALL OQueryComposer::getComposedQuery( )
130 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
132 MutexGuard aGuard(m_aMutex);
134 return m_xComposer->getQuery();
137 OUString SAL_CALL OQueryComposer::getFilter( )
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();
146 Sequence< Sequence< PropertyValue > > SAL_CALL OQueryComposer::getStructuredFilter( )
148 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
150 MutexGuard aGuard(m_aMutex);
151 return m_xComposer->getStructuredFilter();
154 OUString SAL_CALL OQueryComposer::getOrder( )
156 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
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();
164 void SAL_CALL OQueryComposer::appendFilterByColumn( const Reference< XPropertySet >& column )
166 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
167 ::osl::MutexGuard aGuard( m_aMutex );
169 m_xComposerHelper->setQuery(getQuery());
170 m_xComposerHelper->setFilter(OUString());
171 m_xComposerHelper->appendFilterByColumn(column, true, SQLFilterOperator::EQUAL);
173 FilterCreator aFilterCreator;
174 aFilterCreator.append(getFilter());
175 aFilterCreator.append(m_xComposerHelper->getFilter());
177 setFilter( aFilterCreator.getComposedAndClear() );
180 void SAL_CALL OQueryComposer::appendOrderByColumn( const Reference< XPropertySet >& column, sal_Bool ascending )
182 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
183 ::osl::MutexGuard aGuard( m_aMutex );
185 m_xComposerHelper->setQuery(getQuery());
186 m_xComposerHelper->setOrder(OUString());
187 m_xComposerHelper->appendOrderByColumn(column,ascending);
189 OrderCreator aOrderCreator;
190 aOrderCreator.append(getOrder());
191 aOrderCreator.append(m_xComposerHelper->getOrder());
193 setOrder(aOrderCreator.getComposedAndClear());
196 void SAL_CALL OQueryComposer::setFilter( const OUString& filter )
198 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
200 ::osl::MutexGuard aGuard( m_aMutex );
201 FilterCreator aFilterCreator;
202 aFilterCreator.append(m_sOrgFilter);
203 aFilterCreator.append(filter);
205 m_aFilters.clear();
206 if ( !filter.isEmpty() )
207 m_aFilters.push_back(filter);
209 m_xComposer->setFilter( aFilterCreator.getComposedAndClear() );
212 void SAL_CALL OQueryComposer::setOrder( const OUString& order )
214 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
216 ::osl::MutexGuard aGuard( m_aMutex );
218 OrderCreator aOrderCreator;
219 aOrderCreator.append(m_sOrgOrder);
220 aOrderCreator.append(order);
222 m_aOrders.clear();
223 if ( !order.isEmpty() )
224 m_aOrders.push_back(order);
226 m_xComposer->setOrder(aOrderCreator.getComposedAndClear());
229 // XTablesSupplier
230 Reference< XNameAccess > SAL_CALL OQueryComposer::getTables( )
232 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
234 ::osl::MutexGuard aGuard( m_aMutex );
235 return Reference<XTablesSupplier>(m_xComposer,UNO_QUERY_THROW)->getTables();
238 // XColumnsSupplier
239 Reference< XNameAccess > SAL_CALL OQueryComposer::getColumns( )
241 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
243 ::osl::MutexGuard aGuard( m_aMutex );
244 return Reference<XColumnsSupplier>(m_xComposer,UNO_QUERY_THROW)->getColumns();
247 Reference< XIndexAccess > SAL_CALL OQueryComposer::getParameters( )
249 ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
251 ::osl::MutexGuard aGuard( m_aMutex );
252 return Reference<XParametersSupplier>(m_xComposer,UNO_QUERY_THROW)->getParameters();
255 void SAL_CALL OQueryComposer::acquire() noexcept
257 OSubComponent::acquire();
260 void SAL_CALL OQueryComposer::release() noexcept
262 OSubComponent::release();
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */