Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / api / querydescriptor.cxx
blob8b6db104e3c3f0296d6bfcf3752d4409159ae18d
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 <string.h>
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/typeprovider.hxx>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include "definitioncolumn.hxx"
30 #include <tools/debug.hxx>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::awt;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::util;
38 using namespace ::comphelper;
39 using namespace ::osl;
40 using namespace ::cppu;
42 namespace dbaccess
45 //==========================================================================
46 //= OQueryDescriptor
47 //==========================================================================
48 DBG_NAME(OQueryDescriptor)
50 OQueryDescriptor::OQueryDescriptor()
51 :OQueryDescriptor_Base(m_aMutex,*this)
52 ,ODataSettings(m_aBHelper,sal_True)
54 DBG_CTOR(OQueryDescriptor,NULL);
55 registerProperties();
56 ODataSettings::registerPropertiesFor(this);
59 OQueryDescriptor::OQueryDescriptor(const OQueryDescriptor_Base& _rSource)
60 :OQueryDescriptor_Base(_rSource,*this)
61 ,ODataSettings(m_aBHelper,sal_True)
63 DBG_CTOR(OQueryDescriptor,NULL);
64 registerProperties();
65 ODataSettings::registerPropertiesFor(this);
68 OQueryDescriptor::~OQueryDescriptor()
70 DBG_DTOR(OQueryDescriptor,NULL);
73 IMPLEMENT_TYPEPROVIDER2(OQueryDescriptor,OQueryDescriptor_Base,ODataSettings);
74 IMPLEMENT_FORWARD_XINTERFACE3( OQueryDescriptor,OWeakObject,OQueryDescriptor_Base,ODataSettings)
76 void OQueryDescriptor::registerProperties()
78 // the properties which OCommandBase supplies (it has no own registration, as it's not derived from
79 // a OPropertyStateContainer)
80 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND|PropertyAttribute::CONSTRAINED,
81 &m_sElementName, ::getCppuType(&m_sElementName));
83 registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND,
84 &m_sCommand, ::getCppuType(&m_sCommand));
86 registerProperty(PROPERTY_ESCAPE_PROCESSING, PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND,
87 &m_bEscapeProcessing, ::getBooleanCppuType());
89 registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND,
90 &m_sUpdateTableName, ::getCppuType(&m_sUpdateTableName));
92 registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND,
93 &m_sUpdateSchemaName, ::getCppuType(&m_sUpdateSchemaName));
95 registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND,
96 &m_sUpdateCatalogName, ::getCppuType(&m_sUpdateCatalogName));
98 registerProperty(PROPERTY_LAYOUTINFORMATION, PROPERTY_ID_LAYOUTINFORMATION, PropertyAttribute::BOUND,
99 &m_aLayoutInformation, ::getCppuType(&m_aLayoutInformation));
102 Reference< XPropertySetInfo > SAL_CALL OQueryDescriptor::getPropertySetInfo( ) throw(RuntimeException)
104 return createPropertySetInfo( getInfoHelper() ) ;
107 ::cppu::IPropertyArrayHelper& OQueryDescriptor::getInfoHelper()
109 return *getArrayHelper();
112 ::cppu::IPropertyArrayHelper* OQueryDescriptor::createArrayHelper( ) const
114 Sequence< Property > aProps;
115 describeProperties(aProps);
116 return new ::cppu::OPropertyArrayHelper(aProps);
119 DBG_NAME(OQueryDescriptor_Base);
121 OQueryDescriptor_Base::OQueryDescriptor_Base(::osl::Mutex& _rMutex,::cppu::OWeakObject& _rMySelf)
122 :m_bColumnsOutOfDate(sal_True)
123 ,m_rMutex(_rMutex)
125 DBG_CTOR(OQueryDescriptor_Base,NULL);
126 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
129 OQueryDescriptor_Base::OQueryDescriptor_Base(const OQueryDescriptor_Base& _rSource,::cppu::OWeakObject& _rMySelf)
130 :m_bColumnsOutOfDate(sal_True)
131 ,m_rMutex(_rSource.m_rMutex)
133 DBG_CTOR(OQueryDescriptor_Base,NULL);
134 m_pColumns = new OColumns(_rMySelf, m_rMutex, sal_True,::std::vector< ::rtl::OUString>(), this,this);
136 m_sCommand = _rSource.m_sCommand;
137 m_bEscapeProcessing = _rSource.m_bEscapeProcessing;
138 m_sUpdateTableName = _rSource.m_sUpdateTableName;
139 m_sUpdateSchemaName = _rSource.m_sUpdateSchemaName;
140 m_sUpdateCatalogName = _rSource.m_sUpdateCatalogName;
141 m_aLayoutInformation = _rSource.m_aLayoutInformation;
144 OQueryDescriptor_Base::~OQueryDescriptor_Base()
146 m_pColumns->acquire();
147 m_pColumns->disposing();
148 delete m_pColumns;
150 DBG_DTOR(OQueryDescriptor_Base,NULL);
153 sal_Int64 SAL_CALL OQueryDescriptor_Base::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
155 if (_rIdentifier.getLength() != 16)
156 return 0;
158 if (0 == memcmp(getImplementationId().getConstArray(), _rIdentifier.getConstArray(), 16 ) )
159 return reinterpret_cast<sal_Int64>(this);
161 return 0;
164 IMPLEMENT_IMPLEMENTATION_ID(OQueryDescriptor_Base)
166 void OQueryDescriptor_Base::setColumnsOutOfDate( sal_Bool _bOutOfDate )
168 m_bColumnsOutOfDate = _bOutOfDate;
169 if ( !m_bColumnsOutOfDate )
170 m_pColumns->setInitialized();
173 void OQueryDescriptor_Base::implAppendColumn( const ::rtl::OUString& _rName, OColumn* _pColumn )
175 m_pColumns->append( _rName, _pColumn );
178 void OQueryDescriptor_Base::clearColumns( )
180 m_pColumns->clearColumns();
182 setColumnsOutOfDate();
185 Reference< XNameAccess > SAL_CALL OQueryDescriptor_Base::getColumns( ) throw (RuntimeException)
187 MutexGuard aGuard(m_rMutex);
189 if ( isColumnsOutOfDate() )
191 // clear the current columns
192 clearColumns();
194 // do this before rebuildColumns. This prevents recursion, e.g. in the case where we
195 // have queries with cyclic references:
196 // foo := SELECT * FROM bar
197 // bar := SELECT * FROM foo
198 setColumnsOutOfDate( sal_False );
200 // rebuild them
203 rebuildColumns();
205 catch ( const Exception& )
207 setColumnsOutOfDate( sal_True );
208 throw;
212 return m_pColumns;
215 ::rtl::OUString SAL_CALL OQueryDescriptor_Base::getImplementationName( ) throw(RuntimeException)
217 return ::rtl::OUString("com.sun.star.sdb.OQueryDescriptor");
220 sal_Bool SAL_CALL OQueryDescriptor_Base::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
222 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
225 Sequence< ::rtl::OUString > SAL_CALL OQueryDescriptor_Base::getSupportedServiceNames( ) throw(RuntimeException)
227 Sequence< ::rtl::OUString > aSupported(2);
228 aSupported.getArray()[0] = SERVICE_SDB_DATASETTINGS;
229 aSupported.getArray()[1] = SERVICE_SDB_QUERYDESCRIPTOR;
230 return aSupported;
233 void OQueryDescriptor_Base::disposeColumns()
235 m_pColumns->disposing();
238 void OQueryDescriptor_Base::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
240 // not interested in
243 void OQueryDescriptor_Base::columnDropped(const ::rtl::OUString& /*_sName*/)
245 // not interested in
248 Reference< XPropertySet > OQueryDescriptor_Base::createColumnDescriptor()
250 OSL_FAIL( "OQueryDescriptor_Base::createColumnDescriptor: called why?" );
251 return NULL;
254 void OQueryDescriptor_Base::rebuildColumns( )
258 // IRefreshableColumns
259 void OQueryDescriptor_Base::refreshColumns()
261 MutexGuard aGuard( m_rMutex );
263 clearColumns();
264 rebuildColumns();
267 OColumn* OQueryDescriptor_Base::createColumn( const ::rtl::OUString& /*_rName*/ ) const
269 // creating a column/descriptor for a query/descriptor does not make sense at all
270 return NULL;
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */