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)
43 , __pColumnTypeList(null)
47 _DataSetImpl::~_DataSetImpl(void)
49 for (int i = 0; i< __enumImplList.GetCount() ; i++)
50 (static_cast<_DataSetEnumeratorImpl*>(__enumImplList.GetAt(i)))->__dataSetDeleted = true;
51 for (int i = 0; i< __rowImplList.GetCount() ; i++)
52 (static_cast<_DataRowImpl*>(__rowImplList.GetAt(i)))->__dataSetDeleted = true;
56 delete __pColumnTypeList;
60 _DataSetImpl::Construct(const IList& columnNames)
64 __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
65 SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
66 __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
67 SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
68 __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
69 SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
71 __columnCount = columnNames.GetCount();
72 SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
74 r = __pColumnList->Construct(__columnCount);
75 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
76 r = __pColumnTypeList->Construct(__columnCount);
77 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
79 for (int i = 0 ; i < __columnCount ; i++)
81 r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
82 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
84 r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
85 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
87 //SysLog(NID_IO, "column count is %d", __columnCount);
93 _DataSetImpl::CreateDataRowN(void)
96 unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
97 SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
99 unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
100 SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
102 r = __pDataSet->Add(pNewRowArrayList.release());
103 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
105 _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
107 r = __rowImplList.Add(_DataRowImpl::GetInstance(*pDataRow));
108 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
110 _DataRowImpl::GetInstance(*pDataRow)->__pRowImplList = &__rowImplList;
112 __rowCount = __pDataSet->GetCount();
113 //SysLog(NID_IO, "row count is %d", __rowCount);
115 return pDataRow.release();
120 _DataSetImpl::GetDataSetEnumeratorN(void)
124 unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
126 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
127 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
128 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
129 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
131 //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
133 r = __enumImplList.Add(_DataSetEnumeratorImpl::GetInstance(*pDataSetEnum));
134 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add to LinkedList Falied");
136 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pEnumImplList = &__enumImplList;
138 return pDataSetEnum.release();
142 _DataSetImpl::CloneN(void) const
146 unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
147 SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
149 pDataSet->Construct(*__pColumnList);
151 for (int i = 0; i < __columnCount; i++)
153 r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
154 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
157 for (int i = 0; i < __rowCount; i++)
159 DataRow* pNewRow = pDataSet->CreateDataRowN();
160 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
163 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
166 return pDataSet.release();
170 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
172 int thisHash = this->GetHashCode();
173 int othersHash = obj.GetHashCode();
175 if (thisHash == othersHash )
182 _DataSetImpl::GetHashCode(void) const
186 for (int i = 0; i < __rowCount; i++)
188 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
189 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
196 _DataSetImpl::GetInstance(DataSet& dataSet)
198 return dataSet.__pDataSetImpl;
202 _DataSetImpl::GetInstance(const DataSet& dataSet)
204 return dataSet.__pDataSetImpl;