2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIo_DataSetImpl.cpp
19 * @brief This is the implementation file for the _DataSetImpl class.
23 #include <unique_ptr.h>
25 #include <FBaseObject.h>
26 #include <FBaseInteger.h>
27 #include <FBaseSysLog.h>
28 #include <FIo_DataSetImpl.h>
29 #include <FIo_DataRowImpl.h>
30 #include <FIo_DataSetEnumeratorImpl.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Io
38 _DataSetImpl::_DataSetImpl(void)
42 __pColumnTypeList(null)
46 _DataSetImpl::~_DataSetImpl(void)
48 for (int i = 0; i< __enumImplList.GetCount() ; i++)
49 (static_cast<_DataSetEnumeratorImpl*>(__enumImplList.GetAt(i)))->__dataSetDeleted = true;
50 for (int i = 0; i< __rowImplList.GetCount() ; i++)
51 (static_cast<_DataRowImpl*>(__rowImplList.GetAt(i)))->__dataSetDeleted = true;
55 delete __pColumnTypeList;
59 _DataSetImpl::Construct(const IList& columnNames)
63 __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
64 SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
65 __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
66 SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
67 __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
68 SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
70 __columnCount = columnNames.GetCount();
71 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
73 r = __pColumnList->Construct(__columnCount);
74 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
75 r = __pColumnTypeList->Construct(__columnCount);
76 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
78 for (int i = 0 ; i < __columnCount ; i++)
80 r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
81 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
83 r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
84 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
86 //SysLog(NID_IO, "column count is %d", __columnCount);
92 _DataSetImpl::CreateDataRowN(void)
95 unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
96 SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
98 unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
99 SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
101 r = __pDataSet->Add(pNewRowArrayList.release());
102 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
104 _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
106 r = __rowImplList.Add(_DataRowImpl::GetInstance(*pDataRow));
107 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
109 _DataRowImpl::GetInstance(*pDataRow)->__pRowImplList = &__rowImplList;
111 __rowCount = __pDataSet->GetCount();
112 //SysLog(NID_IO, "row count is %d", __rowCount);
114 return pDataRow.release();
119 _DataSetImpl::GetDataSetEnumeratorN(void)
123 unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
125 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
126 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
127 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
128 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
130 //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
132 r = __enumImplList.Add(_DataSetEnumeratorImpl::GetInstance(*pDataSetEnum));
133 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
135 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pEnumImplList = &__enumImplList;
137 return pDataSetEnum.release();
141 _DataSetImpl::CloneN(void) const
145 unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
146 SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
148 pDataSet->Construct(*__pColumnList);
150 for (int i = 0; i < __columnCount; i++)
152 r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
153 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
156 for (int i = 0; i < __rowCount; i++)
158 DataRow* pNewRow = pDataSet->CreateDataRowN();
159 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
162 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
165 return pDataSet.release();
169 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
171 int thisHash = this->GetHashCode();
172 int othersHash = obj.GetHashCode();
174 if (thisHash == othersHash )
181 _DataSetImpl::GetHashCode(void) const
185 for (int i = 0; i < __rowCount; i++)
187 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
188 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
195 _DataSetImpl::GetInstance(DataSet& dataSet)
197 return dataSet.__pDataSetImpl;
201 _DataSetImpl::GetInstance(const DataSet& dataSet)
203 return dataSet.__pDataSetImpl;