2 // Open Service Platform
3 // Copyright (c) 2013 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_DataSetImpl.cpp
20 * @brief This is the implementation file for the _DataSetImpl class.
24 #include <unique_ptr.h>
26 #include <FBaseObject.h>
27 #include <FBaseInteger.h>
28 #include <FBaseSysLog.h>
29 #include <FIo_DataSetImpl.h>
30 #include <FIo_DataRowImpl.h>
31 #include <FIo_DataSetEnumeratorImpl.h>
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
37 namespace Tizen { namespace Io
39 _DataSetImpl::_DataSetImpl(void)
45 _DataSetImpl::~_DataSetImpl(void)
51 _DataSetImpl::Construct(const IList& columnNames)
55 r = __columnList.Construct(columnNames);
56 SysTryReturn(NID_IO, r == E_SUCCESS, E_INVALID_ARG, r, "[E_INVALID_ARG] columnNames is invalid.");
58 __columnCount = __columnList.GetCount();
59 SysTryReturn(NID_IO, __columnCount > 0, E_INVALID_ARG, r, "[E_INVALID_ARG] column count is 0.");
61 __columnTypeList.Construct(__columnCount);
63 for (int i = 0 ; i < __columnCount ; i++)
65 result r = __columnTypeList.Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
66 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
68 //SysLog(NID_IO, "column count is %d", __columnCount);
74 _DataSetImpl::CreateDataRowN(void)
77 unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList);
78 SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
80 unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
81 SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
83 r = __dataSet.Add(pNewRowArrayList.release());
84 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
86 _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = &__columnTypeList;
88 __rowCount = __dataSet.GetCount();
89 //SysLog(NID_IO, "row count is %d", __rowCount);
91 return pDataRow.release();
96 _DataSetImpl::GetDataSetEnumeratorN(void)
98 unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
100 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = &__dataSet;
101 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = &__columnList;
102 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
103 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
105 //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
107 return pDataSetEnum.release();
111 _DataSetImpl::CloneN(void) const
114 unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
115 SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
117 pDataSet->Construct(__columnList);
119 for (int i = 0; i < __rowCount; i++)
121 DataRow* pNewRow = pDataSet->CreateDataRowN();
122 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__dataSet.GetAt(i)));
125 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
128 return pDataSet.release();
132 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
134 int thisHash = this->GetHashCode();
135 int othersHash = obj.GetHashCode();
137 if (thisHash == othersHash )
144 _DataSetImpl::GetHashCode(void) const
148 for (int i = 0; i < __rowCount; i++)
150 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__dataSet.GetAt(i));
151 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);