Branch data 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 : :
21 : : #include "TableDeco.hxx"
22 : : #include <definitioncolumn.hxx>
23 : : #include "dbastrings.hrc"
24 : : #include "core_resource.hxx"
25 : : #include "core_resource.hrc"
26 : : #include <tools/debug.hxx>
27 : : #include <osl/diagnose.h>
28 : :
29 : : #include <cppuhelper/typeprovider.hxx>
30 : : #include <comphelper/enumhelper.hxx>
31 : : #include <comphelper/container.hxx>
32 : : #include <comphelper/sequence.hxx>
33 : : #include <comphelper/property.hxx>
34 : : #include <comphelper/types.hxx>
35 : : #include <com/sun/star/util/XRefreshListener.hpp>
36 : : #include <com/sun/star/sdbc/XConnection.hpp>
37 : : #include <com/sun/star/sdbc/XRow.hpp>
38 : : #include <com/sun/star/sdbcx/Privilege.hpp>
39 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
40 : : #include <connectivity/dbtools.hxx>
41 : : #include <connectivity/dbexception.hxx>
42 : : #include <comphelper/extract.hxx>
43 : : #include "ContainerMediator.hxx"
44 : : #include <rtl/logfile.hxx>
45 : :
46 : : using namespace dbaccess;
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::util;
49 : : using namespace ::com::sun::star::lang;
50 : : using namespace ::com::sun::star::beans;
51 : : using namespace ::com::sun::star::sdbc;
52 : : using namespace ::com::sun::star::sdbcx;
53 : : using namespace ::com::sun::star::container;
54 : : using namespace ::osl;
55 : : using namespace ::comphelper;
56 : : using namespace ::dbtools;
57 : : using namespace ::cppu;
58 : :
59 : : //==========================================================================
60 : : //= ODBTableDecorator
61 : : //==========================================================================
62 : : DBG_NAME(ODBTableDecorator)
63 : :
64 : 28 : ODBTableDecorator::ODBTableDecorator( const Reference< XConnection >& _rxConnection, const Reference< XColumnsSupplier >& _rxNewTable,
65 : : const Reference< XNumberFormatsSupplier >& _rxNumberFormats, const Reference< XNameAccess >& _xColumnDefinitions ) throw(SQLException)
66 : : :OTableDescriptor_BASE(m_aMutex)
67 : : ,ODataSettings(OTableDescriptor_BASE::rBHelper)
68 : : ,m_xTable(_rxNewTable)
69 : : ,m_xColumnDefinitions(_xColumnDefinitions)
70 : : ,m_xConnection( _rxConnection )
71 [ + - ]: 56 : ,m_xMetaData( _rxConnection.is() ? _rxConnection->getMetaData() : Reference< XDatabaseMetaData >() )
72 : : ,m_xNumberFormats( _rxNumberFormats )
73 : : ,m_nPrivileges(-1)
74 [ + - ][ + - ]: 84 : ,m_pColumns(NULL)
[ + - ][ + - ]
75 : : {
76 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::ODBTableDecorator" );
77 : : DBG_CTOR(ODBTableDecorator, NULL);
78 [ + - ]: 28 : ODataSettings::registerPropertiesFor(this);
79 : 28 : }
80 : :
81 [ + - ][ + - ]: 28 : ODBTableDecorator::~ODBTableDecorator()
[ + - ]
82 : : {
83 : : DBG_DTOR(ODBTableDecorator, NULL);
84 [ + - ]: 28 : if ( m_pColumns )
85 [ + - ][ + - ]: 28 : delete m_pColumns;
86 [ - + ]: 56 : }
87 : :
88 : 0 : Sequence< sal_Int8 > ODBTableDecorator::getImplementationId() throw (RuntimeException)
89 : : {
90 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getImplementationId" );
91 : : static OImplementationId * pId = 0;
92 [ # # ]: 0 : if (! pId)
93 : : {
94 [ # # ][ # # ]: 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
95 [ # # ]: 0 : if (! pId)
96 : : {
97 [ # # ][ # # ]: 0 : static OImplementationId aId;
98 : 0 : pId = &aId;
99 [ # # ]: 0 : }
100 : : }
101 : 0 : return pId->getImplementationId();
102 : : }
103 : :
104 : : // OComponentHelper
105 : 28 : void SAL_CALL ODBTableDecorator::disposing()
106 : : {
107 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::disposing" );
108 [ + - ]: 28 : OPropertySetHelper::disposing();
109 [ + - ]: 28 : OTableDescriptor_BASE::disposing();
110 : :
111 [ + - ]: 28 : MutexGuard aGuard(m_aMutex);
112 [ + - ]: 28 : m_xTable = NULL;
113 [ + - ]: 28 : m_xMetaData = NULL;
114 : 28 : m_pTables = NULL;
115 [ + - ]: 28 : m_xColumnDefinitions = NULL;
116 [ + - ]: 28 : m_xNumberFormats = NULL;
117 [ + - ]: 28 : if ( m_pColumns )
118 [ + - ]: 28 : m_pColumns->disposing();
119 [ + - ][ + - ]: 28 : m_xColumnMediator = NULL;
120 : 28 : }
121 : :
122 : 1406 : sal_Bool SAL_CALL ODBTableDecorator::convertFastPropertyValue(
123 : : Any & rConvertedValue,
124 : : Any & rOldValue,
125 : : sal_Int32 nHandle,
126 : : const Any& rValue )
127 : : throw (::com::sun::star::lang::IllegalArgumentException)
128 : : {
129 : 1406 : sal_Bool bRet = sal_True;
130 [ + - ]: 1406 : switch(nHandle)
131 : : {
132 : : case PROPERTY_ID_PRIVILEGES:
133 : : case PROPERTY_ID_FILTER:
134 : : case PROPERTY_ID_ORDER:
135 : : case PROPERTY_ID_APPLYFILTER:
136 : : case PROPERTY_ID_FONT:
137 : : case PROPERTY_ID_ROW_HEIGHT:
138 : : case PROPERTY_ID_TEXTCOLOR:
139 : : case PROPERTY_ID_TEXTLINECOLOR:
140 : : case PROPERTY_ID_TEXTEMPHASIS:
141 : : case PROPERTY_ID_TEXTRELIEF:
142 : : case PROPERTY_ID_FONTCHARWIDTH:
143 : : case PROPERTY_ID_FONTCHARSET:
144 : : case PROPERTY_ID_FONTFAMILY:
145 : : case PROPERTY_ID_FONTHEIGHT:
146 : : case PROPERTY_ID_FONTKERNING:
147 : : case PROPERTY_ID_FONTNAME:
148 : : case PROPERTY_ID_FONTORIENTATION:
149 : : case PROPERTY_ID_FONTPITCH:
150 : : case PROPERTY_ID_FONTSLANT:
151 : : case PROPERTY_ID_FONTSTRIKEOUT:
152 : : case PROPERTY_ID_FONTSTYLENAME:
153 : : case PROPERTY_ID_FONTUNDERLINE:
154 : : case PROPERTY_ID_FONTWEIGHT:
155 : : case PROPERTY_ID_FONTWIDTH:
156 : : case PROPERTY_ID_FONTWORDLINEMODE:
157 : : case PROPERTY_ID_FONTTYPE:
158 : 1406 : bRet = ODataSettings::convertFastPropertyValue(rConvertedValue, rOldValue,nHandle,rValue);
159 : 1406 : break;
160 : :
161 : : default:
162 : : {
163 : 0 : Any aValue;
164 [ # # ]: 0 : getFastPropertyValue(aValue,nHandle);
165 [ # # ][ # # ]: 0 : bRet = ::comphelper::tryPropertyValue(rConvertedValue,rOldValue,rValue,aValue,::getCppuType(static_cast< ::rtl::OUString*>(0)));
166 : : }
167 : 0 : break; // we assume that it works
168 : : }
169 : 1406 : return bRet;
170 : : }
171 : :
172 : 12 : void ODBTableDecorator::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception)
173 : : {
174 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setFastPropertyValue_NoBroadcast" );
175 [ + - - - : 12 : switch(_nHandle)
- - - ]
176 : : {
177 : : case PROPERTY_ID_PRIVILEGES:
178 : : OSL_FAIL("Property is readonly!");
179 : : case PROPERTY_ID_FILTER:
180 : : case PROPERTY_ID_ORDER:
181 : : case PROPERTY_ID_APPLYFILTER:
182 : : case PROPERTY_ID_FONT:
183 : : case PROPERTY_ID_ROW_HEIGHT:
184 : : case PROPERTY_ID_TEXTCOLOR:
185 : : case PROPERTY_ID_TEXTLINECOLOR:
186 : : case PROPERTY_ID_TEXTEMPHASIS:
187 : : case PROPERTY_ID_TEXTRELIEF:
188 : : case PROPERTY_ID_FONTCHARWIDTH:
189 : : case PROPERTY_ID_FONTCHARSET:
190 : : case PROPERTY_ID_FONTFAMILY:
191 : : case PROPERTY_ID_FONTHEIGHT:
192 : : case PROPERTY_ID_FONTKERNING:
193 : : case PROPERTY_ID_FONTNAME:
194 : : case PROPERTY_ID_FONTORIENTATION:
195 : : case PROPERTY_ID_FONTPITCH:
196 : : case PROPERTY_ID_FONTSLANT:
197 : : case PROPERTY_ID_FONTSTRIKEOUT:
198 : : case PROPERTY_ID_FONTSTYLENAME:
199 : : case PROPERTY_ID_FONTUNDERLINE:
200 : : case PROPERTY_ID_FONTWEIGHT:
201 : : case PROPERTY_ID_FONTWIDTH:
202 : : case PROPERTY_ID_FONTWORDLINEMODE:
203 : : case PROPERTY_ID_FONTTYPE:
204 : :
205 : 12 : ODataSettings::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
206 : 12 : break;
207 : : case PROPERTY_ID_CATALOGNAME:
208 : : {
209 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
210 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_CATALOGNAME,_rValue);
[ # # ]
211 : : }
212 : 0 : break;
213 : : case PROPERTY_ID_SCHEMANAME:
214 : : {
215 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
216 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_SCHEMANAME,_rValue);
[ # # ]
217 : : }
218 : 0 : break;
219 : : case PROPERTY_ID_NAME:
220 : : {
221 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
222 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_NAME,_rValue);
[ # # ]
223 : : }
224 : 0 : break;
225 : : case PROPERTY_ID_DESCRIPTION:
226 : : {
227 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
228 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_DESCRIPTION,_rValue);
[ # # ]
229 : : }
230 : 0 : break;
231 : : case PROPERTY_ID_TYPE:
232 : : {
233 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
234 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_TYPE,_rValue);
[ # # ]
235 : : }
236 : 0 : break;
237 : : }
238 : 12 : }
239 : :
240 : 90 : void ODBTableDecorator::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
241 : : {
242 : :
243 [ - + + + : 90 : switch(_nHandle)
+ - - - ]
244 : : {
245 : : case PROPERTY_ID_PRIVILEGES:
246 : : {
247 [ # # ]: 0 : if ( -1 == m_nPrivileges )
248 [ # # ]: 0 : fillPrivileges();
249 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
250 [ # # ][ # # ]: 0 : Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
251 [ # # ][ # # ]: 0 : if ( xInfo->hasPropertyByName(PROPERTY_PRIVILEGES) )
[ # # ][ # # ]
252 : : {
253 [ # # ]: 0 : _rValue <<= m_nPrivileges;
254 : : break;
255 [ # # ][ # # ]: 0 : }
256 : : }
257 : : // run through
258 : :
259 : : case PROPERTY_ID_FILTER:
260 : : case PROPERTY_ID_ORDER:
261 : : case PROPERTY_ID_APPLYFILTER:
262 : : case PROPERTY_ID_FONT:
263 : : case PROPERTY_ID_ROW_HEIGHT:
264 : : case PROPERTY_ID_TEXTCOLOR:
265 : : case PROPERTY_ID_TEXTLINECOLOR:
266 : : case PROPERTY_ID_TEXTEMPHASIS:
267 : : case PROPERTY_ID_TEXTRELIEF:
268 : : case PROPERTY_ID_FONTCHARWIDTH:
269 : : case PROPERTY_ID_FONTCHARSET:
270 : : case PROPERTY_ID_FONTFAMILY:
271 : : case PROPERTY_ID_FONTHEIGHT:
272 : : case PROPERTY_ID_FONTKERNING:
273 : : case PROPERTY_ID_FONTNAME:
274 : : case PROPERTY_ID_FONTORIENTATION:
275 : : case PROPERTY_ID_FONTPITCH:
276 : : case PROPERTY_ID_FONTSLANT:
277 : : case PROPERTY_ID_FONTSTRIKEOUT:
278 : : case PROPERTY_ID_FONTSTYLENAME:
279 : : case PROPERTY_ID_FONTUNDERLINE:
280 : : case PROPERTY_ID_FONTWEIGHT:
281 : : case PROPERTY_ID_FONTWIDTH:
282 : : case PROPERTY_ID_FONTWORDLINEMODE:
283 : : case PROPERTY_ID_FONTTYPE:
284 : 18 : ODataSettings::getFastPropertyValue(_rValue, _nHandle);
285 : 18 : break;
286 : : case PROPERTY_ID_CATALOGNAME:
287 : : {
288 [ + - ]: 24 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
289 [ + - ][ + - ]: 24 : _rValue = xProp->getPropertyValue(PROPERTY_CATALOGNAME);
[ + - ]
290 : : }
291 : 24 : break;
292 : : case PROPERTY_ID_SCHEMANAME:
293 : : {
294 [ + - ]: 24 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
295 [ + - ][ + - ]: 24 : _rValue = xProp->getPropertyValue(PROPERTY_SCHEMANAME);
[ + - ]
296 : : }
297 : 24 : break;
298 : : case PROPERTY_ID_NAME:
299 : : {
300 [ + - ]: 24 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
301 [ + - ][ + - ]: 24 : _rValue = xProp->getPropertyValue(PROPERTY_NAME);
[ + - ]
302 : : }
303 : 24 : break;
304 : : case PROPERTY_ID_DESCRIPTION:
305 : : {
306 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
307 [ # # ][ # # ]: 0 : _rValue = xProp->getPropertyValue(PROPERTY_DESCRIPTION);
[ # # ]
308 : : }
309 : 0 : break;
310 : : case PROPERTY_ID_TYPE:
311 : : {
312 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
313 [ # # ][ # # ]: 0 : _rValue = xProp->getPropertyValue(PROPERTY_TYPE);
[ # # ]
314 : : }
315 : 0 : break;
316 : : default:
317 : : OSL_FAIL("Invalid Handle for table");
318 : : }
319 : 90 : }
320 : :
321 : 28 : void ODBTableDecorator::construct()
322 : : {
323 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::construct" );
324 : 28 : sal_Bool bNotFound = sal_True;
325 [ + - ]: 28 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
326 [ + - ]: 28 : if ( xProp.is() )
327 : : {
328 [ + - ][ + - ]: 28 : Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
329 [ + - ][ + - ]: 28 : bNotFound = !xInfo->hasPropertyByName(PROPERTY_PRIVILEGES);
[ + - ]
330 : : }
331 [ + - ]: 28 : if ( bNotFound )
332 : : registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, PropertyAttribute::BOUND | PropertyAttribute::READONLY,
333 [ + - ][ + - ]: 28 : &m_nPrivileges, ::getCppuType(static_cast<sal_Int32*>(NULL)));
[ + - ]
334 : 28 : }
335 : :
336 : 28 : ::cppu::IPropertyArrayHelper* ODBTableDecorator::createArrayHelper(sal_Int32 /*_nId*/) const
337 : : {
338 [ + - ]: 28 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
339 [ + - ][ + - ]: 28 : Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
340 : :
341 [ + - ][ + - ]: 28 : Sequence< Property > aTableProps = xInfo->getProperties();
342 [ + - ]: 28 : Property* pIter = aTableProps.getArray();
343 : 28 : Property* pEnd = pIter + aTableProps.getLength();
344 [ + + ]: 168 : for (;pIter != pEnd ; ++pIter)
345 : : {
346 [ + + ]: 140 : if (pIter->Name.equalsAsciiL(PROPERTY_CATALOGNAME.ascii, PROPERTY_CATALOGNAME.length))
347 : 28 : pIter->Handle = PROPERTY_ID_CATALOGNAME;
348 [ + + ]: 112 : else if (pIter->Name.equalsAsciiL(PROPERTY_SCHEMANAME.ascii, PROPERTY_SCHEMANAME.length))
349 : 28 : pIter->Handle = PROPERTY_ID_SCHEMANAME;
350 [ + + ]: 84 : else if (pIter->Name.equalsAsciiL(PROPERTY_NAME.ascii, PROPERTY_NAME.length))
351 : 28 : pIter->Handle = PROPERTY_ID_NAME;
352 [ + + ]: 56 : else if (pIter->Name.equalsAsciiL(PROPERTY_DESCRIPTION.ascii, PROPERTY_DESCRIPTION.length))
353 : 28 : pIter->Handle = PROPERTY_ID_DESCRIPTION;
354 [ + - ]: 28 : else if (pIter->Name.equalsAsciiL(PROPERTY_TYPE.ascii, PROPERTY_TYPE.length))
355 : 28 : pIter->Handle = PROPERTY_ID_TYPE;
356 [ # # ]: 0 : else if (pIter->Name.equalsAsciiL(PROPERTY_PRIVILEGES.ascii, PROPERTY_PRIVILEGES.length))
357 : 0 : pIter->Handle = PROPERTY_ID_PRIVILEGES;
358 : : }
359 : :
360 [ + - ]: 28 : describeProperties(aTableProps);
361 : :
362 [ + - ][ + - ]: 28 : return new ::cppu::OPropertyArrayHelper(aTableProps);
363 : : }
364 : :
365 : 3814 : ::cppu::IPropertyArrayHelper & SAL_CALL ODBTableDecorator::getInfoHelper()
366 : : {
367 [ + - ]: 3814 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
368 : :
369 [ + - ][ + - ]: 3814 : Reference<XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
370 [ + - ][ + - ]: 3814 : bool bIsDescriptor = (xInfo->getPropertyByName(PROPERTY_NAME).Attributes & PropertyAttribute::READONLY) == 0;
[ + - ]
371 : :
372 [ + - ][ - + ]: 3814 : return *ODBTableDecorator_PROP::getArrayHelper( bIsDescriptor ? 0 : 1 );
373 : :
374 : : // TODO: this is a HACK, and prone to errors
375 : : // The OIdPropertyArrayUsageHelper is intended for classes where there exists a known, limited
376 : : // number of different property set infos (distinguished by the ID), all implemented by this very
377 : : // same class.
378 : : // However, in this case here we have an unknown, potentially unlimited number of different
379 : : // property set infos: Depending on the table for which we act as decorator, different property
380 : : // sets might exist.
381 : : }
382 : :
383 : : // XServiceInfo
384 [ + - ][ + - ]: 4 : IMPLEMENT_SERVICE_INFO1(ODBTableDecorator, "com.sun.star.sdb.dbaccess.ODBTableDecorator", SERVICE_SDBCX_TABLE.ascii)
[ + - ][ + - ]
[ + - ]
385 : :
386 : 848 : Any SAL_CALL ODBTableDecorator::queryInterface( const Type & rType ) throw(RuntimeException)
387 : : {
388 : 848 : Any aRet;
389 [ + - ]: 848 : if(m_xTable.is())
390 : : {
391 [ + - ][ + - ]: 848 : aRet = m_xTable->queryInterface(rType);
392 [ + + ]: 848 : if(aRet.hasValue())
393 : : { // now we know that our table supports this type so we return ourself
394 [ + - ]: 846 : aRet = OTableDescriptor_BASE::queryInterface(rType);
395 [ + + ]: 846 : if(!aRet.hasValue())
396 [ + - ]: 68 : aRet = ODataSettings::queryInterface(rType);
397 : : }
398 : : }
399 : :
400 : 848 : return aRet;
401 : : }
402 : :
403 : 0 : Sequence< Type > SAL_CALL ODBTableDecorator::getTypes( ) throw(RuntimeException)
404 : : {
405 [ # # ]: 0 : Reference<XTypeProvider> xTypes(m_xTable,UNO_QUERY);
406 : : OSL_ENSURE(xTypes.is(),"Table must be a TypePropvider!");
407 [ # # ][ # # ]: 0 : return xTypes->getTypes();
408 : : }
409 : :
410 : : // XRename,
411 : 0 : void SAL_CALL ODBTableDecorator::rename( const ::rtl::OUString& _rNewName ) throw(SQLException, ElementExistException, RuntimeException)
412 : : {
413 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::rename" );
414 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
415 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
416 [ # # ]: 0 : Reference<XRename> xRename(m_xTable,UNO_QUERY);
417 [ # # ]: 0 : if(xRename.is())
418 : : {
419 [ # # ][ # # ]: 0 : xRename->rename(_rNewName);
420 : : }
421 : : else // not supported
422 [ # # ][ # # ]: 0 : throw SQLException(DBACORE_RESSTRING(RID_STR_NO_TABLE_RENAME),*this,SQLSTATE_GENERAL,1000,Any() );
[ # # ][ # # ]
[ # # ]
423 : 0 : }
424 : :
425 : : // XAlterTable,
426 : 0 : void SAL_CALL ODBTableDecorator::alterColumnByName( const ::rtl::OUString& _rName, const Reference< XPropertySet >& _rxDescriptor ) throw(SQLException, NoSuchElementException, RuntimeException)
427 : : {
428 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByName" );
429 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
430 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
431 [ # # ]: 0 : Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);
432 [ # # ]: 0 : if(xAlter.is())
433 : : {
434 [ # # ][ # # ]: 0 : xAlter->alterColumnByName(_rName,_rxDescriptor);
435 : : }
436 : : else
437 [ # # ][ # # ]: 0 : throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_NAME),*this,SQLSTATE_GENERAL,1000,Any() );
[ # # ][ # # ]
438 [ # # ]: 0 : if(m_pColumns)
439 [ # # ][ # # ]: 0 : m_pColumns->refresh();
440 : 0 : }
441 : :
442 : 0 : void SAL_CALL ODBTableDecorator::alterColumnByIndex( sal_Int32 _nIndex, const Reference< XPropertySet >& _rxDescriptor ) throw(SQLException, IndexOutOfBoundsException, RuntimeException)
443 : : {
444 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::alterColumnByIndex" );
445 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
446 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
447 [ # # ]: 0 : Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);
448 [ # # ]: 0 : if(xAlter.is())
449 : : {
450 [ # # ][ # # ]: 0 : xAlter->alterColumnByIndex(_nIndex,_rxDescriptor);
451 [ # # ]: 0 : if(m_pColumns)
452 [ # # ]: 0 : m_pColumns->refresh();
453 : : }
454 : : else // not supported
455 [ # # ][ # # ]: 0 : throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_ALTER_BY_INDEX),*this,SQLSTATE_GENERAL,1000,Any() );
[ # # ][ # # ]
[ # # ]
456 : 0 : }
457 : :
458 : 0 : Reference< XNameAccess> ODBTableDecorator::getIndexes() throw (RuntimeException)
459 : : {
460 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getIndexes" );
461 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
462 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
463 [ # # ][ # # ]: 0 : return Reference< XIndexesSupplier>(m_xTable,UNO_QUERY)->getIndexes();
[ # # ][ # # ]
464 : : }
465 : :
466 : 0 : Reference< XIndexAccess> ODBTableDecorator::getKeys() throw (RuntimeException)
467 : : {
468 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getKeys" );
469 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
470 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
471 [ # # ][ # # ]: 0 : return Reference< XKeysSupplier>(m_xTable,UNO_QUERY)->getKeys();
[ # # ][ # # ]
472 : : }
473 : :
474 : 1012 : Reference< XNameAccess> ODBTableDecorator::getColumns() throw (RuntimeException)
475 : : {
476 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getColumns" );
477 [ + - ]: 1012 : ::osl::MutexGuard aGuard(m_aMutex);
478 [ + - ]: 1012 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
479 : :
480 [ + + ]: 1012 : if(!m_pColumns)
481 [ + - ]: 28 : refreshColumns();
482 : :
483 [ + - ][ + - ]: 1012 : return m_pColumns;
[ + - ]
484 : : }
485 : :
486 : 0 : ::rtl::OUString SAL_CALL ODBTableDecorator::getName() throw(RuntimeException)
487 : : {
488 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getName" );
489 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
490 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
491 [ # # ]: 0 : Reference<XNamed> xName(m_xTable,UNO_QUERY);
492 : : OSL_ENSURE(xName.is(),"Table should support the XNamed interface");
493 [ # # ][ # # ]: 0 : return xName->getName();
[ # # ]
494 : : }
495 : :
496 : 0 : sal_Int64 SAL_CALL ODBTableDecorator::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
497 : : {
498 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getSomething" );
499 [ # # ][ # # ]: 0 : if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
500 : 0 : return reinterpret_cast<sal_Int64>(this);
501 : :
502 : 0 : sal_Int64 nRet = 0;
503 [ # # ]: 0 : Reference<XUnoTunnel> xTunnel(m_xTable,UNO_QUERY);
504 [ # # ]: 0 : if(xTunnel.is())
505 [ # # ][ # # ]: 0 : nRet = xTunnel->getSomething(rId);
506 : 0 : return nRet;
507 : : }
508 : :
509 : 0 : Sequence< sal_Int8 > ODBTableDecorator::getUnoTunnelImplementationId()
510 : : {
511 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getUnoTunnelImplementationId" );
512 : : static ::cppu::OImplementationId * pId = 0;
513 [ # # ]: 0 : if (! pId)
514 : : {
515 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
516 [ # # ]: 0 : if (! pId)
517 : : {
518 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId aId;
519 : 0 : pId = &aId;
520 [ # # ]: 0 : }
521 : : }
522 : 0 : return pId->getImplementationId();
523 : : }
524 : :
525 : 0 : void ODBTableDecorator::fillPrivileges() const
526 : : {
527 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::fillPrivileges" );
528 : : // somebody is asking for the privileges and we do not know them, yet
529 : 0 : m_nPrivileges = 0;
530 : : try
531 : : {
532 [ # # ]: 0 : Reference<XPropertySet> xProp(m_xTable,UNO_QUERY);
533 [ # # ]: 0 : if ( xProp.is() )
534 : : {
535 [ # # ][ # # ]: 0 : if ( xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_PRIVILEGES) )
[ # # ][ # # ]
[ # # ][ # # ]
536 : : {
537 [ # # ][ # # ]: 0 : xProp->getPropertyValue(PROPERTY_PRIVILEGES) >>= m_nPrivileges;
[ # # ]
538 : : }
539 [ # # ]: 0 : if ( m_nPrivileges == 0 ) // second chance
540 : : {
541 : 0 : ::rtl::OUString sCatalog,sSchema,sName;
542 [ # # ][ # # ]: 0 : xProp->getPropertyValue(PROPERTY_CATALOGNAME) >>= sCatalog;
[ # # ]
543 [ # # ][ # # ]: 0 : xProp->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema;
[ # # ]
544 [ # # ][ # # ]: 0 : xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
[ # # ]
545 [ # # ][ # # ]: 0 : m_nPrivileges = ::dbtools::getTablePrivileges(getMetaData(),sCatalog,sSchema, sName);
546 : : }
547 [ # # ]: 0 : }
548 : : }
549 : 0 : catch(const SQLException& e)
550 : : {
551 : : (void)e;
552 : : OSL_FAIL("ODBTableDecorator::ODBTableDecorator : could not collect the privileges !");
553 : : }
554 : 0 : }
555 : :
556 : 0 : Reference< XPropertySet > SAL_CALL ODBTableDecorator::createDataDescriptor( ) throw (RuntimeException)
557 : : {
558 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createDataDescriptor" );
559 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
560 [ # # ]: 0 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
561 : :
562 [ # # ]: 0 : Reference< XDataDescriptorFactory > xFactory( m_xTable, UNO_QUERY );
563 : : OSL_ENSURE( xFactory.is(), "ODBTableDecorator::createDataDescriptor: invalid table!" );
564 : 0 : Reference< XColumnsSupplier > xColsSupp;
565 [ # # ]: 0 : if ( xFactory.is() )
566 [ # # ][ # # ]: 0 : xColsSupp = xColsSupp.query( xFactory->createDataDescriptor() );
[ # # ][ # # ]
567 : :
568 : : return new ODBTableDecorator(
569 : : m_xConnection,
570 : : xColsSupp,
571 : : m_xNumberFormats,
572 : : NULL
573 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ]
574 : : }
575 : :
576 : 110 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODBTableDecorator::getPropertySetInfo( ) throw(RuntimeException)
577 : : {
578 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::getPropertySetInfo" );
579 : 110 : return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
580 : : }
581 : :
582 : 28 : void ODBTableDecorator::refreshColumns()
583 : : {
584 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::refreshColumns" );
585 [ + - ]: 28 : ::osl::MutexGuard aGuard(m_aMutex);
586 [ + - ]: 28 : ::connectivity::checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
587 : :
588 [ + - ]: 28 : ::std::vector< ::rtl::OUString> aVector;
589 : :
590 : 28 : Reference<XNameAccess> xNames;
591 [ + - ]: 28 : if(m_xTable.is())
592 : : {
593 [ + - ][ + - ]: 28 : xNames = m_xTable->getColumns();
[ + - ]
594 [ + - ]: 28 : if(xNames.is())
595 : : {
596 [ + - ][ + - ]: 28 : Sequence< ::rtl::OUString> aNames = xNames->getElementNames();
597 : 28 : const ::rtl::OUString* pIter = aNames.getConstArray();
598 : 28 : const ::rtl::OUString* pEnd = pIter + aNames.getLength();
599 [ + + ]: 576 : for(;pIter != pEnd;++pIter)
600 [ + - ][ + - ]: 576 : aVector.push_back(*pIter);
601 : : }
602 : : }
603 [ + - ]: 28 : if(!m_pColumns)
604 : : {
605 [ + - ][ + - ]: 56 : OColumns* pCol = new OColumns(*this,m_aMutex,xNames,m_xMetaData.is() && m_xMetaData->supportsMixedCaseQuotedIdentifiers(),aVector,
606 : : this,this,
607 [ + - ][ + - ]: 56 : m_xMetaData.is() && m_xMetaData->supportsAlterTableWithAddColumn(),
608 [ + - ][ + - ]: 112 : m_xMetaData.is() && m_xMetaData->supportsAlterTableWithDropColumn());
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
609 : :
610 [ + - ][ + - ]: 28 : pCol->setParent(*this);
611 [ + - ][ + - ]: 28 : OContainerMediator* pMediator = new OContainerMediator( pCol, m_xColumnDefinitions, m_xConnection, OContainerMediator::eColumns );
[ + - ]
612 [ + - ][ + - ]: 28 : m_xColumnMediator = pMediator;
613 : 28 : pCol->setMediator( pMediator );
614 : 28 : m_pColumns = pCol;
615 : : }
616 : : else
617 [ # # ][ + - ]: 28 : m_pColumns->reFill(aVector);
618 : 28 : }
619 : :
620 : 428 : OColumn* ODBTableDecorator::createColumn(const ::rtl::OUString& _rName) const
621 : : {
622 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumn" );
623 : 428 : OColumn* pReturn = NULL;
624 : :
625 : 428 : Reference<XNameAccess> xNames;
626 [ + - ]: 428 : if ( m_xTable.is() )
627 : : {
628 [ + - ][ + - ]: 428 : xNames = m_xTable->getColumns();
[ + - ]
629 : :
630 [ + - ][ + - ]: 428 : if ( xNames.is() && xNames->hasByName(_rName) )
[ + - ][ + - ]
[ + - ]
631 : : {
632 [ + - ][ + - ]: 428 : Reference<XPropertySet> xProp(xNames->getByName(_rName),UNO_QUERY);
[ + - ]
633 : :
634 : 428 : Reference<XPropertySet> xColumnDefintion;
635 [ + - ][ + - ]: 428 : if ( m_xColumnDefinitions.is() && m_xColumnDefinitions->hasByName(_rName))
[ + + ][ + + ]
[ + - ]
636 [ + - ][ + - ]: 244 : xColumnDefintion.set(m_xColumnDefinitions->getByName(_rName),UNO_QUERY);
[ + - ]
637 : :
638 [ + - ]: 428 : pReturn = new OTableColumnWrapper( xProp, xColumnDefintion, false );
639 : : }
640 : : }
641 : 428 : return pReturn;
642 : : }
643 : :
644 : 0 : void ODBTableDecorator::columnAppended( const Reference< XPropertySet >& /*_rxSourceDescriptor*/ )
645 : : {
646 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnAppended" );
647 : : // not interested in
648 : 0 : }
649 : :
650 : 0 : void ODBTableDecorator::columnDropped(const ::rtl::OUString& _sName)
651 : : {
652 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::columnDropped" );
653 [ # # ]: 0 : Reference<XDrop> xDrop(m_xColumnDefinitions,UNO_QUERY);
654 [ # # ][ # # ]: 0 : if ( xDrop.is() && m_xColumnDefinitions->hasByName(_sName) )
[ # # ][ # # ]
[ # # ]
655 [ # # ][ # # ]: 0 : xDrop->dropByName(_sName);
656 : 0 : }
657 : :
658 : 0 : Reference< XPropertySet > ODBTableDecorator::createColumnDescriptor()
659 : : {
660 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::createColumnDescriptor" );
661 : 0 : Reference<XDataDescriptorFactory> xNames;
662 [ # # ]: 0 : if(m_xTable.is())
663 [ # # ][ # # ]: 0 : xNames.set(m_xTable->getColumns(),UNO_QUERY);
[ # # ]
664 : 0 : Reference< XPropertySet > xRet;
665 [ # # ]: 0 : if ( xNames.is() )
666 [ # # ][ # # ]: 0 : xRet = new OTableColumnDescriptorWrapper( xNames->createDataDescriptor(), false, true );
[ # # ][ # # ]
[ # # ]
667 : 0 : return xRet;
668 : : }
669 : :
670 : 6404 : void SAL_CALL ODBTableDecorator::acquire() throw()
671 : : {
672 : 6404 : OTableDescriptor_BASE::acquire();
673 : 6404 : }
674 : :
675 : 6404 : void SAL_CALL ODBTableDecorator::release() throw()
676 : : {
677 : 6404 : OTableDescriptor_BASE::release();
678 : 6404 : }
679 : :
680 : 0 : void SAL_CALL ODBTableDecorator::setName( const ::rtl::OUString& /*aName*/ ) throw (::com::sun::star::uno::RuntimeException)
681 : : {
682 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "ODBTableDecorator::setName" );
683 [ # # ]: 0 : throwFunctionNotSupportedException( "XNamed::setName", *this );
684 : 0 : }
685 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|