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_connectivity.hxx"
26
27 #include "MacabResultSet.hxx"
28 #include "MacabAddressBook.hxx"
29 #include "MacabRecords.hxx"
30 #include "macabutilities.hxx"
31 #include "MacabResultSetMetaData.hxx"
32 #include "MacabConnection.hxx"
33 #include "macabcondition.hxx"
34 #include "macaborder.hxx"
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
37 #include "TConnection.hxx"
38 #include <connectivity/dbexception.hxx>
39 #include "resource/sharedresources.hxx"
40 #include "resource/macab_res.hrc"
41
42 using namespace connectivity::macab;
43 using namespace cppu;
44 using namespace com::sun::star::uno;
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::beans;
47 using namespace com::sun::star::sdbc;
48 using namespace com::sun::star::sdbcx;
49 using namespace com::sun::star::io;
50 using namespace com::sun::star::util;
51
52 IMPLEMENT_SERVICE_INFO(MacabResultSet, "com.sun.star.sdbc.drivers.MacabResultSet", "com.sun.star.sdbc.ResultSet");
53 // -------------------------------------------------------------------------
MacabResultSet(MacabCommonStatement * pStmt)54 MacabResultSet::MacabResultSet(MacabCommonStatement* pStmt)
55 : MacabResultSet_BASE(m_aMutex),
56 OPropertySetHelper(MacabResultSet_BASE::rBHelper),
57 m_xStatement(pStmt),
58 m_xMetaData(NULL),
59 m_aMacabRecords(),
60 m_nRowPos(-1),
61 m_bWasNull(sal_True)
62 {
63 m_sTableName = MacabAddressBook::getDefaultTableName();
64 }
65 // -------------------------------------------------------------------------
~MacabResultSet()66 MacabResultSet::~MacabResultSet()
67 {
68 }
69 // -------------------------------------------------------------------------
allMacabRecords()70 void MacabResultSet::allMacabRecords()
71 {
72 MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
73
74 m_aMacabRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
75 }
76 // -------------------------------------------------------------------------
someMacabRecords(const MacabCondition * pCondition)77 void MacabResultSet::someMacabRecords(const MacabCondition *pCondition)
78 {
79 MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get());
80 MacabRecords* allRecords;
81
82 allRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName);
83
84 // Bad table!! Throw exception?
85 if(allRecords == NULL)
86 return;
87
88 if(m_aMacabRecords != NULL && m_aMacabRecords != allRecords)
89 delete m_aMacabRecords;
90
91 // The copy constructor copies everything but records (including the
92 // maximum alloted size, which means that we'll never have to resize)
93 m_aMacabRecords = new MacabRecords(allRecords);
94
95 MacabRecords::iterator iterator;
96
97 for (iterator = allRecords->begin();
98 iterator != allRecords->end();
99 ++iterator)
100 {
101 if (pCondition->eval(*iterator))
102 m_aMacabRecords->insertRecord(*iterator);
103 }
104 }
105 // -------------------------------------------------------------------------
sortMacabRecords(const MacabOrder * pOrder)106 void MacabResultSet::sortMacabRecords(const MacabOrder *pOrder)
107 {
108 // I do this with ints rather than an iterator because the ids will
109 // be changing when we change the order and ints are easier to deal
110 // with (for me).
111 sal_Int32 i, j, size, smallest;
112 size = m_aMacabRecords->size();
113
114 for(i = 0; i < size; i++)
115 {
116 smallest = i;
117 for( j = i + 1; j < size; j++)
118 {
119 // if smallest > j
120 if(pOrder->compare(m_aMacabRecords->getRecord(smallest),
121 m_aMacabRecords->getRecord(j) ) > 0)
122 {
123 smallest = j;
124 }
125
126 }
127
128 if(smallest != i)
129 {
130 m_aMacabRecords->swap(i,smallest);
131 }
132 }
133
134 }
135 // -------------------------------------------------------------------------
setTableName(::rtl::OUString _sTableName)136 void MacabResultSet::setTableName(::rtl::OUString _sTableName)
137 {
138 m_sTableName = _sTableName;
139 }
140 // -------------------------------------------------------------------------
disposing()141 void MacabResultSet::disposing()
142 {
143 OPropertySetHelper::disposing();
144
145 ::osl::MutexGuard aGuard(m_aMutex);
146
147 m_xStatement.clear();
148 m_xMetaData.clear();
149 }
150 // -------------------------------------------------------------------------
queryInterface(const Type & rType)151 Any SAL_CALL MacabResultSet::queryInterface(const Type & rType) throw(RuntimeException)
152 {
153 Any aRet = OPropertySetHelper::queryInterface(rType);
154 if (!aRet.hasValue())
155 aRet = MacabResultSet_BASE::queryInterface(rType);
156 return aRet;
157 }
158 // -------------------------------------------------------------------------
acquire()159 void SAL_CALL MacabResultSet::acquire() throw()
160 {
161 MacabResultSet_BASE::acquire();
162 }
163 // -------------------------------------------------------------------------
release()164 void SAL_CALL MacabResultSet::release() throw()
165 {
166 MacabResultSet_BASE::release();
167 }
168 // -------------------------------------------------------------------------
getTypes()169 Sequence< Type > SAL_CALL MacabResultSet::getTypes() throw(RuntimeException)
170 {
171 OTypeCollection aTypes(
172 ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet >*) 0),
173 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet >*) 0),
174 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet >*) 0));
175
176 return comphelper::concatSequences(aTypes.getTypes(), MacabResultSet_BASE::getTypes());
177 }
178 // -------------------------------------------------------------------------
getPropertySetInfo()179 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL MacabResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
180 {
181 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
182 }
183 // -------------------------------------------------------------------------
findColumn(const::rtl::OUString & columnName)184 sal_Int32 SAL_CALL MacabResultSet::findColumn(const ::rtl::OUString& columnName) throw(SQLException, RuntimeException)
185 {
186 ::osl::MutexGuard aGuard( m_aMutex );
187 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
188
189 // find the first column with the name columnName
190 Reference< XResultSetMetaData > xMeta = getMetaData();
191 sal_Int32 nLen = xMeta->getColumnCount();
192
193 for (sal_Int32 i = 1; i <= nLen; ++i)
194 if (xMeta->isCaseSensitive(i) ?
195 columnName == xMeta->getColumnName(i) :
196 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
197 return i;
198
199 ::connectivity::SharedResources aResources;
200 const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
201 STR_NO_ELEMENT_NAME,
202 "$name$", columnName
203 ) );
204 ::dbtools::throwGenericSQLException(sError , *this);
205 // Unreachable:
206 OSL_ASSERT(false);
207 return 0;
208 }
209 // -------------------------------------------------------------------------
getString(sal_Int32 columnIndex)210 ::rtl::OUString SAL_CALL MacabResultSet::getString(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
211 {
212 ::osl::MutexGuard aGuard( m_aMutex );
213 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
214
215 ::rtl::OUString aRet;
216 sal_Int32 nRecords = m_aMacabRecords->size();
217 m_bWasNull = true;
218
219 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
220 {
221 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
222 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
223 if(aField != NULL)
224 {
225 if(aField->type == kABStringProperty)
226 {
227 aRet = CFStringToOUString( (CFStringRef) aField->value);
228 m_bWasNull = false;
229 }
230 }
231 }
232
233 // Trigger an exception if m_bWasNull is true?
234 return aRet;
235 }
236 // -------------------------------------------------------------------------
getBoolean(sal_Int32)237 sal_Bool SAL_CALL MacabResultSet::getBoolean(sal_Int32) throw(SQLException, RuntimeException)
238 {
239 ::osl::MutexGuard aGuard( m_aMutex );
240 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
241
242 ::dbtools::throwFunctionNotSupportedException("getBoolean", NULL);
243
244 return sal_False;
245 }
246 // -------------------------------------------------------------------------
getByte(sal_Int32)247 sal_Int8 SAL_CALL MacabResultSet::getByte(sal_Int32) throw(SQLException, RuntimeException)
248 {
249 ::osl::MutexGuard aGuard( m_aMutex );
250 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
251
252 ::dbtools::throwFunctionNotSupportedException("getByte", NULL);
253
254 sal_Int8 nRet = 0;
255 return nRet;
256 }
257 // -------------------------------------------------------------------------
getShort(sal_Int32)258 sal_Int16 SAL_CALL MacabResultSet::getShort(sal_Int32) throw(SQLException, RuntimeException)
259 {
260 ::osl::MutexGuard aGuard( m_aMutex );
261 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
262
263 ::dbtools::throwFunctionNotSupportedException("getShort", NULL);
264
265 sal_Int16 nRet = 0;
266 return nRet;
267 }
268 // -------------------------------------------------------------------------
getInt(sal_Int32 columnIndex)269 sal_Int32 SAL_CALL MacabResultSet::getInt(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
270 {
271 ::osl::MutexGuard aGuard( m_aMutex );
272 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
273
274 sal_Int32 nRet = 0;
275 sal_Int32 nRecords = m_aMacabRecords->size();
276 m_bWasNull = true;
277
278 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
279 {
280 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
281 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
282 if(aField != NULL)
283 {
284 if(aField->type == kABIntegerProperty)
285 {
286 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
287 // m_bWasNull now becomes whether getting the value was successful
288 // Should we check for the wrong type here, e.g., a float or a 64 bit int?
289 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nRet);
290 }
291 }
292 }
293
294 // Trigger an exception if m_bWasNull is true?
295 return nRet;
296 }
297 // -------------------------------------------------------------------------
getLong(sal_Int32 columnIndex)298 sal_Int64 SAL_CALL MacabResultSet::getLong(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
299 {
300 ::osl::MutexGuard aGuard( m_aMutex );
301 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
302
303 sal_Int64 nRet = 0;
304 sal_Int32 nRecords = m_aMacabRecords->size();
305 m_bWasNull = true;
306
307 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
308 {
309 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
310 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
311 if(aField != NULL)
312 {
313 if(aField->type == kABIntegerProperty)
314 {
315 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
316 // m_bWasNull now becomes whether getting the value was successful
317 // Should we check for the wrong type here, e.g., a float or a 32 bit int?
318 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nRet);
319 }
320 }
321 }
322
323 // Trigger an exception if m_bWasNull is true?
324 return nRet;
325 }
326 // -------------------------------------------------------------------------
getFloat(sal_Int32 columnIndex)327 float SAL_CALL MacabResultSet::getFloat(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
328 {
329 ::osl::MutexGuard aGuard( m_aMutex );
330 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
331
332 float nVal = 0;
333 sal_Int32 nRecords = m_aMacabRecords->size();
334 m_bWasNull = true;
335
336 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
337 {
338 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
339 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
340 if(aField != NULL)
341 {
342 if(aField->type == kABRealProperty)
343 {
344 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
345 // m_bWasNull now becomes whether getting the value was successful
346 // Should we check for the wrong type here, e.g., an int or a double?
347 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nVal);
348 }
349 }
350 }
351
352 // Trigger an exception if m_bWasNull is true?
353 return nVal;
354 }
355 // -------------------------------------------------------------------------
getDouble(sal_Int32 columnIndex)356 double SAL_CALL MacabResultSet::getDouble(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
357 {
358 ::osl::MutexGuard aGuard( m_aMutex );
359 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
360
361 double nVal = 0;
362 sal_Int32 nRecords = m_aMacabRecords->size();
363 m_bWasNull = true;
364
365 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
366 {
367 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
368 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
369 if(aField != NULL)
370 {
371 if(aField->type == kABRealProperty)
372 {
373 CFNumberType numberType = CFNumberGetType( (CFNumberRef) aField->value );
374 // m_bWasNull now becomes whether getting the value was successful
375 // Should we check for the wrong type here, e.g., an int or a float?
376 m_bWasNull = !CFNumberGetValue((CFNumberRef) aField->value, numberType, &nVal);
377 }
378 }
379 }
380
381 // Trigger an exception if m_bWasNull is true?
382 return nVal;
383 }
384 // -------------------------------------------------------------------------
getBytes(sal_Int32)385 Sequence< sal_Int8 > SAL_CALL MacabResultSet::getBytes(sal_Int32) throw(SQLException, RuntimeException)
386 {
387 ::osl::MutexGuard aGuard( m_aMutex );
388 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
389
390 ::dbtools::throwFunctionNotSupportedException("getBytes", NULL);
391
392 return Sequence< sal_Int8 >();
393 }
394 // -------------------------------------------------------------------------
getDate(sal_Int32)395 Date SAL_CALL MacabResultSet::getDate(sal_Int32) throw(SQLException, RuntimeException)
396 {
397 ::osl::MutexGuard aGuard( m_aMutex );
398 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
399
400 ::dbtools::throwFunctionNotSupportedException("getDate", NULL);
401
402 Date aRet;
403 return aRet;
404 }
405 // -------------------------------------------------------------------------
getTime(sal_Int32)406 Time SAL_CALL MacabResultSet::getTime(sal_Int32) throw(SQLException, RuntimeException)
407 {
408 ::osl::MutexGuard aGuard( m_aMutex );
409 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
410
411 ::dbtools::throwFunctionNotSupportedException("getTime", NULL);
412
413 Time nRet;
414 return nRet;
415 }
416 // -------------------------------------------------------------------------
getTimestamp(sal_Int32 columnIndex)417 DateTime SAL_CALL MacabResultSet::getTimestamp(sal_Int32 columnIndex) throw(SQLException, RuntimeException)
418 {
419 ::osl::MutexGuard aGuard( m_aMutex );
420 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
421
422 DateTime nRet;
423 sal_Int32 nRecords = m_aMacabRecords->size();
424 m_bWasNull = true;
425
426 if (m_nRowPos != -1 && m_nRowPos != nRecords && m_xMetaData.is())
427 {
428 sal_Int32 nFieldNumber = m_xMetaData->fieldAtColumn(columnIndex);
429 macabfield *aField = m_aMacabRecords->getField(m_nRowPos,nFieldNumber);
430 if(aField != NULL)
431 {
432 if(aField->type == kABDateProperty)
433 {
434 nRet = CFDateToDateTime((CFDateRef) aField->value);
435 m_bWasNull = false;
436 }
437 }
438 }
439
440 // Trigger an exception if m_bWasNull is true?
441 return nRet;
442 }
443 // -------------------------------------------------------------------------
getBinaryStream(sal_Int32)444 Reference< XInputStream > SAL_CALL MacabResultSet::getBinaryStream(sal_Int32) throw(SQLException, RuntimeException)
445 {
446 ::osl::MutexGuard aGuard( m_aMutex );
447 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
448
449 ::dbtools::throwFunctionNotSupportedException("getBinaryStream", NULL);
450
451 return NULL;
452 }
453 // -------------------------------------------------------------------------
getCharacterStream(sal_Int32)454 Reference< XInputStream > SAL_CALL MacabResultSet::getCharacterStream(sal_Int32) throw(SQLException, RuntimeException)
455 {
456 ::osl::MutexGuard aGuard( m_aMutex );
457 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
458
459 ::dbtools::throwFunctionNotSupportedException("getCharacterStream", NULL);
460
461 return NULL;
462 }
463 // -------------------------------------------------------------------------
getObject(sal_Int32,const Reference<::com::sun::star::container::XNameAccess> &)464 Any SAL_CALL MacabResultSet::getObject(sal_Int32, const Reference< ::com::sun::star::container::XNameAccess >&) throw(SQLException, RuntimeException)
465 {
466 ::osl::MutexGuard aGuard( m_aMutex );
467 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
468
469 ::dbtools::throwFunctionNotSupportedException("getObject", NULL);
470
471 return Any();
472 }
473 // -------------------------------------------------------------------------
getRef(sal_Int32)474 Reference< XRef > SAL_CALL MacabResultSet::getRef(sal_Int32) throw(SQLException, RuntimeException)
475 {
476 ::osl::MutexGuard aGuard( m_aMutex );
477 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
478
479 ::dbtools::throwFunctionNotSupportedException("getRef", NULL);
480
481 return NULL;
482 }
483 // -------------------------------------------------------------------------
getBlob(sal_Int32)484 Reference< XBlob > SAL_CALL MacabResultSet::getBlob(sal_Int32) throw(SQLException, RuntimeException)
485 {
486 ::osl::MutexGuard aGuard( m_aMutex );
487 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
488
489 ::dbtools::throwFunctionNotSupportedException("getBlob", NULL);
490
491 return NULL;
492 }
493 // -------------------------------------------------------------------------
getClob(sal_Int32)494 Reference< XClob > SAL_CALL MacabResultSet::getClob(sal_Int32) throw(SQLException, RuntimeException)
495 {
496 ::osl::MutexGuard aGuard( m_aMutex );
497 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
498
499 ::dbtools::throwFunctionNotSupportedException("getClob", NULL);
500
501 return NULL;
502 }
503 // -------------------------------------------------------------------------
getArray(sal_Int32)504 Reference< XArray > SAL_CALL MacabResultSet::getArray(sal_Int32) throw(SQLException, RuntimeException)
505 {
506 ::osl::MutexGuard aGuard( m_aMutex );
507 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
508
509 ::dbtools::throwFunctionNotSupportedException("getArray", NULL);
510
511 return NULL;
512 }
513 // -------------------------------------------------------------------------
getMetaData()514 Reference< XResultSetMetaData > SAL_CALL MacabResultSet::getMetaData() throw(SQLException, RuntimeException)
515 {
516 ::osl::MutexGuard aGuard( m_aMutex );
517 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
518
519 if (!m_xMetaData.is())
520 m_xMetaData = new MacabResultSetMetaData(m_xStatement->getOwnConnection(), m_sTableName);
521
522 Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
523 return xMetaData;
524 }
525 // -------------------------------------------------------------------------
isBeforeFirst()526 sal_Bool SAL_CALL MacabResultSet::isBeforeFirst() throw(SQLException, RuntimeException)
527 {
528 ::osl::MutexGuard aGuard( m_aMutex );
529 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
530
531 if (m_nRowPos == -1)
532 return sal_True;
533
534 return sal_False;
535 }
536 // -------------------------------------------------------------------------
isAfterLast()537 sal_Bool SAL_CALL MacabResultSet::isAfterLast() throw(SQLException, RuntimeException)
538 {
539 ::osl::MutexGuard aGuard( m_aMutex );
540 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
541
542 sal_Int32 nRecords = m_aMacabRecords->size();
543 if (m_nRowPos == nRecords)
544 return sal_True;
545
546 return sal_False;
547 }
548 // -------------------------------------------------------------------------
isFirst()549 sal_Bool SAL_CALL MacabResultSet::isFirst() throw(SQLException, RuntimeException)
550 {
551 ::osl::MutexGuard aGuard( m_aMutex );
552 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
553
554 if (m_nRowPos == 0)
555 return sal_True;
556
557 return sal_False;
558 }
559 // -------------------------------------------------------------------------
isLast()560 sal_Bool SAL_CALL MacabResultSet::isLast() throw(SQLException, RuntimeException)
561 {
562 ::osl::MutexGuard aGuard( m_aMutex );
563 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
564
565 sal_Int32 nRecords = m_aMacabRecords->size();
566 if (m_nRowPos == nRecords - 1)
567 return sal_True;
568
569 return sal_False;
570 }
571 // -------------------------------------------------------------------------
beforeFirst()572 void SAL_CALL MacabResultSet::beforeFirst() throw(SQLException, RuntimeException)
573 {
574 ::osl::MutexGuard aGuard( m_aMutex );
575 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
576
577 // move before the first row
578 m_nRowPos = -1;
579 }
580 // -------------------------------------------------------------------------
afterLast()581 void SAL_CALL MacabResultSet::afterLast() throw(SQLException, RuntimeException)
582 {
583 ::osl::MutexGuard aGuard( m_aMutex );
584 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
585
586 // move after the last row
587 sal_Int32 nRecords = m_aMacabRecords->size();
588 m_nRowPos = nRecords;
589 }
590 // -------------------------------------------------------------------------
close()591 void SAL_CALL MacabResultSet::close() throw(SQLException, RuntimeException)
592 {
593 {
594 ::osl::MutexGuard aGuard( m_aMutex );
595 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
596 }
597 dispose();
598 }
599 // -------------------------------------------------------------------------
first()600 sal_Bool SAL_CALL MacabResultSet::first() throw(SQLException, RuntimeException)
601 {
602 ::osl::MutexGuard aGuard( m_aMutex );
603 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
604
605 sal_Int32 nRecords = m_aMacabRecords->size();
606 if (nRecords == 0)
607 return sal_False;
608
609 m_nRowPos = 0;
610 return sal_True;
611 }
612 // -------------------------------------------------------------------------
last()613 sal_Bool SAL_CALL MacabResultSet::last() throw(SQLException, RuntimeException)
614 {
615 ::osl::MutexGuard aGuard( m_aMutex );
616 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
617
618 sal_Int32 nRecords = m_aMacabRecords->size();
619 if (nRecords == 0)
620 return sal_False;
621
622 m_nRowPos = nRecords - 1;
623 return sal_True;
624 }
625 // -------------------------------------------------------------------------
getRow()626 sal_Int32 SAL_CALL MacabResultSet::getRow() throw(SQLException, RuntimeException)
627 {
628 ::osl::MutexGuard aGuard( m_aMutex );
629 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
630
631 return m_nRowPos;
632 }
633 // -------------------------------------------------------------------------
absolute(sal_Int32 row)634 sal_Bool SAL_CALL MacabResultSet::absolute(sal_Int32 row) throw(SQLException, RuntimeException)
635 {
636 ::osl::MutexGuard aGuard( m_aMutex );
637 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
638
639 sal_Int32 nRecords = m_aMacabRecords->size();
640 if (row <= -1 ||
641 row >= nRecords)
642 return sal_False;
643
644 m_nRowPos = row;
645 return sal_True;
646 }
647 // -------------------------------------------------------------------------
relative(sal_Int32 row)648 sal_Bool SAL_CALL MacabResultSet::relative(sal_Int32 row) throw(SQLException, RuntimeException)
649 {
650 ::osl::MutexGuard aGuard( m_aMutex );
651 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
652
653 return absolute(m_nRowPos + row);
654 }
655 // -------------------------------------------------------------------------
next()656 sal_Bool SAL_CALL MacabResultSet::next() throw(SQLException, RuntimeException)
657 {
658 ::osl::MutexGuard aGuard( m_aMutex );
659 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
660
661 return absolute(m_nRowPos + 1);
662 }
663 // -------------------------------------------------------------------------
previous()664 sal_Bool SAL_CALL MacabResultSet::previous() throw(SQLException, RuntimeException)
665 {
666 ::osl::MutexGuard aGuard( m_aMutex );
667 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
668
669 return absolute(m_nRowPos - 1);
670 }
671 // -------------------------------------------------------------------------
getStatement()672 Reference< XInterface > SAL_CALL MacabResultSet::getStatement() throw(SQLException, RuntimeException)
673 {
674 ::osl::MutexGuard aGuard( m_aMutex );
675 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
676
677 Reference< XStatement > xStatement = m_xStatement.get();
678 return xStatement;
679 }
680 // -------------------------------------------------------------------------
rowDeleted()681 sal_Bool SAL_CALL MacabResultSet::rowDeleted() throw(SQLException, RuntimeException)
682 {
683 ::osl::MutexGuard aGuard( m_aMutex );
684 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
685
686 return sal_False;
687 }
688 // -------------------------------------------------------------------------
rowInserted()689 sal_Bool SAL_CALL MacabResultSet::rowInserted() throw(SQLException, RuntimeException)
690 {
691 ::osl::MutexGuard aGuard( m_aMutex );
692 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
693
694 return sal_False;
695 }
696 // -------------------------------------------------------------------------
rowUpdated()697 sal_Bool SAL_CALL MacabResultSet::rowUpdated() throw(SQLException, RuntimeException)
698 {
699 ::osl::MutexGuard aGuard( m_aMutex );
700 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
701
702 return sal_False;
703 }
704 // -------------------------------------------------------------------------
wasNull()705 sal_Bool SAL_CALL MacabResultSet::wasNull() throw(SQLException, RuntimeException)
706 {
707 ::osl::MutexGuard aGuard( m_aMutex );
708 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
709
710 return m_bWasNull;
711 }
712 // -------------------------------------------------------------------------
cancel()713 void SAL_CALL MacabResultSet::cancel() throw(RuntimeException)
714 {
715 ::osl::MutexGuard aGuard( m_aMutex );
716 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
717 }
718 // -------------------------------------------------------------------------
clearWarnings()719 void SAL_CALL MacabResultSet::clearWarnings() throw(SQLException, RuntimeException)
720 {
721 }
722 // -------------------------------------------------------------------------
getWarnings()723 Any SAL_CALL MacabResultSet::getWarnings() throw(SQLException, RuntimeException)
724 {
725 return Any();
726 }
727 // -------------------------------------------------------------------------
insertRow()728 void SAL_CALL MacabResultSet::insertRow() throw(SQLException, RuntimeException)
729 {
730 ::osl::MutexGuard aGuard( m_aMutex );
731 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
732
733 // you only have to implement this if you want to insert new rows
734 }
735 // -------------------------------------------------------------------------
updateRow()736 void SAL_CALL MacabResultSet::updateRow() throw(SQLException, RuntimeException)
737 {
738 ::osl::MutexGuard aGuard( m_aMutex );
739 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
740
741 // only when you allow updates
742 }
743 // -------------------------------------------------------------------------
deleteRow()744 void SAL_CALL MacabResultSet::deleteRow() throw(SQLException, RuntimeException)
745 {
746 ::osl::MutexGuard aGuard( m_aMutex );
747 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
748 }
749 // -------------------------------------------------------------------------
cancelRowUpdates()750 void SAL_CALL MacabResultSet::cancelRowUpdates() throw(SQLException, RuntimeException)
751 {
752 ::osl::MutexGuard aGuard( m_aMutex );
753 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
754 }
755 // -------------------------------------------------------------------------
moveToInsertRow()756 void SAL_CALL MacabResultSet::moveToInsertRow() throw(SQLException, RuntimeException)
757 {
758 ::osl::MutexGuard aGuard( m_aMutex );
759 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
760
761 // only when you allow inserts
762 }
763 // -------------------------------------------------------------------------
moveToCurrentRow()764 void SAL_CALL MacabResultSet::moveToCurrentRow() throw(SQLException, RuntimeException)
765 {
766 ::osl::MutexGuard aGuard( m_aMutex );
767 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
768 }
769 // -------------------------------------------------------------------------
updateNull(sal_Int32)770 void SAL_CALL MacabResultSet::updateNull(sal_Int32) throw(SQLException, RuntimeException)
771 {
772 ::osl::MutexGuard aGuard( m_aMutex );
773 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
774 }
775 // -------------------------------------------------------------------------
updateBoolean(sal_Int32,sal_Bool)776 void SAL_CALL MacabResultSet::updateBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException)
777 {
778 ::osl::MutexGuard aGuard( m_aMutex );
779 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
780 }
781 // -------------------------------------------------------------------------
updateByte(sal_Int32,sal_Int8)782 void SAL_CALL MacabResultSet::updateByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException)
783 {
784 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
785 ::osl::MutexGuard aGuard( m_aMutex );
786 }
787 // -------------------------------------------------------------------------
updateShort(sal_Int32,sal_Int16)788 void SAL_CALL MacabResultSet::updateShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException)
789 {
790 ::osl::MutexGuard aGuard( m_aMutex );
791 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
792 }
793 // -------------------------------------------------------------------------
updateInt(sal_Int32,sal_Int32)794 void SAL_CALL MacabResultSet::updateInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
795 {
796 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
797 ::osl::MutexGuard aGuard( m_aMutex );
798 }
799 // -------------------------------------------------------------------------
updateLong(sal_Int32,sal_Int64)800 void SAL_CALL MacabResultSet::updateLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException)
801 {
802 ::osl::MutexGuard aGuard( m_aMutex );
803 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
804 }
805 // -----------------------------------------------------------------------
updateFloat(sal_Int32,float)806 void SAL_CALL MacabResultSet::updateFloat(sal_Int32, float) throw(SQLException, RuntimeException)
807 {
808 ::osl::MutexGuard aGuard( m_aMutex );
809 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
810 }
811 // -------------------------------------------------------------------------
updateDouble(sal_Int32,double)812 void SAL_CALL MacabResultSet::updateDouble(sal_Int32, double) throw(SQLException, RuntimeException)
813 {
814 ::osl::MutexGuard aGuard( m_aMutex );
815 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
816 }
817 // -------------------------------------------------------------------------
updateString(sal_Int32,const::rtl::OUString &)818 void SAL_CALL MacabResultSet::updateString(sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException)
819 {
820 ::osl::MutexGuard aGuard( m_aMutex );
821 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
822 }
823 // -------------------------------------------------------------------------
updateBytes(sal_Int32,const Sequence<sal_Int8> &)824 void SAL_CALL MacabResultSet::updateBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException)
825 {
826 ::osl::MutexGuard aGuard( m_aMutex );
827 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
828 }
829 // -------------------------------------------------------------------------
updateDate(sal_Int32,const Date &)830 void SAL_CALL MacabResultSet::updateDate(sal_Int32, const Date&) throw(SQLException, RuntimeException)
831 {
832 ::osl::MutexGuard aGuard( m_aMutex );
833 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
834 }
835 // -------------------------------------------------------------------------
updateTime(sal_Int32,const Time &)836 void SAL_CALL MacabResultSet::updateTime(sal_Int32, const Time&) throw(SQLException, RuntimeException)
837 {
838 ::osl::MutexGuard aGuard( m_aMutex );
839 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
840 }
841 // -------------------------------------------------------------------------
updateTimestamp(sal_Int32,const DateTime &)842 void SAL_CALL MacabResultSet::updateTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException)
843 {
844 ::osl::MutexGuard aGuard( m_aMutex );
845 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
846 }
847 // -------------------------------------------------------------------------
updateBinaryStream(sal_Int32,const Reference<XInputStream> &,sal_Int32)848 void SAL_CALL MacabResultSet::updateBinaryStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
849 {
850 ::osl::MutexGuard aGuard( m_aMutex );
851 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
852 }
853 // -------------------------------------------------------------------------
updateCharacterStream(sal_Int32,const Reference<XInputStream> &,sal_Int32)854 void SAL_CALL MacabResultSet::updateCharacterStream(sal_Int32, const Reference< XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
855 {
856 ::osl::MutexGuard aGuard( m_aMutex );
857 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
858 }
859 // -------------------------------------------------------------------------
refreshRow()860 void SAL_CALL MacabResultSet::refreshRow() throw(SQLException, RuntimeException)
861 {
862 ::osl::MutexGuard aGuard( m_aMutex );
863 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
864 }
865 // -------------------------------------------------------------------------
updateObject(sal_Int32,const Any &)866 void SAL_CALL MacabResultSet::updateObject(sal_Int32, const Any&) throw(SQLException, RuntimeException)
867 {
868 ::osl::MutexGuard aGuard( m_aMutex );
869 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
870 }
871 // -------------------------------------------------------------------------
updateNumericObject(sal_Int32,const Any &,sal_Int32)872 void SAL_CALL MacabResultSet::updateNumericObject(sal_Int32, const Any&, sal_Int32) throw(SQLException, RuntimeException)
873 {
874 ::osl::MutexGuard aGuard( m_aMutex );
875 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
876 }
877 // -------------------------------------------------------------------------
878 // XRowLocate
getBookmark()879 Any SAL_CALL MacabResultSet::getBookmark() throw( SQLException, RuntimeException)
880 {
881 ::osl::MutexGuard aGuard( m_aMutex );
882 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
883
884 sal_Int32 nRecords = m_aMacabRecords->size();
885
886 if (m_nRowPos != -1 && m_nRowPos != nRecords)
887 {
888 macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,::rtl::OUString::createFromAscii("UID"));
889 if(uidField != NULL)
890 {
891 if(uidField->type == kABStringProperty)
892 {
893 return makeAny(CFStringToOUString( (CFStringRef) uidField->value ));
894 }
895 }
896 }
897 return Any();
898 }
899 // -------------------------------------------------------------------------
moveToBookmark(const Any & bookmark)900 sal_Bool SAL_CALL MacabResultSet::moveToBookmark(const Any& bookmark) throw( SQLException, RuntimeException)
901 {
902 ::osl::MutexGuard aGuard( m_aMutex );
903 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
904
905 ::rtl::OUString sBookmark = comphelper::getString(bookmark);
906 sal_Int32 nRecords = m_aMacabRecords->size();
907
908 for (sal_Int32 nRow = 0; nRow < nRecords; nRow++)
909 {
910 macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,::rtl::OUString::createFromAscii("UID"));
911 if(uidField != NULL)
912 {
913 if(uidField->type == kABStringProperty)
914 {
915 ::rtl::OUString sUniqueIdentifier = CFStringToOUString( (CFStringRef) uidField->value );
916 if (sUniqueIdentifier == sBookmark)
917 {
918 m_nRowPos = nRow;
919 return sal_True;
920 }
921 }
922 }
923 }
924 return sal_False;
925 }
926 // -------------------------------------------------------------------------
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)927 sal_Bool SAL_CALL MacabResultSet::moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows) throw( SQLException, RuntimeException)
928 {
929 ::osl::MutexGuard aGuard( m_aMutex );
930 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
931
932 sal_Int32 nRowSave = m_nRowPos;
933
934 if (moveToBookmark(bookmark))
935 {
936 sal_Int32 nRecords = m_aMacabRecords->size();
937
938 m_nRowPos += rows;
939
940 if (-1 < m_nRowPos && m_nRowPos < nRecords)
941 return sal_True;
942 }
943
944 m_nRowPos = nRowSave;
945 return sal_False;
946 }
947 // -------------------------------------------------------------------------
compareBookmarks(const Any & firstItem,const Any & secondItem)948 sal_Int32 SAL_CALL MacabResultSet::compareBookmarks(const Any& firstItem, const Any& secondItem) throw( SQLException, RuntimeException)
949 {
950 ::osl::MutexGuard aGuard( m_aMutex );
951 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
952
953 ::rtl::OUString sFirst = comphelper::getString(firstItem);
954 ::rtl::OUString sSecond = comphelper::getString(secondItem);
955
956 if (sFirst < sSecond)
957 return CompareBookmark::LESS;
958 if (sFirst > sSecond)
959 return CompareBookmark::GREATER;
960 return CompareBookmark::EQUAL;
961 }
962 // -------------------------------------------------------------------------
hasOrderedBookmarks()963 sal_Bool SAL_CALL MacabResultSet::hasOrderedBookmarks() throw( SQLException, RuntimeException)
964 {
965 return sal_False;
966 }
967 // -------------------------------------------------------------------------
hashBookmark(const Any & bookmark)968 sal_Int32 SAL_CALL MacabResultSet::hashBookmark(const Any& bookmark) throw( SQLException, RuntimeException)
969 {
970 ::osl::MutexGuard aGuard( m_aMutex );
971 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
972
973 ::rtl::OUString sBookmark = comphelper::getString(bookmark);
974
975 return sBookmark.hashCode();
976 }
977 // -------------------------------------------------------------------------
978 // XDeleteRows
deleteRows(const Sequence<Any> &)979 Sequence< sal_Int32 > SAL_CALL MacabResultSet::deleteRows(const Sequence< Any >&) throw( SQLException, RuntimeException)
980 {
981 ::osl::MutexGuard aGuard( m_aMutex );
982 checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed);
983
984 return Sequence< sal_Int32 >();
985 }
986 // -------------------------------------------------------------------------
createArrayHelper() const987 IPropertyArrayHelper* MacabResultSet::createArrayHelper() const
988 {
989 Sequence< Property > aProps(6);
990 Property* pProperties = aProps.getArray();
991 sal_Int32 nPos = 0;
992 DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY);
993 DECL_PROP0(FETCHDIRECTION, sal_Int32);
994 DECL_PROP0(FETCHSIZE, sal_Int32);
995 DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
996 DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
997 DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY);
998
999 return new OPropertyArrayHelper(aProps);
1000 }
1001 // -------------------------------------------------------------------------
getInfoHelper()1002 IPropertyArrayHelper & MacabResultSet::getInfoHelper()
1003 {
1004 return *static_cast<MacabResultSet*>(this)->getArrayHelper();
1005 }
1006 // -------------------------------------------------------------------------
convertFastPropertyValue(Any &,Any &,sal_Int32 nHandle,const Any &)1007 sal_Bool MacabResultSet::convertFastPropertyValue(
1008 Any &,
1009 Any &,
1010 sal_Int32 nHandle,
1011 const Any& )
1012 throw (::com::sun::star::lang::IllegalArgumentException)
1013 {
1014 switch (nHandle)
1015 {
1016 case PROPERTY_ID_ISBOOKMARKABLE:
1017 case PROPERTY_ID_CURSORNAME:
1018 case PROPERTY_ID_RESULTSETCONCURRENCY:
1019 case PROPERTY_ID_RESULTSETTYPE:
1020 throw ::com::sun::star::lang::IllegalArgumentException();
1021 break;
1022 case PROPERTY_ID_FETCHDIRECTION:
1023 case PROPERTY_ID_FETCHSIZE:
1024 default:
1025 ;
1026 }
1027 return sal_False;
1028 }
1029 // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any &)1030 void MacabResultSet::setFastPropertyValue_NoBroadcast(
1031 sal_Int32 nHandle,
1032 const Any& )
1033 throw (Exception)
1034 {
1035 switch (nHandle)
1036 {
1037 case PROPERTY_ID_ISBOOKMARKABLE:
1038 case PROPERTY_ID_CURSORNAME:
1039 case PROPERTY_ID_RESULTSETCONCURRENCY:
1040 case PROPERTY_ID_RESULTSETTYPE:
1041 throw Exception();
1042 break;
1043 case PROPERTY_ID_FETCHDIRECTION:
1044 break;
1045 case PROPERTY_ID_FETCHSIZE:
1046 break;
1047 default:
1048 ;
1049 }
1050 }
1051 // -------------------------------------------------------------------------
getFastPropertyValue(Any & _rValue,sal_Int32 nHandle) const1052 void MacabResultSet::getFastPropertyValue(
1053 Any& _rValue,
1054 sal_Int32 nHandle) const
1055 {
1056 switch (nHandle)
1057 {
1058 case PROPERTY_ID_ISBOOKMARKABLE:
1059 _rValue <<= (sal_Bool)sal_False;
1060 break;
1061 case PROPERTY_ID_CURSORNAME:
1062 case PROPERTY_ID_RESULTSETCONCURRENCY:
1063 case PROPERTY_ID_RESULTSETTYPE:
1064 case PROPERTY_ID_FETCHDIRECTION:
1065 case PROPERTY_ID_FETCHSIZE:
1066 ;
1067 }
1068 }
1069 // -----------------------------------------------------------------------------
1070