2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIo_DataSetEnumeratorImpl.cpp
20 * @brief This is the implementation file for _DataSetEnumeratorImpl class.
24 #include <semaphore.h>
26 #include <unique_ptr.h>
28 #include <FBaseInteger.h>
29 #include <FBaseDouble.h>
30 #include <FBaseString.h>
31 #include <FBaseByteBuffer.h>
32 #include <FBaseDateTime.h>
33 #include <FBaseUtilStringUtil.h>
34 #include <FBaseColLinkedList.h>
35 #include <FBaseColArrayList.h>
36 #include <FBaseColIEnumerator.h>
37 #include <FBaseSysLog.h>
39 #include <FIoDbTypes.h>
40 #include <FIo_DataSetEnumeratorImpl.h>
41 #include <FIo_DataRowImpl.h>
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Utility;
46 using namespace Tizen::Base::Runtime;
47 using namespace Tizen::System;
48 using namespace Tizen::App;
49 using namespace Tizen::Base::Collection;
51 namespace Tizen { namespace Io
54 _DataSetEnumeratorImpl::_DataSetEnumeratorImpl(void)
65 _DataSetEnumeratorImpl::~_DataSetEnumeratorImpl(void)
71 _DataSetEnumeratorImpl::MoveNext(void)
73 if (__currentRowIndex +1 == __rowCount)
74 return E_OUT_OF_RANGE;
77 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
79 if (__pCurrentRow == null)
80 return E_INVALID_STATE;
86 _DataSetEnumeratorImpl::MovePrevious(void)
88 if (__currentRowIndex == 0)
89 return E_OUT_OF_RANGE;
92 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
94 if (__pCurrentRow == null)
95 return E_INVALID_STATE;
101 _DataSetEnumeratorImpl::MoveFirst(void)
103 __currentRowIndex = 0;
104 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
106 if (__pCurrentRow == null)
107 return E_INVALID_STATE;
113 _DataSetEnumeratorImpl::MoveLast(void)
115 __currentRowIndex = __rowCount -1;
116 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
118 if (__pCurrentRow == null)
119 return E_INVALID_STATE;
125 _DataSetEnumeratorImpl::Reset(void)
127 __currentRowIndex = -1;
128 __pCurrentRow = null;
134 _DataSetEnumeratorImpl::GetIntAt(int columnIndex, int& value) const
136 result r = E_SUCCESS;
138 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
139 "The Object is not constructed or the dataset is already been deleted.");
140 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
141 "Given column index is out of range.");
142 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
143 "The method has tried to fetch the column data of a result set that is not activated.");
145 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
148 if (pDataItem->type != DB_COLUMNTYPE_INT)
151 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
155 value = pDataItem->intValue;
164 _DataSetEnumeratorImpl::GetInt64At(int columnIndex, long long& value) const
166 result r = E_SUCCESS;
168 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
169 "The Object is not constructed or the dataset is already been deleted.");
170 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
171 "Given column index is out of range.");
172 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
173 "The method has tried to fetch the column data of a result set that is not activated.");
175 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
178 if (pDataItem->type != DB_COLUMNTYPE_INT64)
181 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
185 value = pDataItem->int64Value;
194 _DataSetEnumeratorImpl::GetDoubleAt(int columnIndex, double& value) const
196 result r = E_SUCCESS;
198 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
199 "The Object is not constructed or the dataset is already been deleted.");
200 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
201 "Given column index is out of range.");
202 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
203 "The method has tried to fetch the column data of a result set that is not activated.");
205 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
208 if (pDataItem->type != DB_COLUMNTYPE_DOUBLE)
211 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
215 value = pDataItem->doubleValue;
224 _DataSetEnumeratorImpl::GetStringAt(int columnIndex, String& value) const
226 result r = E_SUCCESS;
228 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
229 "The Object is not constructed or the dataset is already been deleted.");
230 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
231 "Given column index is out of range.");
232 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
233 "The method has tried to fetch the column data of a result set that is not activated.");
235 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
238 if (pDataItem->type != DB_COLUMNTYPE_TEXT)
241 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
245 value = *((String*)pDataItem->pObj);
253 _DataSetEnumeratorImpl::GetBlobAt(int columnIndex, ByteBuffer& value) const
255 result r = E_SUCCESS;
256 ByteBuffer* pBuffer = null;
258 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
259 "The Object is not constructed or the dataset is already been deleted.");
260 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
261 "Given column index is out of range.");
262 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
263 "The method has tried to fetch the column data of a result set that is not activated.");
265 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
268 if (pDataItem->type != DB_COLUMNTYPE_BLOB)
271 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
275 pBuffer = (ByteBuffer*)pDataItem->pObj;
276 pBuffer->SetPosition(0);
277 r = value.CopyFrom(*pBuffer);
286 _DataSetEnumeratorImpl::GetBlobAt(int columnIndex, void* buffer, int size) const
288 result r = E_SUCCESS;
290 ByteBuffer* pBuffer = null;
292 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
293 "The Object is not constructed or the dataset is already been deleted.");
294 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
295 "Given column index is out of range.");
296 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
297 "The method has tried to fetch the column data of a result set that is not activated.");
299 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
302 if (pDataItem->type != DB_COLUMNTYPE_BLOB)
305 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
309 pBuffer = (ByteBuffer*)pDataItem->pObj;
310 pBuffer->SetPosition(0);
311 blobLen = pBuffer->GetLimit();
312 memcpy(buffer, pBuffer->GetPointer(), (blobLen < size) ? blobLen : size);
326 _DataSetEnumeratorImpl::GetDateTimeAt(int columnIndex, DateTime& value) const
328 result r = E_SUCCESS;
331 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
332 "The instance is not constructed or the dataset is already been deleted.");
333 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
334 "Given column index is out of range.");
335 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
336 "The method has tried to fetch the column data of a result set that is not activated.");
338 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
341 if (pDataItem->type != DB_COLUMNTYPE_TEXT)
344 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
348 pStr = (String*)pDataItem->pObj;
351 r = DateTime::Parse(*pStr, value);
359 _DataSetEnumeratorImpl::GetColumnCount(void) const
361 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
362 "The Object is not constructed or the dataset is already been deleted.");
364 return __columnCount;
368 _DataSetEnumeratorImpl::GetColumnType(int columnIndex) const
370 DbColumnType type = DB_COLUMNTYPE_UNDEFINED;
372 SysTryReturn(NID_IO, __pDataSet != null, DB_COLUMNTYPE_UNDEFINED, E_INVALID_STATE,
373 "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
375 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, DB_COLUMNTYPE_UNDEFINED, E_INVALID_ARG,
376 "[E_INVALID_ARG] Given column index is out of range.");
380 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
383 SetLastResult(E_INVALID_STATE);
384 return DB_COLUMNTYPE_UNDEFINED;
387 type = pDataItem->type;
390 case DB_COLUMNTYPE_INT:
391 case DB_COLUMNTYPE_DOUBLE:
392 case DB_COLUMNTYPE_TEXT:
393 case DB_COLUMNTYPE_BLOB:
394 case DB_COLUMNTYPE_NULL:
395 type = pDataItem->type;
399 SetLastResult(E_INVALID_STATE);
408 _DataSetEnumeratorImpl::GetColumnName(int columnIndex) const
410 SysTryReturn(NID_IO, __pDataSet != null, null, E_INVALID_STATE,
411 "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
413 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, null, E_INVALID_ARG,
414 "[E_INVALID_ARG] Given column index is out of range.");
417 String* pString = dynamic_cast <String *> (__pColumnList->GetAt(columnIndex));
421 SetLastResult(E_INVALID_STATE);
425 return String(pString->GetPointer());
429 _DataSetEnumeratorImpl::GetColumnSize(int columnIndex) const
433 SysTryReturn(NID_IO, __pDataSet != null, 0, E_INVALID_STATE,
434 "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
436 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, 0, E_INVALID_ARG,
437 "[E_INVALID_ARG] Given column index is out of range.");
439 SysTryReturn(NID_IO, __pCurrentRow != null, 0, E_INVALID_STATE,
440 "[E_INVALID_STATE] The method has tried to fetch the column data of a result set that is not activated.");
442 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
445 SetLastResult(E_INVALID_STATE);
449 bytes = pDataItem->size;
450 //SysLog(NID_IO, "Size is %d", bytes);
455 _DataSetEnumeratorImpl*
456 _DataSetEnumeratorImpl::GetInstance(DataSetEnumerator& dataSetEnumerator)
458 return dataSetEnumerator.__pDataSetEnumeratorImpl;
461 const _DataSetEnumeratorImpl*
462 _DataSetEnumeratorImpl::GetInstance(const DataSetEnumerator& dataSetEnumerator)
464 return dataSetEnumerator.__pDataSetEnumeratorImpl;
468 _DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN(void)
470 unique_ptr<DataSetEnumerator> pDataSetEnumerator(new (std::nothrow) DataSetEnumerator());
471 SysTryReturn(NID_IO, pDataSetEnumerator != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
472 return pDataSetEnumerator.release();