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

349 lines
13 KiB
C++
Raw Normal View History

2000-09-18 23:16:46 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:16:46 +00:00
*
* $RCSfile: querydescriptor.cxx,v $
2000-09-18 23:16:46 +00:00
*
2006-11-23 13:19:48 +00:00
* $Revision: 1.31 $
2000-09-18 23:16:46 +00:00
*
2006-11-23 13:19:48 +00:00
* last change: $Author: vg $ $Date: 2006-11-23 14:19:48 $
2000-09-18 23:16:46 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-09-18 23:16:46 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-09-18 23:16:46 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-09-18 23:16:46 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-09-18 23:16:46 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-09-18 23:16:46 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
2000-09-18 23:16:46 +00:00
#ifndef _DBA_COREAPI_QUERYDESCRIPTOR_HXX_
#include "querydescriptor.hxx"
#endif
#ifndef _DBASHARED_APITOOLS_HXX_
#include "apitools.hxx"
#endif
2000-10-25 06:32:52 +00:00
#ifndef DBACCESS_SHARED_DBASTRINGS_HRC
#include "dbastrings.hrc"
2000-09-18 23:16:46 +00:00
#endif
2000-10-11 10:21:40 +00:00
#ifndef _COMPHELPER_PROPERTY_HXX_
#include <comphelper/property.hxx>
2000-09-18 23:16:46 +00:00
#endif
2000-10-11 10:21:40 +00:00
#ifndef _COMPHELPER_SEQUENCE_HXX_
#include <comphelper/sequence.hxx>
2000-09-18 23:16:46 +00:00
#endif
#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
#include <cppuhelper/typeprovider.hxx>
#endif
2000-10-25 06:32:52 +00:00
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
2001-02-23 14:22:32 +00:00
#ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
#include "definitioncolumn.hxx"
#endif
2001-08-15 12:05:15 +00:00
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
2000-09-18 23:16:46 +00:00
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
2001-08-30 07:07:36 +00:00
using namespace ::com::sun::star::util;
2000-10-11 10:21:40 +00:00
using namespace ::comphelper;
2000-09-18 23:16:46 +00:00
using namespace ::osl;
using namespace ::cppu;
//........................................................................
namespace dbaccess
{
//........................................................................
2000-09-18 23:16:46 +00:00
//==========================================================================
//= OQueryDescriptor
//==========================================================================
2004-08-05 15:37:09 +00:00
DBG_NAME(OQueryDescriptor)
//--------------------------------------------------------------------------
OQueryDescriptor::OQueryDescriptor()
:OQueryDescriptor_Base(m_aMutex,*this)
,ODataSettings(m_aBHelper,sal_True)
{
DBG_CTOR(OQueryDescriptor,NULL);
registerProperties();
ODataSettings::registerPropertiesFor(this);
}
//--------------------------------------------------------------------------
OQueryDescriptor::OQueryDescriptor(const Reference< XPropertySet >& _rxCommandDefinition)
:OQueryDescriptor_Base(m_aMutex,*this)
,ODataSettings(m_aBHelper,sal_True)
{
DBG_CTOR(OQueryDescriptor,NULL);
registerProperties();
ODataSettings::registerPropertiesFor(this);
osl_incrementInterlockedCount(&m_refCount);
OSL_ENSURE(_rxCommandDefinition.is(), "OQueryDescriptor_Base::OQueryDescriptor_Base : invalid source property set !");
try
{
::comphelper::copyProperties(_rxCommandDefinition,this);
}
catch(Exception&)
{
OSL_ENSURE(sal_False, "OQueryDescriptor_Base::OQueryDescriptor_Base: caught an exception!");
}
osl_decrementInterlockedCount(&m_refCount);
}
//--------------------------------------------------------------------------
OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
:OQueryDescriptor_Base(_rSource,*this)
,ODataSettings(m_aBHelper,sal_True)
{
DBG_CTOR(OQueryDescriptor,NULL);
registerProperties();
ODataSettings::registerPropertiesFor(this);
}
// -----------------------------------------------------------------------------
IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
void OQueryDescriptor::registerProperties()
{
// the properties which OCommandBase supplies (it has no own registration, as it's not derived from
// a OPropertyStateContainer)
registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
2000-09-18 23:16:46 +00:00
&m_sElementName, ::getCppuType(&m_sElementName));
registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
&m_sCommand, ::getCppuType(&m_sCommand));
registerProperty(PROPERTY_USE_ESCAPE_PROCESSING, PROPERTY_ID_USE_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
&m_bEscapeProcessing, ::getBooleanCppuType());
registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
&m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
&m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
&m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
2001-02-05 07:58:23 +00:00
registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
2001-02-05 07:58:23 +00:00
&m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
2000-09-18 23:16:46 +00:00
}
// -----------------------------------------------------------------------------
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
return createPropertySetInfo( getInfoHelper() ) ;
2000-09-18 23:16:46 +00:00
}
//------------------------------------------------------------------------------
::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
{
return *getArrayHelper();
}
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
2000-09-18 23:16:46 +00:00
{
Sequence< Property > aProps;
describeProperties(aProps);
return new ::cppu::OPropertyArrayHelper(aProps);
2000-09-18 23:16:46 +00:00
}
// -----------------------------------------------------------------------------
DBG_NAME(OQueryDescriptor_Base);
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
:m_bColumnsOutOfDate(sal_True)
,m_rMutex(_rMutex)
2000-09-18 23:16:46 +00:00
{
DBG_CTOR(OQueryDescriptor_Base,NULL);
m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
}
//--------------------------------------------------------------------------
OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
:m_bColumnsOutOfDate(sal_True)
,m_rMutex(_rSource.m_rMutex)
{
DBG_CTOR(OQueryDescriptor_Base,NULL);
m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
2000-09-18 23:16:46 +00:00
m_sCommand = _rSource.m_sCommand;
m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
m_sUpdateTableName = _rSource.m_sUpdateTableName;
m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
2001-02-05 07:58:23 +00:00
m_aLayoutInformation = _rSource.m_aLayoutInformation;
2000-09-18 23:16:46 +00:00
}
//--------------------------------------------------------------------------
OQueryDescriptor_Base::~OQueryDescriptor_Base()
2000-09-18 23:16:46 +00:00
{
m_pColumns->acquire();
m_pColumns->disposing();
delete m_pColumns;
2000-09-18 23:16:46 +00:00
DBG_DTOR(OQueryDescriptor_Base,NULL);
2000-09-18 23:16:46 +00:00
}
// -----------------------------------------------------------------------------
sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
if (_rIdentifier.getLength() != 16)
2006-11-23 13:19:48 +00:00
return 0;
2000-09-18 23:16:46 +00:00
if (0 == rtl_compareMemory(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
2000-09-18 23:16:46 +00:00
return reinterpret_cast<sal_Int64>(this);
2006-11-23 13:19:48 +00:00
return 0;
2000-09-18 23:16:46 +00:00
}
2001-08-30 07:07:36 +00:00
//--------------------------------------------------------------------------
IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
2001-08-30 07:07:36 +00:00
//--------------------------------------------------------------------------
void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
2001-08-30 07:07:36 +00:00
{
m_bColumnsOutOfDate = _bOutOfDate;
if ( !m_bColumnsOutOfDate )
m_pColumns->setInitialized();
}
//--------------------------------------------------------------------------
void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
2001-08-30 07:07:36 +00:00
{
m_pColumns->append( _rName, _pColumn );
}
//--------------------------------------------------------------------------
void OQueryDescriptor_Base::clearColumns( )
2001-08-30 07:07:36 +00:00
{
m_pColumns->clearColumns();
setColumnsOutOfDate();
}
2000-09-18 23:16:46 +00:00
//--------------------------------------------------------------------------
Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard(m_rMutex);
2001-08-30 07:07:36 +00:00
if ( isColumnsOutOfDate() )
2001-08-30 07:07:36 +00:00
{
// clear the current columns
clearColumns();
2001-08-30 07:07:36 +00:00
// do this before rebuildColumns. This prevents recursion, e.g. in the case where we
// have queries with cyclic references:
// foo := SELECT * FROM bar
// bar := SELECT * FROM foo
setColumnsOutOfDate( sal_False );
// rebuild them
try
{
rebuildColumns();
}
catch(...)
{
setColumnsOutOfDate( sal_True );
throw;
}
2001-08-30 07:07:36 +00:00
}
return m_pColumns;
2000-09-18 23:16:46 +00:00
}
//--------------------------------------------------------------------------
::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
return ::rtl::OUString::createFromAscii("com.sun.star.sdb.OQueryDescriptor");
}
//--------------------------------------------------------------------------
sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
2000-10-11 10:21:40 +00:00
return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
2000-09-18 23:16:46 +00:00
}
//--------------------------------------------------------------------------
Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
2000-09-18 23:16:46 +00:00
{
Sequence< ::rtl::OUString > aSupported(2);
aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
return aSupported;
}
//--------------------------------------------------------------------------
void OQueryDescriptor_Base::disposeColumns()
2000-09-18 23:16:46 +00:00
{
2001-05-21 08:21:15 +00:00
m_pColumns->disposing();
2000-09-18 23:16:46 +00:00
}
2001-08-15 12:05:15 +00:00
// -----------------------------------------------------------------------------
void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
2001-08-15 12:05:15 +00:00
{
// not interested in
2001-08-15 12:05:15 +00:00
}
2000-09-18 23:16:46 +00:00
// -----------------------------------------------------------------------------
void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
{
// not interested in
}
// -----------------------------------------------------------------------------
Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
{
OSL_ENSURE( false, "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
return NULL;
}
2001-08-30 07:07:36 +00:00
// -----------------------------------------------------------------------------
void OQueryDescriptor_Base::rebuildColumns( )
2000-09-18 23:16:46 +00:00
{
}
2001-08-30 07:07:36 +00:00
// -----------------------------------------------------------------------------
// IRefreshableColumns
void OQueryDescriptor_Base::refreshColumns()
2000-09-18 23:16:46 +00:00
{
MutexGuard aGuard( m_rMutex );
2000-09-18 23:16:46 +00:00
2001-08-30 07:07:36 +00:00
clearColumns();
rebuildColumns();
2000-09-18 23:16:46 +00:00
}
//------------------------------------------------------------------------------
OColumn* OQueryDescriptor_Base::createColumn(const ::rtl::OUString& _rName) const
2000-09-18 23:16:46 +00:00
{
2001-08-30 07:07:36 +00:00
return new OTableColumn(_rName);
2000-09-18 23:16:46 +00:00
}
2001-08-30 07:07:36 +00:00
// -----------------------------------------------------------------------------
//........................................................................
} // namespace dbaccess
//........................................................................
2000-09-18 23:16:46 +00:00