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