1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef _DBACORE_DATACOLUMN_HXX_
27 #include "datacolumn.hxx"
28 #endif
29 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #endif
32 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
33 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
36 #include <com/sun/star/sdbc/DataType.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
39 #include <com/sun/star/sdbc/ColumnValue.hpp>
40 #endif
41 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
42 #include <cppuhelper/typeprovider.hxx>
43 #endif
44 #ifndef _TOOLS_DEBUG_HXX
45 #include <tools/debug.hxx>
46 #endif
47 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
48 #include "dbastrings.hrc"
49 #endif
50 #ifndef _DBASHARED_APITOOLS_HXX_
51 #include "apitools.hxx"
52 #endif
53 
54 using namespace dbaccess;
55 using namespace ::com::sun::star::sdbc;
56 using namespace ::com::sun::star::sdb;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::container;
61 using namespace ::osl;
62 using namespace ::comphelper;
63 using namespace ::cppu;
64 
DBG_NAME(ODataColumn)65 DBG_NAME(ODataColumn)
66 //--------------------------------------------------------------------------
67 ODataColumn::ODataColumn(
68 						 const Reference < XResultSetMetaData >& _xMetaData,
69 						 const Reference < XRow >& _xRow,
70 						 const Reference < XRowUpdate >& _xRowUpdate,
71 						 sal_Int32 _nPos,
72                          const Reference< XDatabaseMetaData >& _rxDBMeta)
73 					 :OResultColumn(_xMetaData, _nPos, _rxDBMeta)
74 					 ,m_xRow(_xRow)
75 					 ,m_xRowUpdate(_xRowUpdate)
76 {
77 	DBG_CTOR(ODataColumn,NULL);
78 }
79 // -----------------------------------------------------------------------------
~ODataColumn()80 ODataColumn::~ODataColumn()
81 {
82 	DBG_DTOR(ODataColumn,NULL);
83 }
84 
85 // com::sun::star::lang::XTypeProvider
86 //--------------------------------------------------------------------------
getTypes()87 Sequence< Type > ODataColumn::getTypes() throw (RuntimeException)
88 {
89 	OTypeCollection aTypes(::getCppuType( (const Reference< XColumn > *)0 ),
90 						   ::getCppuType( (const Reference< XColumnUpdate > *)0 ),
91 						   OColumn::getTypes());
92 	return aTypes.getTypes();
93 }
94 
95 //--------------------------------------------------------------------------
getImplementationId()96 Sequence< sal_Int8 > ODataColumn::getImplementationId() throw (RuntimeException)
97 {
98 	static OImplementationId * pId = 0;
99 	if (! pId)
100 	{
101 		MutexGuard aGuard( Mutex::getGlobalMutex() );
102 		if (! pId)
103 		{
104 			static OImplementationId aId;
105 			pId = &aId;
106 		}
107 	}
108 	return pId->getImplementationId();
109 }
110 
111 //------------------------------------------------------------------------------
queryInterface(const Type & _rType)112 Any SAL_CALL ODataColumn::queryInterface( const Type & _rType ) throw (RuntimeException)
113 {
114 	Any aReturn = OResultColumn::queryInterface(_rType);
115 	if (!aReturn.hasValue())
116 		aReturn = ::cppu::queryInterface(_rType,
117 			static_cast< XColumn* >(this),
118 			static_cast< XColumnUpdate* >(this)
119 		);
120 	return aReturn;
121 }
122 
123 // XServiceInfo
124 //------------------------------------------------------------------------------
getImplementationName()125 rtl::OUString ODataColumn::getImplementationName(  ) throw(RuntimeException)
126 {
127 	return rtl::OUString::createFromAscii("com.sun.star.sdb.ODataColumn");
128 }
129 
130 //------------------------------------------------------------------------------
getSupportedServiceNames()131 Sequence< ::rtl::OUString > ODataColumn::getSupportedServiceNames(  ) throw (RuntimeException)
132 {
133 	Sequence< ::rtl::OUString > aSNS( 3 );
134 	aSNS[0] = SERVICE_SDBCX_COLUMN;
135 	aSNS[1] = SERVICE_SDB_RESULTCOLUMN;
136 	aSNS[2] = SERVICE_SDB_DATACOLUMN;
137 	return aSNS;
138 }
139 
140 // OComponentHelper
141 //------------------------------------------------------------------------------
disposing()142 void ODataColumn::disposing()
143 {
144 	OResultColumn::disposing();
145 
146 	m_xRow = NULL;
147 	m_xRowUpdate = NULL;
148 }
149 
150 // ::com::sun::star::sdb::XColumn
151 //------------------------------------------------------------------------------
wasNull(void)152 sal_Bool ODataColumn::wasNull(void) throw( SQLException, RuntimeException )
153 {
154 	MutexGuard aGuard(m_aMutex);
155 	::connectivity::checkDisposed(!m_xRow.is());
156 
157 	return m_xRow->wasNull();
158 }
159 
160 //------------------------------------------------------------------------------
getString(void)161 rtl::OUString ODataColumn::getString(void) throw( SQLException, RuntimeException )
162 {
163 	MutexGuard aGuard(m_aMutex);
164 	::connectivity::checkDisposed(!m_xRow.is());
165 
166 	return m_xRow->getString(m_nPos);
167 }
168 
169 //------------------------------------------------------------------------------
getBoolean(void)170 sal_Bool ODataColumn::getBoolean(void) throw( SQLException, RuntimeException )
171 {
172 	MutexGuard aGuard(m_aMutex);
173 	::connectivity::checkDisposed(!m_xRow.is());
174 
175 	return m_xRow->getBoolean(m_nPos);
176 }
177 
178 //------------------------------------------------------------------------------
getByte(void)179 sal_Int8 ODataColumn::getByte(void) throw( SQLException, RuntimeException )
180 {
181 	MutexGuard aGuard(m_aMutex);
182 	::connectivity::checkDisposed(!m_xRow.is());
183 
184 	return m_xRow->getByte(m_nPos);
185 }
186 
187 //------------------------------------------------------------------------------
getShort(void)188 sal_Int16 ODataColumn::getShort(void) throw( SQLException, RuntimeException )
189 {
190 	MutexGuard aGuard(m_aMutex);
191 	::connectivity::checkDisposed(!m_xRow.is());
192 
193 	return m_xRow->getShort(m_nPos);
194 }
195 
196 //------------------------------------------------------------------------------
getInt(void)197 sal_Int32 ODataColumn::getInt(void) throw( SQLException, RuntimeException )
198 {
199 	MutexGuard aGuard(m_aMutex);
200 	::connectivity::checkDisposed(!m_xRow.is());
201 
202 	return m_xRow->getInt(m_nPos);
203 }
204 
205 //------------------------------------------------------------------------------
getLong(void)206 sal_Int64 ODataColumn::getLong(void) throw( SQLException, RuntimeException )
207 {
208 	MutexGuard aGuard(m_aMutex);
209 	::connectivity::checkDisposed(!m_xRow.is());
210 
211 	return m_xRow->getLong(m_nPos);
212 }
213 
214 //------------------------------------------------------------------------------
getFloat(void)215 float ODataColumn::getFloat(void) throw( SQLException, RuntimeException )
216 {
217 	MutexGuard aGuard(m_aMutex);
218 	::connectivity::checkDisposed(!m_xRow.is());
219 
220 	return m_xRow->getFloat(m_nPos);
221 }
222 //------------------------------------------------------------------------------
getDouble(void)223 double ODataColumn::getDouble(void) throw( SQLException, RuntimeException )
224 {
225 	MutexGuard aGuard(m_aMutex);
226 	::connectivity::checkDisposed(!m_xRow.is());
227 
228 	return m_xRow->getDouble(m_nPos);
229 }
230 
231 //------------------------------------------------------------------------------
getBytes(void)232 Sequence< sal_Int8 > ODataColumn::getBytes(void) throw( SQLException, RuntimeException )
233 {
234 	MutexGuard aGuard(m_aMutex);
235 	::connectivity::checkDisposed(!m_xRow.is());
236 
237 	return m_xRow->getBytes(m_nPos);
238 }
239 //------------------------------------------------------------------------------
getDate(void)240 com::sun::star::util::Date ODataColumn::getDate(void) throw( SQLException, RuntimeException )
241 {
242 	MutexGuard aGuard(m_aMutex);
243 	::connectivity::checkDisposed(!m_xRow.is());
244 
245 	return m_xRow->getDate(m_nPos);
246 }
247 
248 //------------------------------------------------------------------------------
getTime(void)249 com::sun::star::util::Time ODataColumn::getTime(void) throw( SQLException, RuntimeException )
250 {
251 	MutexGuard aGuard(m_aMutex);
252 	::connectivity::checkDisposed(!m_xRow.is());
253 
254 	return m_xRow->getTime(m_nPos);
255 }
256 //------------------------------------------------------------------------------
getTimestamp(void)257 com::sun::star::util::DateTime ODataColumn::getTimestamp(void) throw( SQLException, RuntimeException )
258 {
259 	MutexGuard aGuard(m_aMutex);
260 	::connectivity::checkDisposed(!m_xRow.is());
261 
262 	return m_xRow->getTimestamp(m_nPos);
263 }
264 
265 //------------------------------------------------------------------------------
getBinaryStream(void)266 Reference< ::com::sun::star::io::XInputStream >  ODataColumn::getBinaryStream(void) throw( SQLException, RuntimeException )
267 {
268 	MutexGuard aGuard(m_aMutex);
269 	::connectivity::checkDisposed(!m_xRow.is());
270 
271 	return m_xRow->getBinaryStream(m_nPos);
272 }
273 
274 //------------------------------------------------------------------------------
getCharacterStream(void)275 Reference< ::com::sun::star::io::XInputStream >  ODataColumn::getCharacterStream(void) throw( SQLException, RuntimeException )
276 {
277 	MutexGuard aGuard(m_aMutex);
278 	::connectivity::checkDisposed(!m_xRow.is());
279 
280 	return m_xRow->getCharacterStream(m_nPos);
281 }
282 
283 //------------------------------------------------------------------------------
getObject(const Reference<::com::sun::star::container::XNameAccess> & typeMap)284 Any ODataColumn::getObject(const Reference< ::com::sun::star::container::XNameAccess > & typeMap) throw( SQLException, RuntimeException )
285 {
286 	MutexGuard aGuard(m_aMutex);
287 	::connectivity::checkDisposed(!m_xRow.is());
288 
289 	return m_xRow->getObject(m_nPos, typeMap);
290 }
291 
292 //------------------------------------------------------------------------------
getRef(void)293 Reference< XRef >  ODataColumn::getRef(void) throw( SQLException, RuntimeException )
294 {
295 	MutexGuard aGuard(m_aMutex);
296 	::connectivity::checkDisposed(!m_xRow.is());
297 
298 	return m_xRow->getRef(m_nPos);
299 }
300 
301 //------------------------------------------------------------------------------
getBlob(void)302 Reference< XBlob >  ODataColumn::getBlob(void) throw( SQLException, RuntimeException )
303 {
304 	MutexGuard aGuard(m_aMutex);
305 	::connectivity::checkDisposed(!m_xRow.is());
306 
307 	return m_xRow->getBlob(m_nPos);
308 }
309 
310 //------------------------------------------------------------------------------
getClob(void)311 Reference< XClob >  ODataColumn::getClob(void) throw( SQLException, RuntimeException )
312 {
313 	MutexGuard aGuard(m_aMutex);
314 	::connectivity::checkDisposed(!m_xRow.is());
315 
316 	return m_xRow->getClob(m_nPos);
317 }
318 
319 //------------------------------------------------------------------------------
getArray(void)320 Reference< XArray >  ODataColumn::getArray(void) throw( SQLException, RuntimeException )
321 {
322 	MutexGuard aGuard(m_aMutex);
323 	::connectivity::checkDisposed(!m_xRow.is());
324 
325 	return m_xRow->getArray(m_nPos);
326 }
327 
328 // ::com::sun::star::sdb::XColumnUpdate
329 //------------------------------------------------------------------------------
updateNull(void)330 void ODataColumn::updateNull(void) throw( SQLException, RuntimeException )
331 {
332 	MutexGuard aGuard( m_aMutex );
333 	::connectivity::checkDisposed(!m_xRowUpdate.is());
334 
335 	m_xRowUpdate->updateNull(m_nPos);
336 }
337 
338 //------------------------------------------------------------------------------
updateBoolean(sal_Bool x)339 void ODataColumn::updateBoolean(sal_Bool x) throw( SQLException, RuntimeException )
340 {
341 	MutexGuard aGuard( m_aMutex );
342 	::connectivity::checkDisposed(!m_xRowUpdate.is());
343 
344 	m_xRowUpdate->updateBoolean(m_nPos, x);
345 }
346 
347 //------------------------------------------------------------------------------
updateByte(sal_Int8 x)348 void ODataColumn::updateByte(sal_Int8 x) throw( SQLException, RuntimeException )
349 {
350 	MutexGuard aGuard( m_aMutex );
351 	::connectivity::checkDisposed(!m_xRowUpdate.is());
352 
353 	m_xRowUpdate->updateByte(m_nPos, x);
354 }
355 
356 //------------------------------------------------------------------------------
updateShort(sal_Int16 x)357 void ODataColumn::updateShort(sal_Int16 x) throw( SQLException, RuntimeException )
358 {
359 	MutexGuard aGuard( m_aMutex );
360 	::connectivity::checkDisposed(!m_xRowUpdate.is());
361 
362 	m_xRowUpdate->updateShort(m_nPos, x);
363 }
364 
365 //------------------------------------------------------------------------------
updateInt(sal_Int32 x)366 void ODataColumn::updateInt(sal_Int32 x) throw( SQLException, RuntimeException )
367 {
368 	MutexGuard aGuard( m_aMutex );
369 	::connectivity::checkDisposed(!m_xRowUpdate.is());
370 
371 	m_xRowUpdate->updateInt(m_nPos, x);
372 }
373 
374 //------------------------------------------------------------------------------
updateLong(sal_Int64 x)375 void ODataColumn::updateLong(sal_Int64 x) throw( SQLException, RuntimeException )
376 {
377 	MutexGuard aGuard( m_aMutex );
378 	::connectivity::checkDisposed(!m_xRowUpdate.is());
379 
380 	m_xRowUpdate->updateLong(m_nPos, x);
381 }
382 
383 //------------------------------------------------------------------------------
updateFloat(float x)384 void ODataColumn::updateFloat(float x) throw( SQLException, RuntimeException )
385 {
386 	MutexGuard aGuard( m_aMutex );
387 	::connectivity::checkDisposed(!m_xRowUpdate.is());
388 
389 	m_xRowUpdate->updateFloat(m_nPos, x);
390 }
391 
392 //------------------------------------------------------------------------------
updateDouble(double x)393 void ODataColumn::updateDouble(double x) throw( SQLException, RuntimeException )
394 {
395 	MutexGuard aGuard( m_aMutex );
396 	::connectivity::checkDisposed(!m_xRowUpdate.is());
397 
398 	m_xRowUpdate->updateDouble(m_nPos, x);
399 }
400 
401 //------------------------------------------------------------------------------
updateString(const rtl::OUString & x)402 void ODataColumn::updateString(const rtl::OUString& x) throw( SQLException, RuntimeException )
403 {
404 	MutexGuard aGuard( m_aMutex );
405 	::connectivity::checkDisposed(!m_xRowUpdate.is());
406 
407 	m_xRowUpdate->updateString(m_nPos, x);
408 }
409 
410 //------------------------------------------------------------------------------
updateBytes(const Sequence<sal_Int8> & x)411 void ODataColumn::updateBytes(const Sequence< sal_Int8 >& x) throw( SQLException, RuntimeException )
412 {
413 	MutexGuard aGuard( m_aMutex );
414 	::connectivity::checkDisposed(!m_xRowUpdate.is());
415 
416 	m_xRowUpdate->updateBytes(m_nPos, x);
417 }
418 
419 //------------------------------------------------------------------------------
updateDate(const com::sun::star::util::Date & x)420 void ODataColumn::updateDate(const com::sun::star::util::Date& x) throw( SQLException, RuntimeException )
421 {
422 	MutexGuard aGuard( m_aMutex );
423 	::connectivity::checkDisposed(!m_xRowUpdate.is());
424 
425 	m_xRowUpdate->updateDate(m_nPos, x);
426 }
427 
428 //------------------------------------------------------------------------------
updateTime(const::com::sun::star::util::Time & x)429 void ODataColumn::updateTime(const ::com::sun::star::util::Time& x) throw( SQLException, RuntimeException )
430 {
431 	MutexGuard aGuard( m_aMutex );
432 	::connectivity::checkDisposed(!m_xRowUpdate.is());
433 
434 	m_xRowUpdate->updateTime(m_nPos, x);
435 }
436 
437 //------------------------------------------------------------------------------
updateTimestamp(const::com::sun::star::util::DateTime & x)438 void ODataColumn::updateTimestamp(const ::com::sun::star::util::DateTime& x) throw( SQLException, RuntimeException )
439 {
440 	MutexGuard aGuard( m_aMutex );
441 	::connectivity::checkDisposed(!m_xRowUpdate.is());
442 
443 	m_xRowUpdate->updateTimestamp(m_nPos, x);
444 }
445 
446 //------------------------------------------------------------------------------
updateCharacterStream(const Reference<::com::sun::star::io::XInputStream> & x,sal_Int32 length)447 void ODataColumn::updateCharacterStream(const Reference< ::com::sun::star::io::XInputStream > & x, sal_Int32 length) throw( SQLException, RuntimeException )
448 {
449 	MutexGuard aGuard( m_aMutex );
450 	::connectivity::checkDisposed(!m_xRowUpdate.is());
451 
452 	m_xRowUpdate->updateCharacterStream(m_nPos, x, length);
453 }
454 
455 //------------------------------------------------------------------------------
updateBinaryStream(const Reference<::com::sun::star::io::XInputStream> & x,sal_Int32 length)456 void ODataColumn::updateBinaryStream(const Reference< ::com::sun::star::io::XInputStream > & x, sal_Int32 length) throw( SQLException, RuntimeException )
457 {
458 	MutexGuard aGuard( m_aMutex );
459 	::connectivity::checkDisposed(!m_xRowUpdate.is());
460 
461 	m_xRowUpdate->updateBinaryStream(m_nPos, x, length);
462 }
463 
464 //------------------------------------------------------------------------------
updateNumericObject(const Any & x,sal_Int32 scale)465 void ODataColumn::updateNumericObject(const Any& x, sal_Int32 scale) throw( SQLException, RuntimeException )
466 {
467 	MutexGuard aGuard( m_aMutex );
468 	::connectivity::checkDisposed(!m_xRowUpdate.is());
469 
470 	m_xRowUpdate->updateNumericObject(m_nPos, x, scale);
471 }
472 
473 //------------------------------------------------------------------------------
updateObject(const Any & x)474 void ODataColumn::updateObject(const Any& x) throw( SQLException, RuntimeException )
475 {
476 	MutexGuard aGuard( m_aMutex );
477 	::connectivity::checkDisposed(!m_xRowUpdate.is());
478 
479 	m_xRowUpdate->updateObject(m_nPos, x);
480 }
481 
482