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 __columnCount = columnNames.GetCount();
56 SysTryReturn(NID_IO, __columnCount > 0, E_INVALID_ARG, r, "[E_INVALID_ARG] column count is 0.");
58 r = __columnList.Construct(__columnCount);
59 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
60 r = __columnTypeList.Construct(__columnCount);
61 SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
63 for (int i = 0 ; i < __columnCount ; i++)
65 r = __columnList.Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
66 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
68 r = __columnTypeList.Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
69 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
71 //SysLog(NID_IO, "column count is %d", __columnCount);
77 _DataSetImpl::CreateDataRowN(void)
80 unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList);
81 SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
83 unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
84 SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
86 r = __dataSet.Add(pNewRowArrayList.release());
87 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
89 _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = &__columnTypeList;
91 __rowCount = __dataSet.GetCount();
92 //SysLog(NID_IO, "row count is %d", __rowCount);
94 return pDataRow.release();
99 _DataSetImpl::GetDataSetEnumeratorN(void)
101 unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
103 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = &__dataSet;
104 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = &__columnList;
105 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
106 _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
108 //SysLog(NID_IO, "row count is %d, column count is %d", __rowCount, __columnCount);
110 return pDataSetEnum.release();
114 _DataSetImpl::CloneN(void) const
117 Integer* pColumnType = null;
119 unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
120 SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
122 pDataSet->Construct(__columnList);
124 for (int i = 0; i < __columnCount; i++)
126 pColumnType = static_cast<Integer*>(_DataSetImpl::GetInstance(*pDataSet)->__columnTypeList.GetAt(i));
127 r = _DataSetImpl::GetInstance(*pDataSet)->__columnTypeList.SetAt(new Integer(*(Integer*)__columnTypeList.GetAt(i)), i);
130 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
133 for (int i = 0; i < __rowCount; i++)
135 DataRow* pNewRow = pDataSet->CreateDataRowN();
136 r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__dataSet.GetAt(i)));
139 SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
142 return pDataSet.release();
146 _DataSetImpl::Equals(const Tizen::Base::Object& obj) const
148 int thisHash = this->GetHashCode();
149 int othersHash = obj.GetHashCode();
151 if (thisHash == othersHash )
158 _DataSetImpl::GetHashCode(void) const
162 for (int i = 0; i < __rowCount; i++)
164 const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__dataSet.GetAt(i));
165 hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
172 _DataSetImpl::GetInstance(DataSet& dataSet)
174 return dataSet.__pDataSetImpl;
178 _DataSetImpl::GetInstance(const DataSet& dataSet)
180 return dataSet.__pDataSetImpl;