1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dataaccessdescriptor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "dbastrings.hrc"
35 #include "module_dba.hxx"
37 /** === begin UNO includes === **/
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/sdb/CommandType.hpp>
41 #include <com/sun/star/sdbc/XConnection.hpp>
42 #include <com/sun/star/sdbc/XResultSet.hpp>
43 #include <com/sun/star/sdb/XDataAccessDescriptorFactory.hpp>
44 /** === end UNO includes === **/
46 #include <comphelper/broadcasthelper.hxx>
47 #include <comphelper/componentcontext.hxx>
48 #include <comphelper/proparrhlp.hxx>
49 #include <comphelper/propertycontainer.hxx>
50 #include <comphelper/uno3.hxx>
51 #include <cppuhelper/implbase1.hxx>
52 #include <cppuhelper/implbase2.hxx>
54 //........................................................................
57 //........................................................................
59 /** === begin UNO using === **/
60 using ::com::sun::star::uno::Reference
;
61 using ::com::sun::star::uno::XInterface
;
62 using ::com::sun::star::uno::UNO_QUERY
;
63 using ::com::sun::star::uno::UNO_QUERY_THROW
;
64 using ::com::sun::star::uno::UNO_SET_THROW
;
65 using ::com::sun::star::uno::Exception
;
66 using ::com::sun::star::uno::RuntimeException
;
67 using ::com::sun::star::uno::Any
;
68 using ::com::sun::star::uno::makeAny
;
69 using ::com::sun::star::uno::Sequence
;
70 using ::com::sun::star::lang::XServiceInfo
;
71 using ::com::sun::star::lang::XMultiServiceFactory
;
72 using ::com::sun::star::beans::XPropertySetInfo
;
73 using ::com::sun::star::beans::Property
;
74 using ::com::sun::star::sdbc::XConnection
;
75 using ::com::sun::star::sdbc::XResultSet
;
76 using ::com::sun::star::sdb::XDataAccessDescriptorFactory
;
77 using ::com::sun::star::beans::XPropertySet
;
78 using ::com::sun::star::uno::XComponentContext
;
79 using ::com::sun::star::beans::PropertyValue
;
80 /** === end UNO using === **/
82 namespace PropertyAttribute
= ::com::sun::star::beans::PropertyAttribute
;
83 namespace CommandType
= ::com::sun::star::sdb::CommandType
;
85 //====================================================================
86 //= DataAccessDescriptor
87 //====================================================================
88 typedef ::comphelper::OMutexAndBroadcastHelper DataAccessDescriptor_MutexBase
;
90 typedef ::cppu::WeakImplHelper1
< XServiceInfo
91 > DataAccessDescriptor_TypeBase
;
93 typedef ::comphelper::OPropertyContainer DataAccessDescriptor_PropertyBase
;
95 class DataAccessDescriptor
:public DataAccessDescriptor_MutexBase
96 ,public DataAccessDescriptor_TypeBase
97 ,public DataAccessDescriptor_PropertyBase
98 ,public ::comphelper::OPropertyArrayUsageHelper
< DataAccessDescriptor
>
101 DataAccessDescriptor( const ::comphelper::ComponentContext
& _rContext
);
105 DECLARE_XTYPEPROVIDER()
108 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
109 virtual ::sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw (RuntimeException
);
110 virtual Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
113 ~DataAccessDescriptor();
117 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw(RuntimeException
);
118 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
120 // OPropertyArrayUsageHelper
121 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
124 ::comphelper::ComponentContext m_aContext
;
127 ::rtl::OUString m_sDataSourceName
;
128 ::rtl::OUString m_sDatabaseLocation
;
129 ::rtl::OUString m_sConnectionResource
;
130 Sequence
< PropertyValue
> m_aConnectionInfo
;
131 Reference
< XConnection
> m_xActiveConnection
;
132 ::rtl::OUString m_sCommand
;
133 sal_Int32 m_nCommandType
;
134 ::rtl::OUString m_sFilter
;
135 ::rtl::OUString m_sOrder
;
136 ::rtl::OUString m_sHavingClause
;
137 ::rtl::OUString m_sGroupBy
;
138 sal_Bool m_bEscapeProcessing
;
139 Reference
< XResultSet
> m_xResultSet
;
140 Sequence
< Any
> m_aSelection
;
141 sal_Bool m_bBookmarkSelection
;
142 ::rtl::OUString m_sColumnName
;
143 Reference
< XPropertySet
> m_xColumn
;
147 #define REGISTER_PROPERTY( propname, member ) \
148 registerProperty( PROPERTY_##propname, PROPERTY_ID_##propname, PropertyAttribute::BOUND, &member, ::getCppuType( &member ) )
150 //--------------------------------------------------------------------
151 DataAccessDescriptor::DataAccessDescriptor( const ::comphelper::ComponentContext
& _rContext
)
152 :DataAccessDescriptor_MutexBase()
153 ,DataAccessDescriptor_TypeBase()
154 ,DataAccessDescriptor_PropertyBase( m_aBHelper
)
155 ,m_aContext( _rContext
)
157 ,m_sDatabaseLocation()
158 ,m_sConnectionResource()
160 ,m_xActiveConnection()
162 ,m_nCommandType( CommandType::COMMAND
)
167 ,m_bEscapeProcessing( sal_True
)
170 ,m_bBookmarkSelection( sal_True
)
174 REGISTER_PROPERTY( DATASOURCENAME
, m_sDataSourceName
);
175 REGISTER_PROPERTY( DATABASE_LOCATION
, m_sDatabaseLocation
);
176 REGISTER_PROPERTY( CONNECTION_RESOURCE
, m_sConnectionResource
);
177 REGISTER_PROPERTY( CONNECTION_INFO
, m_aConnectionInfo
);
178 REGISTER_PROPERTY( ACTIVE_CONNECTION
, m_xActiveConnection
);
179 REGISTER_PROPERTY( COMMAND
, m_sCommand
);
180 REGISTER_PROPERTY( COMMAND_TYPE
, m_nCommandType
);
181 REGISTER_PROPERTY( FILTER
, m_sFilter
);
182 REGISTER_PROPERTY( ORDER
, m_sOrder
);
183 REGISTER_PROPERTY( HAVING_CLAUSE
, m_sHavingClause
);
184 REGISTER_PROPERTY( GROUP_BY
, m_sGroupBy
);
185 REGISTER_PROPERTY( ESCAPE_PROCESSING
, m_bEscapeProcessing
);
186 REGISTER_PROPERTY( RESULT_SET
, m_xResultSet
);
187 REGISTER_PROPERTY( SELECTION
, m_aSelection
);
188 REGISTER_PROPERTY( BOOKMARK_SELECTION
, m_bBookmarkSelection
);
189 REGISTER_PROPERTY( COLUMN_NAME
, m_sColumnName
);
190 REGISTER_PROPERTY( COLUMN
, m_xColumn
);
193 //--------------------------------------------------------------------
194 DataAccessDescriptor::~DataAccessDescriptor()
198 //--------------------------------------------------------------------
199 IMPLEMENT_FORWARD_XINTERFACE2( DataAccessDescriptor
, DataAccessDescriptor_TypeBase
, DataAccessDescriptor_PropertyBase
);
201 //--------------------------------------------------------------------
202 IMPLEMENT_FORWARD_XTYPEPROVIDER2( DataAccessDescriptor
, DataAccessDescriptor_TypeBase
, DataAccessDescriptor_PropertyBase
);
204 //--------------------------------------------------------------------
205 ::rtl::OUString SAL_CALL
DataAccessDescriptor::getImplementationName() throw (RuntimeException
)
207 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dba.DataAccessDescriptor" ) );
210 //--------------------------------------------------------------------
211 ::sal_Bool SAL_CALL
DataAccessDescriptor::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
213 Sequence
< ::rtl::OUString
> aServices( getSupportedServiceNames() );
214 const ::rtl::OUString
* pStart
= aServices
.getConstArray();
215 const ::rtl::OUString
* pEnd
= aServices
.getConstArray() + aServices
.getLength();
216 return ::std::find( pStart
, pEnd
, rServiceName
) != pEnd
;
219 //--------------------------------------------------------------------
220 Sequence
< ::rtl::OUString
> SAL_CALL
DataAccessDescriptor::getSupportedServiceNames( ) throw (RuntimeException
)
222 Sequence
< ::rtl::OUString
> aServices(1);
223 aServices
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataAccessDescriptor" ) );
227 //-------------------------------------------------------------------------
228 Reference
< XPropertySetInfo
> SAL_CALL
DataAccessDescriptor::getPropertySetInfo() throw(RuntimeException
)
230 Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
234 //-------------------------------------------------------------------------
235 ::cppu::IPropertyArrayHelper
& DataAccessDescriptor::getInfoHelper()
237 return *getArrayHelper();
240 //------------------------------------------------------------------------------
241 ::cppu::IPropertyArrayHelper
* DataAccessDescriptor::createArrayHelper( ) const
243 Sequence
< Property
> aProps
;
244 describeProperties( aProps
);
245 return new ::cppu::OPropertyArrayHelper( aProps
);
248 //====================================================================
249 //= DataAccessDescriptorFactory
250 //====================================================================
251 typedef ::cppu::WeakImplHelper2
< XServiceInfo
252 , XDataAccessDescriptorFactory
253 > DataAccessDescriptorFactory_Base
;
254 class DataAccessDescriptorFactory
: public DataAccessDescriptorFactory_Base
258 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
259 virtual ::sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw (RuntimeException
);
260 virtual Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
262 // XServiceInfo - static versions
263 static Sequence
< ::rtl::OUString
> getSupportedServiceNames_static(void) throw( RuntimeException
);
264 static ::rtl::OUString
getImplementationName_static(void) throw( RuntimeException
);
265 static Reference
< XInterface
> Create(const Reference
< XComponentContext
>& _rxContext
);
266 static ::rtl::OUString
getSingletonName_static();
268 // XDataAccessDescriptorFactory
269 virtual Reference
< XPropertySet
> SAL_CALL
createDataAccessDescriptor( ) throw (RuntimeException
);
272 DataAccessDescriptorFactory( const Reference
< XComponentContext
>& _rxContext
);
273 ~DataAccessDescriptorFactory();
276 ::comphelper::ComponentContext m_aContext
;
279 //--------------------------------------------------------------------
280 DataAccessDescriptorFactory::DataAccessDescriptorFactory( const Reference
< XComponentContext
>& _rxContext
)
281 :m_aContext( _rxContext
)
285 //--------------------------------------------------------------------
286 DataAccessDescriptorFactory::~DataAccessDescriptorFactory()
290 //--------------------------------------------------------------------
291 ::rtl::OUString
DataAccessDescriptorFactory::getSingletonName_static()
293 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataAccessDescriptorFactory" ) );
296 //--------------------------------------------------------------------
297 Sequence
< ::rtl::OUString
> DataAccessDescriptorFactory::getSupportedServiceNames_static() throw( RuntimeException
)
299 Sequence
< ::rtl::OUString
> aServices(1);
300 aServices
[0] = getSingletonName_static();
304 //--------------------------------------------------------------------
305 ::rtl::OUString
DataAccessDescriptorFactory::getImplementationName_static() throw( RuntimeException
)
307 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dba.DataAccessDescriptorFactory" ) );
310 //--------------------------------------------------------------------
311 Reference
< XInterface
> DataAccessDescriptorFactory::Create( const Reference
< XComponentContext
>& _rxContext
)
313 return *( new DataAccessDescriptorFactory( _rxContext
) );
316 //--------------------------------------------------------------------
317 ::rtl::OUString SAL_CALL
DataAccessDescriptorFactory::getImplementationName() throw (RuntimeException
)
319 return getImplementationName_static();
322 //--------------------------------------------------------------------
323 ::sal_Bool SAL_CALL
DataAccessDescriptorFactory::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
325 Sequence
< ::rtl::OUString
> aServices( getSupportedServiceNames_static() );
326 const ::rtl::OUString
* pStart
= aServices
.getConstArray();
327 const ::rtl::OUString
* pEnd
= aServices
.getConstArray() + aServices
.getLength();
328 return ::std::find( pStart
, pEnd
, rServiceName
) != pEnd
;
331 //--------------------------------------------------------------------
332 Sequence
< ::rtl::OUString
> SAL_CALL
DataAccessDescriptorFactory::getSupportedServiceNames( ) throw (RuntimeException
)
334 return getSupportedServiceNames_static();
337 //--------------------------------------------------------------------
338 Reference
< XPropertySet
> SAL_CALL
DataAccessDescriptorFactory::createDataAccessDescriptor( ) throw (RuntimeException
)
340 return new DataAccessDescriptor( m_aContext
);
343 //........................................................................
344 } // namespace dbaccess
345 //........................................................................
347 //--------------------------------------------------------------------------
348 extern "C" void SAL_CALL
createRegistryInfo_DataAccessDescriptorFactory()
350 static ::dba::OSingletonRegistration
< ::dbaccess::DataAccessDescriptorFactory
> aAutoRegistration
;