1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*96de5490SAndrew Rist * distributed with this work for additional information
6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist * software distributed under the License is distributed on an
15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the
17*96de5490SAndrew Rist * specific language governing permissions and limitations
18*96de5490SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*96de5490SAndrew Rist *************************************************************/
21*96de5490SAndrew Rist
22*96de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef _DBA_COREAPI_QUERYDESCRIPTOR_HXX_
28cdf0e10cSrcweir #include "querydescriptor.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _DBASHARED_APITOOLS_HXX_
31cdf0e10cSrcweir #include "apitools.hxx"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
34cdf0e10cSrcweir #include "dbastrings.hrc"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _COMPHELPER_PROPERTY_HXX_
37cdf0e10cSrcweir #include <comphelper/property.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCE_HXX_
40cdf0e10cSrcweir #include <comphelper/sequence.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
43cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
46cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
49cdf0e10cSrcweir #include "definitioncolumn.hxx"
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
52cdf0e10cSrcweir #include <tools/debug.hxx>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir
55cdf0e10cSrcweir using namespace ::com::sun::star::uno;
56cdf0e10cSrcweir using namespace ::com::sun::star::awt;
57cdf0e10cSrcweir using namespace ::com::sun::star::lang;
58cdf0e10cSrcweir using namespace ::com::sun::star::beans;
59cdf0e10cSrcweir using namespace ::com::sun::star::container;
60cdf0e10cSrcweir using namespace ::com::sun::star::util;
61cdf0e10cSrcweir using namespace ::comphelper;
62cdf0e10cSrcweir using namespace ::osl;
63cdf0e10cSrcweir using namespace ::cppu;
64cdf0e10cSrcweir
65cdf0e10cSrcweir //........................................................................
66cdf0e10cSrcweir namespace dbaccess
67cdf0e10cSrcweir {
68cdf0e10cSrcweir //........................................................................
69cdf0e10cSrcweir
70cdf0e10cSrcweir //==========================================================================
71cdf0e10cSrcweir //= OQueryDescriptor
72cdf0e10cSrcweir //==========================================================================
DBG_NAME(OQueryDescriptor)73cdf0e10cSrcweir DBG_NAME(OQueryDescriptor)
74cdf0e10cSrcweir //--------------------------------------------------------------------------
75cdf0e10cSrcweir OQueryDescriptor::OQueryDescriptor()
76cdf0e10cSrcweir :OQueryDescriptor_Base(m_aMutex,*this)
77cdf0e10cSrcweir ,ODataSettings(m_aBHelper,sal_True)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir DBG_CTOR(OQueryDescriptor,NULL);
80cdf0e10cSrcweir registerProperties();
81cdf0e10cSrcweir ODataSettings::registerPropertiesFor(this);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir //--------------------------------------------------------------------------
OQueryDescriptor(const OQueryDescriptor_Base & _rSource)85cdf0e10cSrcweir OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
86cdf0e10cSrcweir :OQueryDescriptor_Base(_rSource,*this)
87cdf0e10cSrcweir ,ODataSettings(m_aBHelper,sal_True)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir DBG_CTOR(OQueryDescriptor,NULL);
90cdf0e10cSrcweir registerProperties();
91cdf0e10cSrcweir ODataSettings::registerPropertiesFor(this);
92cdf0e10cSrcweir }
93cdf0e10cSrcweir // -----------------------------------------------------------------------------
~OQueryDescriptor()94cdf0e10cSrcweir OQueryDescriptor::~OQueryDescriptor()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir DBG_DTOR(OQueryDescriptor,NULL);
97cdf0e10cSrcweir }
98cdf0e10cSrcweir // -----------------------------------------------------------------------------
99cdf0e10cSrcweir IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
IMPLEMENT_FORWARD_XINTERFACE3(OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)100cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
101cdf0e10cSrcweir //--------------------------------------------------------------------------
102cdf0e10cSrcweir void OQueryDescriptor::registerProperties()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
105cdf0e10cSrcweir // a OPropertyStateContainer)
106cdf0e10cSrcweir registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
107cdf0e10cSrcweir &m_sElementName, ::getCppuType(&m_sElementName));
108cdf0e10cSrcweir
109cdf0e10cSrcweir registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
110cdf0e10cSrcweir &m_sCommand, ::getCppuType(&m_sCommand));
111cdf0e10cSrcweir
112cdf0e10cSrcweir registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
113cdf0e10cSrcweir &m_bEscapeProcessing, ::getBooleanCppuType());
114cdf0e10cSrcweir
115cdf0e10cSrcweir registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
116cdf0e10cSrcweir &m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
117cdf0e10cSrcweir
118cdf0e10cSrcweir registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
119cdf0e10cSrcweir &m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
120cdf0e10cSrcweir
121cdf0e10cSrcweir registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
122cdf0e10cSrcweir &m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
123cdf0e10cSrcweir
124cdf0e10cSrcweir registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
125cdf0e10cSrcweir &m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
126cdf0e10cSrcweir }
127cdf0e10cSrcweir // -----------------------------------------------------------------------------
128cdf0e10cSrcweir //--------------------------------------------------------------------------
getPropertySetInfo()129cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir return createPropertySetInfo( getInfoHelper() ) ;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir //------------------------------------------------------------------------------
getInfoHelper()135cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir return *getArrayHelper();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir //--------------------------------------------------------------------------
createArrayHelper() const140cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
141cdf0e10cSrcweir {
142cdf0e10cSrcweir Sequence< Property > aProps;
143cdf0e10cSrcweir describeProperties(aProps);
144cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper(aProps);
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir // -----------------------------------------------------------------------------
148cdf0e10cSrcweir DBG_NAME(OQueryDescriptor_Base);
149cdf0e10cSrcweir //--------------------------------------------------------------------------
OQueryDescriptor_Base(::osl::Mutex & _rMutex,::cppu::OWeakObject & _rMySelf)150cdf0e10cSrcweir OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
151cdf0e10cSrcweir :m_bColumnsOutOfDate(sal_True)
152cdf0e10cSrcweir ,m_rMutex(_rMutex)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir DBG_CTOR(OQueryDescriptor_Base,NULL);
155cdf0e10cSrcweir m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
156cdf0e10cSrcweir }
157cdf0e10cSrcweir //--------------------------------------------------------------------------
OQueryDescriptor_Base(const OQueryDescriptor_Base & _rSource,::cppu::OWeakObject & _rMySelf)158cdf0e10cSrcweir OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
159cdf0e10cSrcweir :m_bColumnsOutOfDate(sal_True)
160cdf0e10cSrcweir ,m_rMutex(_rSource.m_rMutex)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir DBG_CTOR(OQueryDescriptor_Base,NULL);
163cdf0e10cSrcweir m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
164cdf0e10cSrcweir
165cdf0e10cSrcweir m_sCommand = _rSource.m_sCommand;
166cdf0e10cSrcweir m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
167cdf0e10cSrcweir m_sUpdateTableName = _rSource.m_sUpdateTableName;
168cdf0e10cSrcweir m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
169cdf0e10cSrcweir m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
170cdf0e10cSrcweir m_aLayoutInformation = _rSource.m_aLayoutInformation;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir //--------------------------------------------------------------------------
~OQueryDescriptor_Base()174cdf0e10cSrcweir OQueryDescriptor_Base::~OQueryDescriptor_Base()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir m_pColumns->acquire();
177cdf0e10cSrcweir m_pColumns->disposing();
178cdf0e10cSrcweir delete m_pColumns;
179cdf0e10cSrcweir
180cdf0e10cSrcweir DBG_DTOR(OQueryDescriptor_Base,NULL);
181cdf0e10cSrcweir }
182cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & _rIdentifier)183cdf0e10cSrcweir sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir if (_rIdentifier.getLength() != 16)
186cdf0e10cSrcweir return 0;
187cdf0e10cSrcweir
188cdf0e10cSrcweir if (0 == rtl_compareMemory(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
189cdf0e10cSrcweir return reinterpret_cast<sal_Int64>(this);
190cdf0e10cSrcweir
191cdf0e10cSrcweir return 0;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir //--------------------------------------------------------------------------
IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)194cdf0e10cSrcweir IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
195cdf0e10cSrcweir //--------------------------------------------------------------------------
196cdf0e10cSrcweir void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir m_bColumnsOutOfDate = _bOutOfDate;
199cdf0e10cSrcweir if ( !m_bColumnsOutOfDate )
200cdf0e10cSrcweir m_pColumns->setInitialized();
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir //--------------------------------------------------------------------------
implAppendColumn(const::rtl::OUString & _rName,OColumn * _pColumn)204cdf0e10cSrcweir void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir m_pColumns->append( _rName, _pColumn );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir //--------------------------------------------------------------------------
clearColumns()210cdf0e10cSrcweir void OQueryDescriptor_Base::clearColumns( )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir m_pColumns->clearColumns();
213cdf0e10cSrcweir
214cdf0e10cSrcweir setColumnsOutOfDate();
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
217cdf0e10cSrcweir //--------------------------------------------------------------------------
getColumns()218cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir MutexGuard aGuard(m_rMutex);
221cdf0e10cSrcweir
222cdf0e10cSrcweir if ( isColumnsOutOfDate() )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir // clear the current columns
225cdf0e10cSrcweir clearColumns();
226cdf0e10cSrcweir
227cdf0e10cSrcweir // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
228cdf0e10cSrcweir // have queries with cyclic references:
229cdf0e10cSrcweir // foo := SELECT * FROM bar
230cdf0e10cSrcweir // bar := SELECT * FROM foo
231cdf0e10cSrcweir setColumnsOutOfDate( sal_False );
232cdf0e10cSrcweir
233cdf0e10cSrcweir // rebuild them
234cdf0e10cSrcweir try
235cdf0e10cSrcweir {
236cdf0e10cSrcweir rebuildColumns();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir catch ( const Exception& )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir setColumnsOutOfDate( sal_True );
241cdf0e10cSrcweir throw;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir return m_pColumns;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir //--------------------------------------------------------------------------
getImplementationName()249cdf0e10cSrcweir ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.sdb.OQueryDescriptor");
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir //--------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)255cdf0e10cSrcweir sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir //--------------------------------------------------------------------------
getSupportedServiceNames()261cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(2);
264cdf0e10cSrcweir aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
265cdf0e10cSrcweir aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
266cdf0e10cSrcweir return aSupported;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir //--------------------------------------------------------------------------
disposeColumns()269cdf0e10cSrcweir void OQueryDescriptor_Base::disposeColumns()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir m_pColumns->disposing();
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir // -----------------------------------------------------------------------------
columnAppended(const Reference<XPropertySet> &)275cdf0e10cSrcweir void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
276cdf0e10cSrcweir {
277cdf0e10cSrcweir // not interested in
278cdf0e10cSrcweir }
279cdf0e10cSrcweir
280cdf0e10cSrcweir // -----------------------------------------------------------------------------
columnDropped(const::rtl::OUString &)281cdf0e10cSrcweir void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir // not interested in
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir // -----------------------------------------------------------------------------
createColumnDescriptor()287cdf0e10cSrcweir Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
288cdf0e10cSrcweir {
289cdf0e10cSrcweir OSL_ENSURE( false, "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
290cdf0e10cSrcweir return NULL;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir // -----------------------------------------------------------------------------
rebuildColumns()294cdf0e10cSrcweir void OQueryDescriptor_Base::rebuildColumns( )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir // -----------------------------------------------------------------------------
299cdf0e10cSrcweir // IRefreshableColumns
refreshColumns()300cdf0e10cSrcweir void OQueryDescriptor_Base::refreshColumns()
301cdf0e10cSrcweir {
302cdf0e10cSrcweir MutexGuard aGuard( m_rMutex );
303cdf0e10cSrcweir
304cdf0e10cSrcweir clearColumns();
305cdf0e10cSrcweir rebuildColumns();
306cdf0e10cSrcweir }
307cdf0e10cSrcweir
308cdf0e10cSrcweir //------------------------------------------------------------------------------
createColumn(const::rtl::OUString &) const309cdf0e10cSrcweir OColumn* OQueryDescriptor_Base::createColumn( const ::rtl::OUString& /*_rName*/ ) const
310cdf0e10cSrcweir {
311cdf0e10cSrcweir // creating a column/descriptor for a query/descriptor does not make sense at all
312cdf0e10cSrcweir return NULL;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir // -----------------------------------------------------------------------------
315cdf0e10cSrcweir //........................................................................
316cdf0e10cSrcweir } // namespace dbaccess
317cdf0e10cSrcweir //........................................................................
318cdf0e10cSrcweir
319cdf0e10cSrcweir
320