xref: /AOO41X/main/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #include "dbastrings.hrc"
32 #include "module_dba.hxx"
33 
34 /** === begin UNO includes === **/
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/sdb/CommandType.hpp>
38 #include <com/sun/star/sdbc/XConnection.hpp>
39 #include <com/sun/star/sdbc/XResultSet.hpp>
40 #include <com/sun/star/sdb/XDataAccessDescriptorFactory.hpp>
41 /** === end UNO includes === **/
42 
43 #include <comphelper/broadcasthelper.hxx>
44 #include <comphelper/componentcontext.hxx>
45 #include <comphelper/proparrhlp.hxx>
46 #include <comphelper/propertycontainer.hxx>
47 #include <comphelper/uno3.hxx>
48 #include <cppuhelper/implbase1.hxx>
49 #include <cppuhelper/implbase2.hxx>
50 
51 //........................................................................
52 namespace dbaccess
53 {
54 //........................................................................
55 
56     /** === begin UNO using === **/
57     using ::com::sun::star::uno::Reference;
58     using ::com::sun::star::uno::XInterface;
59     using ::com::sun::star::uno::UNO_QUERY;
60     using ::com::sun::star::uno::UNO_QUERY_THROW;
61     using ::com::sun::star::uno::UNO_SET_THROW;
62     using ::com::sun::star::uno::Exception;
63     using ::com::sun::star::uno::RuntimeException;
64     using ::com::sun::star::uno::Any;
65     using ::com::sun::star::uno::makeAny;
66     using ::com::sun::star::uno::Sequence;
67     using ::com::sun::star::lang::XServiceInfo;
68     using ::com::sun::star::lang::XMultiServiceFactory;
69     using ::com::sun::star::beans::XPropertySetInfo;
70     using ::com::sun::star::beans::Property;
71     using ::com::sun::star::sdbc::XConnection;
72     using ::com::sun::star::sdbc::XResultSet;
73     using ::com::sun::star::sdb::XDataAccessDescriptorFactory;
74     using ::com::sun::star::beans::XPropertySet;
75     using ::com::sun::star::uno::XComponentContext;
76     using ::com::sun::star::beans::PropertyValue;
77     /** === end UNO using === **/
78 
79     namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
80     namespace CommandType = ::com::sun::star::sdb::CommandType;
81 
82     //====================================================================
83     //= DataAccessDescriptor
84     //====================================================================
85     typedef ::comphelper::OMutexAndBroadcastHelper  DataAccessDescriptor_MutexBase;
86 
87     typedef ::cppu::WeakImplHelper1             <   XServiceInfo
88                                                 >   DataAccessDescriptor_TypeBase;
89 
90     typedef ::comphelper::OPropertyContainer        DataAccessDescriptor_PropertyBase;
91 
92     class DataAccessDescriptor  :public DataAccessDescriptor_MutexBase
93                                 ,public DataAccessDescriptor_TypeBase
94                                 ,public DataAccessDescriptor_PropertyBase
95 		                        ,public ::comphelper::OPropertyArrayUsageHelper< DataAccessDescriptor >
96     {
97     public:
98         DataAccessDescriptor( const ::comphelper::ComponentContext& _rContext );
99 
100         // UNO
101         DECLARE_XINTERFACE()
102         DECLARE_XTYPEPROVIDER()
103 
104         // XServiceInfo
105         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
106         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException);
107         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
108 
109     protected:
110         ~DataAccessDescriptor();
111 
112     protected:
113 	    // XPropertySet
114 	    virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException);
115 	    virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
116 
117 	    // OPropertyArrayUsageHelper
118 	    virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
119 
120     private:
121         ::comphelper::ComponentContext  m_aContext;
122 
123         // </properties>
124         ::rtl::OUString             m_sDataSourceName;
125         ::rtl::OUString             m_sDatabaseLocation;
126         ::rtl::OUString             m_sConnectionResource;
127         Sequence< PropertyValue >   m_aConnectionInfo;
128         Reference< XConnection >    m_xActiveConnection;
129         ::rtl::OUString             m_sCommand;
130         sal_Int32                   m_nCommandType;
131         ::rtl::OUString             m_sFilter;
132         ::rtl::OUString             m_sOrder;
133         ::rtl::OUString             m_sHavingClause;
134         ::rtl::OUString             m_sGroupBy;
135         sal_Bool                    m_bEscapeProcessing;
136         Reference< XResultSet >     m_xResultSet;
137         Sequence< Any >             m_aSelection;
138         sal_Bool                    m_bBookmarkSelection;
139         ::rtl::OUString             m_sColumnName;
140         Reference< XPropertySet >   m_xColumn;
141         // </properties>
142     };
143 
144 #define REGISTER_PROPERTY( propname, member ) \
145     registerProperty( PROPERTY_##propname, PROPERTY_ID_##propname, PropertyAttribute::BOUND, &member, ::getCppuType( &member ) )
146 
147     //--------------------------------------------------------------------
148     DataAccessDescriptor::DataAccessDescriptor( const ::comphelper::ComponentContext& _rContext )
149         :DataAccessDescriptor_MutexBase()
150         ,DataAccessDescriptor_TypeBase()
151         ,DataAccessDescriptor_PropertyBase( m_aBHelper )
152         ,m_aContext( _rContext )
153         ,m_sDataSourceName()
154         ,m_sDatabaseLocation()
155         ,m_sConnectionResource()
156         ,m_aConnectionInfo()
157         ,m_xActiveConnection()
158         ,m_sCommand()
159         ,m_nCommandType( CommandType::COMMAND )
160         ,m_sFilter()
161         ,m_sOrder()
162         ,m_sHavingClause()
163         ,m_sGroupBy()
164         ,m_bEscapeProcessing( sal_True )
165         ,m_xResultSet()
166         ,m_aSelection()
167         ,m_bBookmarkSelection( sal_True )
168         ,m_sColumnName()
169         ,m_xColumn()
170     {
171         REGISTER_PROPERTY( DATASOURCENAME,      m_sDataSourceName );
172         REGISTER_PROPERTY( DATABASE_LOCATION,   m_sDatabaseLocation );
173         REGISTER_PROPERTY( CONNECTION_RESOURCE, m_sConnectionResource );
174         REGISTER_PROPERTY( CONNECTION_INFO,     m_aConnectionInfo );
175         REGISTER_PROPERTY( ACTIVE_CONNECTION,   m_xActiveConnection );
176         REGISTER_PROPERTY( COMMAND,             m_sCommand );
177         REGISTER_PROPERTY( COMMAND_TYPE,        m_nCommandType );
178         REGISTER_PROPERTY( FILTER,              m_sFilter );
179         REGISTER_PROPERTY( ORDER,               m_sOrder );
180         REGISTER_PROPERTY( HAVING_CLAUSE,       m_sHavingClause );
181         REGISTER_PROPERTY( GROUP_BY,            m_sGroupBy );
182         REGISTER_PROPERTY( ESCAPE_PROCESSING,   m_bEscapeProcessing );
183         REGISTER_PROPERTY( RESULT_SET,          m_xResultSet );
184         REGISTER_PROPERTY( SELECTION,           m_aSelection );
185         REGISTER_PROPERTY( BOOKMARK_SELECTION,  m_bBookmarkSelection );
186         REGISTER_PROPERTY( COLUMN_NAME,         m_sColumnName );
187         REGISTER_PROPERTY( COLUMN,              m_xColumn );
188     }
189 
190     //--------------------------------------------------------------------
191     DataAccessDescriptor::~DataAccessDescriptor()
192     {
193     }
194 
195     //--------------------------------------------------------------------
196     IMPLEMENT_FORWARD_XINTERFACE2( DataAccessDescriptor, DataAccessDescriptor_TypeBase, DataAccessDescriptor_PropertyBase );
197 
198     //--------------------------------------------------------------------
199     IMPLEMENT_FORWARD_XTYPEPROVIDER2( DataAccessDescriptor, DataAccessDescriptor_TypeBase, DataAccessDescriptor_PropertyBase );
200 
201     //--------------------------------------------------------------------
202     ::rtl::OUString SAL_CALL DataAccessDescriptor::getImplementationName() throw (RuntimeException)
203     {
204         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dba.DataAccessDescriptor" ) );
205     }
206 
207     //--------------------------------------------------------------------
208     ::sal_Bool SAL_CALL DataAccessDescriptor::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
209     {
210         Sequence< ::rtl::OUString > aServices( getSupportedServiceNames() );
211         const ::rtl::OUString* pStart = aServices.getConstArray();
212         const ::rtl::OUString* pEnd = aServices.getConstArray() + aServices.getLength();
213         return ::std::find( pStart, pEnd, rServiceName ) != pEnd;
214     }
215 
216     //--------------------------------------------------------------------
217     Sequence< ::rtl::OUString > SAL_CALL DataAccessDescriptor::getSupportedServiceNames(  ) throw (RuntimeException)
218     {
219         Sequence< ::rtl::OUString > aServices(1);
220         aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataAccessDescriptor" ) );
221         return aServices;
222     }
223 
224     //-------------------------------------------------------------------------
225     Reference< XPropertySetInfo > SAL_CALL DataAccessDescriptor::getPropertySetInfo() throw(RuntimeException)
226     {
227 	    Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
228 	    return xInfo;
229     }
230 
231     //-------------------------------------------------------------------------
232     ::cppu::IPropertyArrayHelper& DataAccessDescriptor::getInfoHelper()
233     {
234 	    return *getArrayHelper();
235     }
236 
237     //------------------------------------------------------------------------------
238     ::cppu::IPropertyArrayHelper* DataAccessDescriptor::createArrayHelper( ) const
239     {
240 	    Sequence< Property > aProps;
241 	    describeProperties( aProps );
242 	    return new ::cppu::OPropertyArrayHelper( aProps );
243     }
244 
245     //====================================================================
246     //= DataAccessDescriptorFactory
247     //====================================================================
248     typedef ::cppu::WeakImplHelper2 <   XServiceInfo
249                                     ,   XDataAccessDescriptorFactory
250                                     >   DataAccessDescriptorFactory_Base;
251     class DataAccessDescriptorFactory : public DataAccessDescriptorFactory_Base
252     {
253     public:
254         // XServiceInfo
255         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
256         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException);
257         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
258 
259         // XServiceInfo - static versions
260         static Sequence< ::rtl::OUString >  getSupportedServiceNames_static(void) throw( RuntimeException );
261         static ::rtl::OUString              getImplementationName_static(void) throw( RuntimeException );
262         static Reference< XInterface >      Create(const Reference< XComponentContext >& _rxContext);
263         static ::rtl::OUString              getSingletonName_static();
264 
265         // XDataAccessDescriptorFactory
266         virtual Reference< XPropertySet > SAL_CALL createDataAccessDescriptor(  ) throw (RuntimeException);
267 
268     protected:
269         DataAccessDescriptorFactory( const Reference< XComponentContext >& _rxContext );
270         ~DataAccessDescriptorFactory();
271 
272     private:
273         ::comphelper::ComponentContext  m_aContext;
274     };
275 
276     //--------------------------------------------------------------------
277     DataAccessDescriptorFactory::DataAccessDescriptorFactory( const Reference< XComponentContext >& _rxContext )
278         :m_aContext( _rxContext )
279     {
280     }
281 
282     //--------------------------------------------------------------------
283     DataAccessDescriptorFactory::~DataAccessDescriptorFactory()
284     {
285     }
286 
287     //--------------------------------------------------------------------
288     ::rtl::OUString DataAccessDescriptorFactory::getSingletonName_static()
289     {
290         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataAccessDescriptorFactory" ) );
291     }
292 
293     //--------------------------------------------------------------------
294     Sequence< ::rtl::OUString > DataAccessDescriptorFactory::getSupportedServiceNames_static() throw( RuntimeException )
295     {
296         Sequence< ::rtl::OUString > aServices(1);
297         aServices[0] = getSingletonName_static();
298         return aServices;
299     }
300 
301     //--------------------------------------------------------------------
302     ::rtl::OUString DataAccessDescriptorFactory::getImplementationName_static() throw( RuntimeException )
303     {
304         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dba.DataAccessDescriptorFactory" ) );
305     }
306 
307     //--------------------------------------------------------------------
308     Reference< XInterface > DataAccessDescriptorFactory::Create( const Reference< XComponentContext >& _rxContext )
309     {
310         return *( new DataAccessDescriptorFactory( _rxContext ) );
311     }
312 
313     //--------------------------------------------------------------------
314     ::rtl::OUString SAL_CALL DataAccessDescriptorFactory::getImplementationName() throw (RuntimeException)
315     {
316         return getImplementationName_static();
317     }
318 
319     //--------------------------------------------------------------------
320     ::sal_Bool SAL_CALL DataAccessDescriptorFactory::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
321     {
322         Sequence< ::rtl::OUString > aServices( getSupportedServiceNames_static() );
323         const ::rtl::OUString* pStart = aServices.getConstArray();
324         const ::rtl::OUString* pEnd = aServices.getConstArray() + aServices.getLength();
325         return ::std::find( pStart, pEnd, rServiceName ) != pEnd;
326     }
327 
328     //--------------------------------------------------------------------
329     Sequence< ::rtl::OUString > SAL_CALL DataAccessDescriptorFactory::getSupportedServiceNames(  ) throw (RuntimeException)
330     {
331         return getSupportedServiceNames_static();
332     }
333 
334     //--------------------------------------------------------------------
335     Reference< XPropertySet > SAL_CALL DataAccessDescriptorFactory::createDataAccessDescriptor(  ) throw (RuntimeException)
336     {
337         return new DataAccessDescriptor( m_aContext );
338     }
339 
340 //........................................................................
341 } // namespace dbaccess
342 //........................................................................
343 
344 //--------------------------------------------------------------------------
345 extern "C" void SAL_CALL createRegistryInfo_DataAccessDescriptorFactory()
346 {
347     static ::dba::OSingletonRegistration< ::dbaccess::DataAccessDescriptorFactory > aAutoRegistration;
348 }
349