Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "dbastrings.hrc"
21 : #include "module_dba.hxx"
22 :
23 : #include <com/sun/star/lang/XServiceInfo.hpp>
24 : #include <com/sun/star/beans/PropertyAttribute.hpp>
25 : #include <com/sun/star/beans/PropertyValue.hpp>
26 : #include <com/sun/star/sdb/CommandType.hpp>
27 : #include <com/sun/star/sdbc/XConnection.hpp>
28 : #include <com/sun/star/sdbc/XResultSet.hpp>
29 : #include <com/sun/star/sdb/XDataAccessDescriptorFactory.hpp>
30 :
31 : #include <comphelper/broadcasthelper.hxx>
32 : #include <comphelper/proparrhlp.hxx>
33 : #include <comphelper/propertycontainer.hxx>
34 : #include <comphelper/uno3.hxx>
35 : #include <cppuhelper/implbase1.hxx>
36 : #include <cppuhelper/implbase2.hxx>
37 : #include <cppuhelper/supportsservice.hxx>
38 :
39 : namespace dbaccess
40 : {
41 :
42 : using ::com::sun::star::uno::Reference;
43 : using ::com::sun::star::uno::XInterface;
44 : using ::com::sun::star::uno::UNO_QUERY;
45 : using ::com::sun::star::uno::UNO_QUERY_THROW;
46 : using ::com::sun::star::uno::UNO_SET_THROW;
47 : using ::com::sun::star::uno::Exception;
48 : using ::com::sun::star::uno::RuntimeException;
49 : using ::com::sun::star::uno::Any;
50 : using ::com::sun::star::uno::makeAny;
51 : using ::com::sun::star::uno::Sequence;
52 : using ::com::sun::star::lang::XServiceInfo;
53 : using ::com::sun::star::lang::XMultiServiceFactory;
54 : using ::com::sun::star::beans::XPropertySetInfo;
55 : using ::com::sun::star::beans::Property;
56 : using ::com::sun::star::sdbc::XConnection;
57 : using ::com::sun::star::sdbc::XResultSet;
58 : using ::com::sun::star::sdb::XDataAccessDescriptorFactory;
59 : using ::com::sun::star::beans::XPropertySet;
60 : using ::com::sun::star::uno::XComponentContext;
61 : using ::com::sun::star::beans::PropertyValue;
62 :
63 : namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
64 : namespace CommandType = ::com::sun::star::sdb::CommandType;
65 :
66 : // DataAccessDescriptor
67 : typedef ::comphelper::OMutexAndBroadcastHelper DataAccessDescriptor_MutexBase;
68 :
69 : typedef ::cppu::WeakImplHelper1 < XServiceInfo
70 : > DataAccessDescriptor_TypeBase;
71 :
72 : typedef ::comphelper::OPropertyContainer DataAccessDescriptor_PropertyBase;
73 :
74 : class DataAccessDescriptor :public DataAccessDescriptor_MutexBase
75 : ,public DataAccessDescriptor_TypeBase
76 : ,public DataAccessDescriptor_PropertyBase
77 : ,public ::comphelper::OPropertyArrayUsageHelper< DataAccessDescriptor >
78 : {
79 : public:
80 : DataAccessDescriptor( const Reference<XComponentContext> & _rContext );
81 :
82 : // UNO
83 : DECLARE_XINTERFACE()
84 : DECLARE_XTYPEPROVIDER()
85 :
86 : // XServiceInfo
87 : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
88 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
89 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
90 :
91 : protected:
92 : virtual ~DataAccessDescriptor();
93 :
94 : protected:
95 : // XPropertySet
96 : virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException, std::exception) SAL_OVERRIDE;
97 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;
98 :
99 : // OPropertyArrayUsageHelper
100 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE;
101 :
102 : private:
103 : Reference<XComponentContext> m_xContext;
104 :
105 : // </properties>
106 : OUString m_sDataSourceName;
107 : OUString m_sDatabaseLocation;
108 : OUString m_sConnectionResource;
109 : Sequence< PropertyValue > m_aConnectionInfo;
110 : Reference< XConnection > m_xActiveConnection;
111 : OUString m_sCommand;
112 : sal_Int32 m_nCommandType;
113 : OUString m_sFilter;
114 : OUString m_sOrder;
115 : OUString m_sHavingClause;
116 : OUString m_sGroupBy;
117 : sal_Bool m_bEscapeProcessing;
118 : Reference< XResultSet > m_xResultSet;
119 : Sequence< Any > m_aSelection;
120 : sal_Bool m_bBookmarkSelection;
121 : OUString m_sColumnName;
122 : Reference< XPropertySet > m_xColumn;
123 : // </properties>
124 : };
125 :
126 : #define REGISTER_PROPERTY( propname, member ) \
127 : registerProperty( PROPERTY_##propname, PROPERTY_ID_##propname, PropertyAttribute::BOUND, &member, ::getCppuType( &member ) )
128 :
129 0 : DataAccessDescriptor::DataAccessDescriptor( const Reference<XComponentContext> & _rContext )
130 : :DataAccessDescriptor_MutexBase()
131 : ,DataAccessDescriptor_TypeBase()
132 : ,DataAccessDescriptor_PropertyBase( m_aBHelper )
133 : ,m_xContext( _rContext )
134 : ,m_sDataSourceName()
135 : ,m_sDatabaseLocation()
136 : ,m_sConnectionResource()
137 : ,m_aConnectionInfo()
138 : ,m_xActiveConnection()
139 : ,m_sCommand()
140 : ,m_nCommandType( CommandType::COMMAND )
141 : ,m_sFilter()
142 : ,m_sOrder()
143 : ,m_sHavingClause()
144 : ,m_sGroupBy()
145 : ,m_bEscapeProcessing( sal_True )
146 : ,m_xResultSet()
147 : ,m_aSelection()
148 : ,m_bBookmarkSelection( sal_True )
149 : ,m_sColumnName()
150 0 : ,m_xColumn()
151 : {
152 0 : REGISTER_PROPERTY( DATASOURCENAME, m_sDataSourceName );
153 0 : REGISTER_PROPERTY( DATABASE_LOCATION, m_sDatabaseLocation );
154 0 : REGISTER_PROPERTY( CONNECTION_RESOURCE, m_sConnectionResource );
155 0 : REGISTER_PROPERTY( CONNECTION_INFO, m_aConnectionInfo );
156 0 : REGISTER_PROPERTY( ACTIVE_CONNECTION, m_xActiveConnection );
157 0 : REGISTER_PROPERTY( COMMAND, m_sCommand );
158 0 : REGISTER_PROPERTY( COMMAND_TYPE, m_nCommandType );
159 0 : REGISTER_PROPERTY( FILTER, m_sFilter );
160 0 : REGISTER_PROPERTY( ORDER, m_sOrder );
161 0 : REGISTER_PROPERTY( HAVING_CLAUSE, m_sHavingClause );
162 0 : REGISTER_PROPERTY( GROUP_BY, m_sGroupBy );
163 0 : REGISTER_PROPERTY( ESCAPE_PROCESSING, m_bEscapeProcessing );
164 0 : REGISTER_PROPERTY( RESULT_SET, m_xResultSet );
165 0 : REGISTER_PROPERTY( SELECTION, m_aSelection );
166 0 : REGISTER_PROPERTY( BOOKMARK_SELECTION, m_bBookmarkSelection );
167 0 : REGISTER_PROPERTY( COLUMN_NAME, m_sColumnName );
168 0 : REGISTER_PROPERTY( COLUMN, m_xColumn );
169 0 : }
170 :
171 0 : DataAccessDescriptor::~DataAccessDescriptor()
172 : {
173 0 : }
174 :
175 0 : IMPLEMENT_FORWARD_XINTERFACE2( DataAccessDescriptor, DataAccessDescriptor_TypeBase, DataAccessDescriptor_PropertyBase );
176 :
177 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( DataAccessDescriptor, DataAccessDescriptor_TypeBase, DataAccessDescriptor_PropertyBase );
178 :
179 0 : OUString SAL_CALL DataAccessDescriptor::getImplementationName() throw (RuntimeException, std::exception)
180 : {
181 0 : return OUString( "com.sun.star.comp.dba.DataAccessDescriptor" );
182 : }
183 :
184 0 : sal_Bool SAL_CALL DataAccessDescriptor::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
185 : {
186 0 : return cppu::supportsService(this, rServiceName);
187 : }
188 :
189 0 : Sequence< OUString > SAL_CALL DataAccessDescriptor::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
190 : {
191 0 : Sequence< OUString > aServices(1);
192 0 : aServices[0] = "com.sun.star.sdb.DataAccessDescriptor";
193 0 : return aServices;
194 : }
195 :
196 0 : Reference< XPropertySetInfo > SAL_CALL DataAccessDescriptor::getPropertySetInfo() throw(RuntimeException, std::exception)
197 : {
198 0 : Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
199 0 : return xInfo;
200 : }
201 :
202 0 : ::cppu::IPropertyArrayHelper& DataAccessDescriptor::getInfoHelper()
203 : {
204 0 : return *getArrayHelper();
205 : }
206 :
207 0 : ::cppu::IPropertyArrayHelper* DataAccessDescriptor::createArrayHelper( ) const
208 : {
209 0 : Sequence< Property > aProps;
210 0 : describeProperties( aProps );
211 0 : return new ::cppu::OPropertyArrayHelper( aProps );
212 : }
213 :
214 : // DataAccessDescriptorFactory
215 : typedef ::cppu::WeakImplHelper2 < XServiceInfo
216 : , XDataAccessDescriptorFactory
217 : > DataAccessDescriptorFactory_Base;
218 : class DataAccessDescriptorFactory : public DataAccessDescriptorFactory_Base
219 : {
220 : public:
221 : // XServiceInfo
222 : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
223 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
224 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
225 :
226 : // XServiceInfo - static versions
227 : static Sequence< OUString > getSupportedServiceNames_static(void) throw( RuntimeException );
228 : static OUString getImplementationName_static(void) throw( RuntimeException );
229 : static Reference< XInterface > Create(const Reference< XComponentContext >& _rxContext);
230 : static OUString getSingletonName_static();
231 :
232 : // XDataAccessDescriptorFactory
233 : virtual Reference< XPropertySet > SAL_CALL createDataAccessDescriptor( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
234 :
235 : protected:
236 : DataAccessDescriptorFactory( const Reference< XComponentContext >& _rxContext );
237 : virtual ~DataAccessDescriptorFactory();
238 :
239 : private:
240 : Reference<XComponentContext> m_xContext;
241 : };
242 :
243 0 : DataAccessDescriptorFactory::DataAccessDescriptorFactory( const Reference< XComponentContext >& _rxContext )
244 0 : :m_xContext( _rxContext )
245 : {
246 0 : }
247 :
248 0 : DataAccessDescriptorFactory::~DataAccessDescriptorFactory()
249 : {
250 0 : }
251 :
252 0 : OUString DataAccessDescriptorFactory::getSingletonName_static()
253 : {
254 0 : return OUString( "com.sun.star.sdb.DataAccessDescriptorFactory" );
255 : }
256 :
257 0 : Sequence< OUString > DataAccessDescriptorFactory::getSupportedServiceNames_static() throw( RuntimeException )
258 : {
259 0 : Sequence< OUString > aServices(1);
260 0 : aServices[0] = getSingletonName_static();
261 0 : return aServices;
262 : }
263 :
264 0 : OUString DataAccessDescriptorFactory::getImplementationName_static() throw( RuntimeException )
265 : {
266 0 : return OUString( "com.sun.star.comp.dba.DataAccessDescriptorFactory" );
267 : }
268 :
269 0 : Reference< XInterface > DataAccessDescriptorFactory::Create( const Reference< XComponentContext >& _rxContext )
270 : {
271 0 : return *( new DataAccessDescriptorFactory( _rxContext ) );
272 : }
273 :
274 0 : OUString SAL_CALL DataAccessDescriptorFactory::getImplementationName() throw (RuntimeException, std::exception)
275 : {
276 0 : return getImplementationName_static();
277 : }
278 :
279 0 : sal_Bool SAL_CALL DataAccessDescriptorFactory::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
280 : {
281 0 : return cppu::supportsService(this, rServiceName);
282 : }
283 :
284 0 : Sequence< OUString > SAL_CALL DataAccessDescriptorFactory::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
285 : {
286 0 : return getSupportedServiceNames_static();
287 : }
288 :
289 0 : Reference< XPropertySet > SAL_CALL DataAccessDescriptorFactory::createDataAccessDescriptor( ) throw (RuntimeException, std::exception)
290 : {
291 0 : return new DataAccessDescriptor( m_xContext );
292 : }
293 :
294 : } // namespace dbaccess
295 :
296 0 : extern "C" void SAL_CALL createRegistryInfo_DataAccessDescriptorFactory()
297 : {
298 0 : static ::dba::OSingletonRegistration< ::dbaccess::DataAccessDescriptorFactory > aAutoRegistration;
299 0 : }
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|