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 #ifndef _DBA_CORE_TABLEDECORATOR_HXX_
29 #define _DBA_CORE_TABLEDECORATOR_HXX_
30 
31 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
32 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
33 #endif
34 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
35 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36 #endif
37 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
38 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_SDBCX_XINDEXESSUPPLIER_HPP_
41 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
44 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_
47 #include <com/sun/star/sdbcx/XRename.hpp>
48 #endif
49 #ifndef _COM_SUN_STAR_SDBCX_XALTERTABLE_HPP_
50 #include <com/sun/star/sdbcx/XAlterTable.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
53 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #endif
55 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
56 #include <com/sun/star/sdbc/XRow.hpp>
57 #endif
58 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
59 #include <com/sun/star/sdbc/XConnection.hpp>
60 #endif
61 #ifndef _CPPUHELPER_COMPBASE9_HXX_
62 #include <cppuhelper/compbase9.hxx>
63 #endif
64 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
65 #include <cppuhelper/implbase5.hxx>
66 #endif
67 #ifndef _DBASHARED_APITOOLS_HXX_
68 #include "apitools.hxx"
69 #endif
70 #ifndef _DBA_CORE_DATASETTINGS_HXX_
71 #include "datasettings.hxx"
72 #endif
73 #ifndef _DBA_COREAPI_COLUMN_HXX_
74 #include "column.hxx"
75 #endif
76 
77 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
78 #include <connectivity/CommonTools.hxx>
79 #endif
80 #ifndef _CONNECTIVITY_SDBCX_IREFRESHABLE_HXX_
81 #include <connectivity/sdbcx/IRefreshable.hxx>
82 #endif
83 #ifndef COMPHELPER_IDPROPERTYARRAYUSAGEHELPER_HXX
84 #include <comphelper/IdPropArrayHelper.hxx>
85 #endif
86 
87 namespace dbaccess
88 {
89 	typedef ::cppu::WeakComponentImplHelper9<	::com::sun::star::sdbcx::XColumnsSupplier,
90 												::com::sun::star::sdbcx::XKeysSupplier,
91 												::com::sun::star::container::XNamed,
92 												::com::sun::star::lang::XServiceInfo,
93 												::com::sun::star::sdbcx::XDataDescriptorFactory,
94 												::com::sun::star::sdbcx::XIndexesSupplier,
95 												::com::sun::star::sdbcx::XRename,
96 												::com::sun::star::lang::XUnoTunnel,
97 												::com::sun::star::sdbcx::XAlterTable> OTableDescriptor_BASE;
98 	//==========================================================================
99 	//= OTables
100 	//==========================================================================
101 	class ODBTableDecorator;
102     typedef ::comphelper::OIdPropertyArrayUsageHelper< ODBTableDecorator >  ODBTableDecorator_PROP;
103 
104 	class ODBTableDecorator	:public comphelper::OBaseMutex
105 							,public OTableDescriptor_BASE
106 							,public ODataSettings //ODataSettings_Base
107 							,public IColumnFactory
108 							,public ::connectivity::sdbcx::IRefreshableColumns
109 							,public ODBTableDecorator_PROP
110 	{
111 		void fillPrivileges() const;
112 	protected:
113 		::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >	m_xColumnMediator;
114 		::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier >		m_xTable;
115 		::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >		m_xColumnDefinitions;
116 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >             m_xConnection;
117 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >		m_xMetaData;
118 		::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >	m_xNumberFormats;
119 
120 	// <properties>
121 		mutable sal_Int32																	m_nPrivileges;
122 	// </properties>
123 		::connectivity::sdbcx::OCollection*													m_pColumns;
124 		::connectivity::sdbcx::OCollection*													m_pTables;
125 
126 		// IColumnFactory
127 		virtual OColumn*	createColumn(const ::rtl::OUString& _rName) const;
128 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > createColumnDescriptor();
129         virtual void columnAppended( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSourceDescriptor );
130 		virtual void columnDropped(const ::rtl::OUString& _sName);
131 
132         virtual void refreshColumns();
133 
134         virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 _nId) const;
135 		virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
136 
137 		// OPropertySetHelper
138 		virtual sal_Bool SAL_CALL convertFastPropertyValue(
139 							::com::sun::star::uno::Any & rConvertedValue,
140 							::com::sun::star::uno::Any & rOldValue,
141 							sal_Int32 nHandle,
142 							const ::com::sun::star::uno::Any& rValue )
143 								throw (::com::sun::star::lang::IllegalArgumentException);
144 		virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
145 		virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
146 								sal_Int32 nHandle,
147 								const ::com::sun::star::uno::Any& rValue
148 												 )
149 
150 										 throw (::com::sun::star::uno::Exception);
151 
152 		virtual ~ODBTableDecorator();
153 	public:
154 		/** constructs a wrapper supporting the com.sun.star.sdb.Table service.
155 
156             @param _rxConn
157                 the connection the table belongs to. Must not be <NULL/>
158 			@param _rxTable
159                 the table from the driver can be <NULL/>
160 		*/
161 		ODBTableDecorator(
162             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn,
163 			const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier >& _rxTable,
164 			const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& _rxNumberFormats,
165 			const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxColumnDefinitions
166 		)	throw(::com::sun::star::sdbc::SQLException);
167 
168 
169 
170 		// ODescriptor
171 		virtual void construct();
172 
173 		//XInterface
174 		virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
175 		virtual void SAL_CALL acquire() throw();
176         virtual void SAL_CALL release() throw();
177 		//XTypeProvider
178 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
179 		virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
180 
181 	// OComponentHelper
182 		virtual void SAL_CALL disposing(void);
183 
184 	// ::com::sun::star::lang::XServiceInfo
185 		DECLARE_SERVICE_INFO();
186 		// XPropertySet
187         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
188 	// ::com::sun::star::sdbcx::XRename,
189 		virtual void SAL_CALL rename( const ::rtl::OUString& _rNewName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
190 
191 	// ::com::sun::star::sdbcx::XAlterTable,
192 		virtual void SAL_CALL alterColumnByName( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDescriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
193 		virtual void SAL_CALL alterColumnByIndex( sal_Int32 _nIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDescriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
194 
195 		// XNamed
196         virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
197 		virtual void SAL_CALL setName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException);
198 		// com::sun::star::lang::XUnoTunnel
199         virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
200 		static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
201 
202 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> getMetaData() const { return m_xMetaData; }
203 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> getConnection() const { return m_xMetaData.is() ? m_xMetaData->getConnection() : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>(); }
204 
205 		// XColumnsSupplier
206 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns(  ) throw (::com::sun::star::uno::RuntimeException);
207 		// XKeysSupplier
208 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getKeys(  ) throw (::com::sun::star::uno::RuntimeException);
209 		// XIndexesSupplier
210 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getIndexes(  ) throw (::com::sun::star::uno::RuntimeException);
211 		// XDataDescriptorFactory
212 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL createDataDescriptor(  ) throw (::com::sun::star::uno::RuntimeException);
213 
214     protected:
215         using ODataSettings::getFastPropertyValue;
216 	};
217 }
218 #endif // _DBA_CORE_TABLEDECORATOR_HXX_
219 
220 
221