1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "querydescriptor.hxx"
23 #include "apitools.hxx"
24 #include "dbastrings.hrc"
25 #include <comphelper/property.hxx>
26 #include <comphelper/sequence.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include "definitioncolumn.hxx"
31 #include <tools/debug.hxx>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::awt
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::util
;
39 using namespace ::comphelper
;
40 using namespace ::osl
;
41 using namespace ::cppu
;
48 OQueryDescriptor::OQueryDescriptor()
49 :OQueryDescriptor_Base(m_aMutex
,*this)
50 ,ODataSettings(m_aBHelper
,true)
53 ODataSettings::registerPropertiesFor(this);
56 OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base
& _rSource
)
57 :OQueryDescriptor_Base(_rSource
,*this)
58 ,ODataSettings(m_aBHelper
,true)
61 ODataSettings::registerPropertiesFor(this);
64 OQueryDescriptor::~OQueryDescriptor()
68 css::uno::Sequence
<sal_Int8
> OQueryDescriptor::getImplementationId()
69 throw (css::uno::RuntimeException
, std::exception
)
71 return css::uno::Sequence
<sal_Int8
>();
74 IMPLEMENT_GETTYPES2(OQueryDescriptor
,OQueryDescriptor_Base
,ODataSettings
);
75 IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor
,OWeakObject
,OQueryDescriptor_Base
,ODataSettings
)
77 void OQueryDescriptor::registerProperties()
79 // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
80 // a OPropertyStateContainer)
81 registerProperty(PROPERTY_NAME
, PROPERTY_ID_NAME
, PropertyAttribute::BOUND
|PropertyAttribute::CONSTRAINED
,
82 &m_sElementName
, cppu::UnoType
<decltype(m_sElementName
)>::get());
84 registerProperty(PROPERTY_COMMAND
, PROPERTY_ID_COMMAND
, PropertyAttribute::BOUND
,
85 &m_sCommand
, cppu::UnoType
<decltype(m_sCommand
)>::get());
87 registerProperty(PROPERTY_ESCAPE_PROCESSING
, PROPERTY_ID_ESCAPE_PROCESSING
, PropertyAttribute::BOUND
,
88 &m_bEscapeProcessing
, cppu::UnoType
<bool>::get());
90 registerProperty(PROPERTY_UPDATE_TABLENAME
, PROPERTY_ID_UPDATE_TABLENAME
, PropertyAttribute::BOUND
,
91 &m_sUpdateTableName
, cppu::UnoType
<decltype(m_sUpdateTableName
)>::get());
93 registerProperty(PROPERTY_UPDATE_SCHEMANAME
, PROPERTY_ID_UPDATE_SCHEMANAME
, PropertyAttribute::BOUND
,
94 &m_sUpdateSchemaName
, cppu::UnoType
<decltype(m_sUpdateSchemaName
)>::get());
96 registerProperty(PROPERTY_UPDATE_CATALOGNAME
, PROPERTY_ID_UPDATE_CATALOGNAME
, PropertyAttribute::BOUND
,
97 &m_sUpdateCatalogName
, cppu::UnoType
<decltype(m_sUpdateCatalogName
)>::get());
99 registerProperty(PROPERTY_LAYOUTINFORMATION
, PROPERTY_ID_LAYOUTINFORMATION
, PropertyAttribute::BOUND
,
100 &m_aLayoutInformation
, cppu::UnoType
<decltype(m_aLayoutInformation
)>::get());
103 Reference
< XPropertySetInfo
> SAL_CALL
OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
105 return createPropertySetInfo( getInfoHelper() ) ;
108 ::cppu::IPropertyArrayHelper
& OQueryDescriptor::getInfoHelper()
110 return *getArrayHelper();
113 ::cppu::IPropertyArrayHelper
* OQueryDescriptor::createArrayHelper( ) const
115 Sequence
< Property
> aProps
;
116 describeProperties(aProps
);
117 return new ::cppu::OPropertyArrayHelper(aProps
);
121 OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex
& _rMutex
,::cppu::OWeakObject
& _rMySelf
)
122 :m_bColumnsOutOfDate(true)
125 m_pColumns
= new OColumns(_rMySelf
, m_rMutex
, true,::std::vector
< OUString
>(), this,this);
128 OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base
& _rSource
,::cppu::OWeakObject
& _rMySelf
)
129 :m_bColumnsOutOfDate(true)
130 ,m_rMutex(_rSource
.m_rMutex
)
132 m_pColumns
= new OColumns(_rMySelf
, m_rMutex
, true,::std::vector
< OUString
>(), this,this);
134 m_sCommand
= _rSource
.m_sCommand
;
135 m_bEscapeProcessing
= _rSource
.m_bEscapeProcessing
;
136 m_sUpdateTableName
= _rSource
.m_sUpdateTableName
;
137 m_sUpdateSchemaName
= _rSource
.m_sUpdateSchemaName
;
138 m_sUpdateCatalogName
= _rSource
.m_sUpdateCatalogName
;
139 m_aLayoutInformation
= _rSource
.m_aLayoutInformation
;
142 OQueryDescriptor_Base::~OQueryDescriptor_Base()
144 m_pColumns
->acquire();
145 m_pColumns
->disposing();
150 sal_Int64 SAL_CALL
OQueryDescriptor_Base::getSomething( const Sequence
< sal_Int8
>& _rIdentifier
) throw(RuntimeException
, std::exception
)
152 if (_rIdentifier
.getLength() != 16)
155 if (0 == memcmp(getUnoTunnelImplementationId().getConstArray(), _rIdentifier
.getConstArray(), 16 ) )
156 return reinterpret_cast<sal_Int64
>(this);
161 IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base
)
163 void OQueryDescriptor_Base::setColumnsOutOfDate( bool _bOutOfDate
)
165 m_bColumnsOutOfDate
= _bOutOfDate
;
166 if ( !m_bColumnsOutOfDate
)
167 m_pColumns
->setInitialized();
170 void OQueryDescriptor_Base::implAppendColumn( const OUString
& _rName
, OColumn
* _pColumn
)
172 m_pColumns
->append( _rName
, _pColumn
);
175 void OQueryDescriptor_Base::clearColumns( )
177 m_pColumns
->clearColumns();
179 setColumnsOutOfDate();
182 Reference
< XNameAccess
> SAL_CALL
OQueryDescriptor_Base::getColumns( ) throw (RuntimeException
, std::exception
)
184 MutexGuard
aGuard(m_rMutex
);
186 if ( isColumnsOutOfDate() )
188 // clear the current columns
191 // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
192 // have queries with cyclic references:
193 // foo := SELECT * FROM bar
194 // bar := SELECT * FROM foo
195 setColumnsOutOfDate( false );
202 catch ( const Exception
& )
204 setColumnsOutOfDate( true );
212 OUString SAL_CALL
OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException
, std::exception
)
214 return OUString("com.sun.star.sdb.OQueryDescriptor");
217 sal_Bool SAL_CALL
OQueryDescriptor_Base::supportsService( const OUString
& _rServiceName
) throw(RuntimeException
, std::exception
)
219 return cppu::supportsService(this, _rServiceName
);
222 Sequence
< OUString
> SAL_CALL
OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException
, std::exception
)
224 Sequence
< OUString
> aSupported(2);
225 aSupported
.getArray()[0] = SERVICE_SDB_DATASETTINGS
;
226 aSupported
.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR
;
230 void OQueryDescriptor_Base::disposeColumns()
232 m_pColumns
->disposing();
235 void OQueryDescriptor_Base::columnAppended( const Reference
< XPropertySet
>& /*_rxSourceDescriptor*/ )
240 void OQueryDescriptor_Base::columnDropped(const OUString
& /*_sName*/)
245 Reference
< XPropertySet
> OQueryDescriptor_Base::createColumnDescriptor()
247 OSL_FAIL( "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
251 void OQueryDescriptor_Base::rebuildColumns( )
255 // IRefreshableColumns
256 void OQueryDescriptor_Base::refreshColumns()
258 MutexGuard
aGuard( m_rMutex
);
264 OColumn
* OQueryDescriptor_Base::createColumn( const OUString
& /*_rName*/ ) const
266 // creating a column/descriptor for a query/descriptor does not make sense at all
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */