Files
libreoffice/dbaccess/source/core/api/querycomposer.cxx

328 lines
11 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-14 17:39:53 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 23:16:46 +00:00
#include <string.h>
2000-09-18 23:16:46 +00:00
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/util/XNumberFormatter.hpp>
#include <com/sun/star/sdbc/ColumnSearch.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
2001-04-11 05:21:33 +00:00
#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
#include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
2000-10-11 10:21:40 +00:00
#include <comphelper/sequence.hxx>
#include <com/sun/star/uno/XAggregation.hpp>
2000-10-11 10:21:40 +00:00
#include <comphelper/processfactory.hxx>
2000-10-24 11:59:42 +00:00
#include "dbastrings.hrc"
#include <cppuhelper/supportsservice.hxx>
2000-09-18 23:16:46 +00:00
#include <cppuhelper/typeprovider.hxx>
2000-09-29 14:23:36 +00:00
#include <unotools/configmgr.hxx>
2000-10-12 15:21:03 +00:00
#include <comphelper/types.hxx>
2000-10-24 11:59:42 +00:00
#include <tools/debug.hxx>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/i18n/XLocaleData.hpp>
#include <unotools/syslocale.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/sdb/SQLFilterOperator.hpp>
#include "querycomposer.hxx"
#include "HelperCollections.hxx"
#include "composertools.hxx"
#include <algorithm>
2000-09-18 23:16:46 +00:00
using namespace dbaccess;
2001-08-09 12:08:05 +00:00
using namespace dbtools;
2001-05-18 11:02:50 +00:00
using namespace comphelper;
2000-09-18 23:16:46 +00:00
using namespace connectivity;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::i18n;
2000-09-18 23:16:46 +00:00
using namespace ::com::sun::star::lang;
2001-08-09 12:08:05 +00:00
using namespace ::com::sun::star::script;
2000-09-18 23:16:46 +00:00
using namespace ::cppu;
using namespace ::osl;
2000-09-29 14:23:36 +00:00
using namespace ::utl;
2000-09-18 23:16:46 +00:00
2000-09-18 23:16:46 +00:00
DBG_NAME(OQueryComposer)
OQueryComposer::OQueryComposer(const Reference< XConnection>& _xConnection)
2000-09-18 23:16:46 +00:00
: OSubComponent(m_aMutex,_xConnection)
{
SAL_INFO("dbaccess", "OQueryComposer::OQueryComposer" );
2000-09-18 23:16:46 +00:00
DBG_CTOR(OQueryComposer,NULL);
2001-03-23 12:33:59 +00:00
OSL_ENSURE(_xConnection.is()," Connection cant be null!");
2000-09-18 23:16:46 +00:00
Reference<XMultiServiceFactory> xFac( _xConnection, UNO_QUERY_THROW );
m_xComposer.set( xFac->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
m_xComposerHelper.set( xFac->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
OQueryComposer::~OQueryComposer()
{
DBG_DTOR(OQueryComposer,NULL);
}
void SAL_CALL OQueryComposer::disposing()
{
SAL_INFO("dbaccess", "OQueryComposer::disposing" );
::comphelper::disposeComponent(m_xComposerHelper);
::comphelper::disposeComponent(m_xComposer);
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
// ::com::sun::star::lang::XTypeProvider
Sequence< Type > SAL_CALL OQueryComposer::getTypes() throw (RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::getTypes" );
2000-10-11 10:21:40 +00:00
return ::comphelper::concatSequences(OSubComponent::getTypes(),OQueryComposer_BASE::getTypes());
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
Sequence< sal_Int8 > SAL_CALL OQueryComposer::getImplementationId() throw (RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::getImplementationId" );
2000-09-18 23:16:46 +00:00
static OImplementationId * pId = 0;
if (! pId)
{
MutexGuard aGuard( Mutex::getGlobalMutex() );
if (! pId)
{
static OImplementationId aId;
pId = &aId;
}
}
return pId->getImplementationId();
}
2000-09-18 23:16:46 +00:00
// com::sun::star::lang::XUnoTunnel
sal_Int64 SAL_CALL OQueryComposer::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::getSomething" );
if (rId.getLength() == 16 && 0 == memcmp(getImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
return reinterpret_cast<sal_Int64>(this);
2000-09-18 23:16:46 +00:00
return 0;
}
2000-09-18 23:16:46 +00:00
Any SAL_CALL OQueryComposer::queryInterface( const Type & rType ) throw(RuntimeException)
{
//SAL_INFO("dbaccess", "OQueryComposer::queryInterface" );
2000-09-18 23:16:46 +00:00
Any aRet = OSubComponent::queryInterface(rType);
if(!aRet.hasValue())
aRet = OQueryComposer_BASE::queryInterface(rType);
return aRet;
}
2000-09-18 23:16:46 +00:00
// XServiceInfo
OUString OQueryComposer::getImplementationName( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getImplementationName" );
return OUString("com.sun.star.sdb.dbaccess.OQueryComposer");
2000-09-18 23:16:46 +00:00
}
sal_Bool OQueryComposer::supportsService( const OUString& _rServiceName ) throw (RuntimeException)
2000-09-18 23:16:46 +00:00
{
return cppu::supportsService(this, _rServiceName);
2000-09-18 23:16:46 +00:00
}
Sequence< OUString > OQueryComposer::getSupportedServiceNames( ) throw (RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getSupportedServiceNames" );
Sequence< OUString > aSNS( 1 );
aSNS[0] = SERVICE_SDB_SQLQUERYCOMPOSER;
2000-09-18 23:16:46 +00:00
return aSNS;
}
2000-09-18 23:16:46 +00:00
// XSQLQueryComposer
OUString SAL_CALL OQueryComposer::getQuery( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getQuery" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
Reference<XPropertySet> xProp(m_xComposer,UNO_QUERY);
OUString sQuery;
if ( xProp.is() )
xProp->getPropertyValue(PROPERTY_ORIGINAL) >>= sQuery;
return sQuery;
2000-09-18 23:16:46 +00:00
}
void SAL_CALL OQueryComposer::setQuery( const OUString& command ) throw(SQLException, RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::setQuery" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
m_aFilters.clear();
m_xComposer->setQuery(command);
m_sOrgFilter = m_xComposer->getFilter();
m_sOrgOrder = m_xComposer->getOrder();
2000-09-18 23:16:46 +00:00
}
OUString SAL_CALL OQueryComposer::getComposedQuery( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getComposedQuery" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
MutexGuard aGuard(m_aMutex);
return m_xComposer->getQuery();
2000-09-18 23:16:46 +00:00
}
OUString SAL_CALL OQueryComposer::getFilter( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getFilter" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
MutexGuard aGuard(m_aMutex);
FilterCreator aFilterCreator;
aFilterCreator = ::std::for_each(m_aFilters.begin(),m_aFilters.end(),aFilterCreator);
return aFilterCreator.getComposedAndClear();
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
Sequence< Sequence< PropertyValue > > SAL_CALL OQueryComposer::getStructuredFilter( ) throw(RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::getStructuredFilter" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
MutexGuard aGuard(m_aMutex);
return m_xComposer->getStructuredFilter();
2000-09-18 23:16:46 +00:00
}
OUString SAL_CALL OQueryComposer::getOrder( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getOrder" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
OrderCreator aOrderCreator;
aOrderCreator = ::std::for_each(m_aOrders.begin(),m_aOrders.end(),aOrderCreator);
return aOrderCreator.getComposedAndClear();
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
void SAL_CALL OQueryComposer::appendFilterByColumn( const Reference< XPropertySet >& column ) throw(SQLException, RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::appendFilterByColumn" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
m_xComposerHelper->setQuery(getQuery());
m_xComposerHelper->setFilter(OUString());
m_xComposerHelper->appendFilterByColumn(column, sal_True, SQLFilterOperator::EQUAL);
FilterCreator aFilterCreator;
aFilterCreator.append(getFilter());
aFilterCreator.append(m_xComposerHelper->getFilter());
setFilter( aFilterCreator.getComposedAndClear() );
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
void SAL_CALL OQueryComposer::appendOrderByColumn( const Reference< XPropertySet >& column, sal_Bool ascending ) throw(SQLException, RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::appendOrderByColumn" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
m_xComposerHelper->setQuery(getQuery());
m_xComposerHelper->setOrder(OUString());
m_xComposerHelper->appendOrderByColumn(column,ascending);
OrderCreator aOrderCreator;
aOrderCreator.append(getOrder());
aOrderCreator.append(m_xComposerHelper->getOrder());
setOrder(aOrderCreator.getComposedAndClear());
2000-09-18 23:16:46 +00:00
}
void SAL_CALL OQueryComposer::setFilter( const OUString& filter ) throw(SQLException, RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::setFilter" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
FilterCreator aFilterCreator;
aFilterCreator.append(m_sOrgFilter);
aFilterCreator.append(filter);
m_aFilters.clear();
if ( !filter.isEmpty() )
m_aFilters.push_back(filter);
m_xComposer->setFilter( aFilterCreator.getComposedAndClear() );
2000-09-18 23:16:46 +00:00
}
void SAL_CALL OQueryComposer::setOrder( const OUString& order ) throw(SQLException, RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::setOrder" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
OrderCreator aOrderCreator;
aOrderCreator.append(m_sOrgOrder);
aOrderCreator.append(order);
m_aOrders.clear();
if ( !order.isEmpty() )
m_aOrders.push_back(order);
m_xComposer->setOrder(aOrderCreator.getComposedAndClear());
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
// XTablesSupplier
2001-03-01 10:04:49 +00:00
Reference< XNameAccess > SAL_CALL OQueryComposer::getTables( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getTables" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
return Reference<XTablesSupplier>(m_xComposer,UNO_QUERY)->getTables();
2000-09-18 23:16:46 +00:00
}
2000-09-18 23:16:46 +00:00
// XColumnsSupplier
2001-03-01 10:04:49 +00:00
Reference< XNameAccess > SAL_CALL OQueryComposer::getColumns( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
SAL_INFO("dbaccess", "OQueryComposer::getColumns" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2000-09-18 23:16:46 +00:00
::osl::MutexGuard aGuard( m_aMutex );
return Reference<XColumnsSupplier>(m_xComposer,UNO_QUERY)->getColumns();
2000-09-18 23:16:46 +00:00
}
2001-03-01 10:04:49 +00:00
Reference< XIndexAccess > SAL_CALL OQueryComposer::getParameters( ) throw(RuntimeException)
{
SAL_INFO("dbaccess", "OQueryComposer::getParameters" );
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
2001-03-01 10:04:49 +00:00
::osl::MutexGuard aGuard( m_aMutex );
return Reference<XParametersSupplier>(m_xComposer,UNO_QUERY)->getParameters();
2001-03-01 10:04:49 +00:00
}
void SAL_CALL OQueryComposer::acquire() throw()
2001-04-30 09:16:19 +00:00
{
OSubComponent::acquire();
}
void SAL_CALL OQueryComposer::release() throw()
2001-04-30 09:16:19 +00:00
{
OSubComponent::release();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */