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)
43 __pColumnTypeList(null)
47 _DataSetImpl::~_DataSetImpl(void)
49 for (int i = 0; i< __enumImplList.GetCount() ; i++)
50 (static_cast<_DataSetEnumeratorImpl*>(__enumImplList.GetAt(i)))->__dataSetDeleted = 1;
54 delete __pColumnTypeList;
58 _DataSetImpl::Construct(const IList& columnNames)
62 __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
63 SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
64 __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
65 SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
66 __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
67 SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
69 __columnCount = columnNames.GetCount();
70 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
72 r = __pColumnList->Construct(__columnCount);
73 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
74 r = __pColumnTypeList->Construct(__columnCount);
75 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
77 for (int i = 0 ; i < __columnCount ; i++)
79 r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
80 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
82 r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
83 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
85 //SysLog(NID_IO, "column count is %d", __columnCount);
91 _DataSetImpl::CreateDataRowN(void)
94 unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
95 SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
97 unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
98 SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
100 r = __pDataSet->Add(pNewRowArrayList.release());
101 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
103 _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
105 __rowCount = __pDataSet->GetCount();
106 //SysLog(NID_IO, "row count is %d", __rowCount);
108 return pDataRow.release();
113 _DataSetImpl::GetDataSetEnumeratorN(void)
117 unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
119 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
120 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
121 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
122 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
124 //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
126 r = __enumImplList.Add(_DataSetEnumeratorImpl::GetInstance(*pDataSetEnum));
127 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
129 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pEnumImplList = &__enumImplList;
131 return pDataSetEnum.release();
135 _DataSetImpl::CloneN(void) const
139 unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
140 SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
142 pDataSet->Construct(*__pColumnList);
144 for (int i = 0; i < __columnCount; i++)
146 r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
147 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
150 for (int i = 0; i < __rowCount; i++)
152 DataRow* pNewRow = pDataSet->CreateDataRowN();
153 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
156 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
159 return pDataSet.release();
163 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
165 int thisHash = this->GetHashCode();
166 int othersHash = obj.GetHashCode();
168 if (thisHash == othersHash )
175 _DataSetImpl::GetHashCode(void) const
179 for (int i = 0; i < __rowCount; i++)
181 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
182 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
189 _DataSetImpl::GetInstance(DataSet& dataSet)
191 return dataSet.__pDataSetImpl;
195 _DataSetImpl::GetInstance(const DataSet& dataSet)
197 return dataSet.__pDataSetImpl;