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 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
74 "The Object is not constructed or the dataset is already been deleted.");
76 if (__currentRowIndex +1 == __rowCount)
77 return E_OUT_OF_RANGE;
80 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
82 if (__pCurrentRow == null)
83 return E_INVALID_STATE;
89 _DataSetEnumeratorImpl::MovePrevious(void)
91 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
92 "The Object is not constructed or the dataset is already been deleted.");
94 if (__currentRowIndex == 0)
95 return E_OUT_OF_RANGE;
98 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
100 if (__pCurrentRow == null)
101 return E_INVALID_STATE;
107 _DataSetEnumeratorImpl::MoveFirst(void)
109 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
110 "The Object is not constructed or the dataset is already been deleted.");
112 __currentRowIndex = 0;
113 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
115 if (__pCurrentRow == null)
116 return E_INVALID_STATE;
122 _DataSetEnumeratorImpl::MoveLast(void)
124 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
125 "The Object is not constructed or the dataset is already been deleted.");
127 __currentRowIndex = __rowCount -1;
128 __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
130 if (__pCurrentRow == null)
131 return E_INVALID_STATE;
137 _DataSetEnumeratorImpl::Reset(void)
139 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
140 "The Object is not constructed or the dataset is already been deleted.");
142 __currentRowIndex = -1;
143 __pCurrentRow = null;
149 _DataSetEnumeratorImpl::GetIntAt(int columnIndex, int& value) const
151 result r = E_SUCCESS;
153 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
154 "The Object is not constructed or the dataset is already been deleted.");
155 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
156 "Given column index is out of range.");
157 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
158 "The method has tried to fetch the column data of a result set that is not activated.");
160 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
163 if (pDataItem->type != DB_COLUMNTYPE_INT)
166 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
170 value = pDataItem->intValue;
179 _DataSetEnumeratorImpl::GetInt64At(int columnIndex, long long& value) const
181 result r = E_SUCCESS;
183 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
184 "The Object is not constructed or the dataset is already been deleted.");
185 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
186 "Given column index is out of range.");
187 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
188 "The method has tried to fetch the column data of a result set that is not activated.");
190 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
193 if (pDataItem->type != DB_COLUMNTYPE_INT64)
196 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
200 value = pDataItem->int64Value;
209 _DataSetEnumeratorImpl::GetDoubleAt(int columnIndex, double& value) const
211 result r = E_SUCCESS;
213 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
214 "The Object is not constructed or the dataset is already been deleted.");
215 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
216 "Given column index is out of range.");
217 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
218 "The method has tried to fetch the column data of a result set that is not activated.");
220 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
223 if (pDataItem->type != DB_COLUMNTYPE_DOUBLE)
226 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
230 value = pDataItem->doubleValue;
239 _DataSetEnumeratorImpl::GetStringAt(int columnIndex, String& value) const
241 result r = E_SUCCESS;
243 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
244 "The Object is not constructed or the dataset is already been deleted.");
245 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
246 "Given column index is out of range.");
247 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
248 "The method has tried to fetch the column data of a result set that is not activated.");
250 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
253 if (pDataItem->type != DB_COLUMNTYPE_TEXT)
256 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
260 value = *((String*)pDataItem->pObj);
268 _DataSetEnumeratorImpl::GetBlobAt(int columnIndex, ByteBuffer& value) const
270 result r = E_SUCCESS;
271 ByteBuffer* pBuffer = null;
273 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
274 "The Object is not constructed or the dataset is already been deleted.");
275 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
276 "Given column index is out of range.");
277 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
278 "The method has tried to fetch the column data of a result set that is not activated.");
280 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
283 if (pDataItem->type != DB_COLUMNTYPE_BLOB)
286 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
290 pBuffer = (ByteBuffer*)pDataItem->pObj;
291 pBuffer->SetPosition(0);
292 r = value.CopyFrom(*pBuffer);
301 _DataSetEnumeratorImpl::GetBlobAt(int columnIndex, void* buffer, int size) const
303 result r = E_SUCCESS;
305 ByteBuffer* pBuffer = null;
307 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
308 "The Object is not constructed or the dataset is already been deleted.");
309 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
310 "Given column index is out of range.");
311 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
312 "The method has tried to fetch the column data of a result set that is not activated.");
314 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
317 if (pDataItem->type != DB_COLUMNTYPE_BLOB)
320 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
324 pBuffer = (ByteBuffer*)pDataItem->pObj;
325 pBuffer->SetPosition(0);
326 blobLen = pBuffer->GetLimit();
327 memcpy(buffer, pBuffer->GetPointer(), (blobLen < size) ? blobLen : size);
341 _DataSetEnumeratorImpl::GetDateTimeAt(int columnIndex, DateTime& value) const
343 result r = E_SUCCESS;
346 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
347 "The instance is not constructed or the dataset is already been deleted.");
348 SysTryReturnResult(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, E_INVALID_ARG,
349 "Given column index is out of range.");
350 SysTryReturnResult(NID_IO, __pCurrentRow != null, E_INVALID_STATE,
351 "The method has tried to fetch the column data of a result set that is not activated.");
353 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
356 if (pDataItem->type != DB_COLUMNTYPE_TEXT)
359 SysLog(NID_IO, "[E_TYPE_MISMATCH] Trying to access column of different type.");
363 pStr = (String*)pDataItem->pObj;
364 r = DateTime::Parse(*pStr, value);
373 _DataSetEnumeratorImpl::GetColumnCount(void) const
375 SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
376 "The Object is not constructed or the dataset is already been deleted.");
378 return __columnCount;
382 _DataSetEnumeratorImpl::GetColumnType(int columnIndex) const
384 DbColumnType type = DB_COLUMNTYPE_UNDEFINED;
386 SysTryReturn(NID_IO, __pDataSet != null, DB_COLUMNTYPE_UNDEFINED, E_INVALID_STATE,
387 "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
389 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, DB_COLUMNTYPE_UNDEFINED, E_INVALID_ARG,
390 "[E_INVALID_ARG] Given column index is out of range.");
394 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
397 SetLastResult(E_INVALID_STATE);
398 return DB_COLUMNTYPE_UNDEFINED;
401 switch (pDataItem->type)
403 case DB_COLUMNTYPE_INT:
404 case DB_COLUMNTYPE_INT64:
405 case DB_COLUMNTYPE_DOUBLE:
406 case DB_COLUMNTYPE_TEXT:
407 case DB_COLUMNTYPE_BLOB:
408 case DB_COLUMNTYPE_NULL:
409 type = pDataItem->type;
413 SetLastResult(E_INVALID_STATE);
422 _DataSetEnumeratorImpl::GetColumnName(int columnIndex) const
424 SysTryReturn(NID_IO, __pDataSet != null, null, E_INVALID_STATE,
425 "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
427 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, null, E_INVALID_ARG,
428 "[E_INVALID_ARG] Given column index is out of range.");
431 String* pString = dynamic_cast <String *> (__pColumnList->GetAt(columnIndex));
435 SetLastResult(E_INVALID_STATE);
439 return String(pString->GetPointer());
443 _DataSetEnumeratorImpl::GetColumnSize(int columnIndex) const
447 SysTryReturn(NID_IO, __pDataSet != null, -1, E_INVALID_STATE,
448 "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
450 SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, -1, E_INVALID_ARG,
451 "[E_INVALID_ARG] Given column index is out of range.");
453 SysTryReturn(NID_IO, __pCurrentRow != null, -1, E_INVALID_STATE,
454 "[E_INVALID_STATE] The method has tried to fetch the column data of a result set that is not activated.");
456 _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
459 SetLastResult(E_INVALID_STATE);
463 bytes = pDataItem->size;
464 //SysLog(NID_IO, "Size is %d", bytes);
469 _DataSetEnumeratorImpl*
470 _DataSetEnumeratorImpl::GetInstance(DataSetEnumerator& dataSetEnumerator)
472 return dataSetEnumerator.__pDataSetEnumeratorImpl;
475 const _DataSetEnumeratorImpl*
476 _DataSetEnumeratorImpl::GetInstance(const DataSetEnumerator& dataSetEnumerator)
478 return dataSetEnumerator.__pDataSetEnumeratorImpl;
482 _DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN(void)
484 unique_ptr<DataSetEnumerator> pDataSetEnumerator(new (std::nothrow) DataSetEnumerator());
485 SysTryReturn(NID_IO, pDataSetEnumerator != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
486 return pDataSetEnumerator.release();