2 // Open Service Platform
3 // Copyright (c) 2012 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 FApp_SqlDataControlImpl.cpp
20 * @brief This is the implementation for the %_SqlDataControlImpl class.
25 #include <unique_ptr.h>
27 #include <appsvc/appsvc.h>
29 #include <FBaseInteger.h>
30 #include <FBaseString.h>
31 #include <FBaseLongLong.h>
32 #include <FBaseColIList.h>
33 #include <FBaseColIMap.h>
34 #include <FBaseColIMapEnumerator.h>
35 #include <FBaseRtIEventArg.h>
37 #include <FAppSqlDataControl.h>
38 #include <FAppISqlDataControlResponseListener.h>
40 #include <FBaseSysLog.h>
42 #include <FIo_DataControlResultSetEnumerator.h>
44 #include "FApp_AppControlManager.h"
45 #include "FApp_SqlDataControlImpl.h"
46 #include "FApp_AppArg.h"
47 #include "FApp_DataControlManager.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::App;
55 using namespace Tizen::Io;
57 namespace Tizen { namespace App
60 static const int MAX_REQUEST_COUNT = 128;
61 static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
63 class _SqlDataControlEventArg
67 _SqlDataControlEventArg(_DataControlRequestType requestType, RequestId reqId, String providerId, String dataId,
68 _DataControlResultSetEnumerator* pResultSetEnum, long long insertRowId, bool providerResult, String* pErrorMsg)
69 : __requestType(requestType)
71 , __providerId(providerId)
73 , __pResultSetEnum(pResultSetEnum)
74 , __insertRowId(insertRowId)
75 , __providerResult(providerResult)
76 , __pErrorMsg(pErrorMsg)
79 ~_SqlDataControlEventArg(void)
81 delete __pResultSetEnum;
85 _DataControlRequestType __requestType;
89 _DataControlResultSetEnumerator* __pResultSetEnum;
90 long long __insertRowId;
91 bool __providerResult;
95 class _SqlDataControlEvent
99 virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
103 _SqlDataControlEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
105 const _SqlDataControlEventArg* pArg = dynamic_cast<const _SqlDataControlEventArg*>(&arg);
108 ISqlDataControlResponseListener* pListener = dynamic_cast<ISqlDataControlResponseListener*> (&listener);
109 if (pListener != null)
111 switch (pArg->__requestType)
113 case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
114 pListener->OnSqlDataControlSelectResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
115 *(pArg->__pResultSetEnum), pArg->__providerResult, pArg->__pErrorMsg);
117 case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
118 pListener->OnSqlDataControlInsertResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
119 pArg->__insertRowId, pArg->__providerResult, pArg->__pErrorMsg);
121 case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
122 pListener->OnSqlDataControlUpdateResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
123 pArg->__providerResult, pArg->__pErrorMsg);
125 case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
126 pListener->OnSqlDataControlDeleteResponseReceived(pArg->__reqId, pArg->__providerId, pArg->__dataId,
127 pArg->__providerResult, pArg->__pErrorMsg);
137 _SqlDataControlImpl::_SqlDataControlImpl(void)
140 , __access(_DATACONTROL_ACCESS_UNDEFINED)
141 , __pPreviousListener(null)
142 , __pSqlDataControlEvent(null)
146 _SqlDataControlImpl::~_SqlDataControlImpl(void)
148 delete __pSqlDataControlEvent;
152 _SqlDataControlImpl::GetInstance(SqlDataControl& dc)
154 return dc.__pSqlDataControlImpl;
157 const _SqlDataControlImpl*
158 _SqlDataControlImpl::GetInstance(const SqlDataControl& dc)
160 return dc.__pSqlDataControlImpl;
164 _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int* pReq)
166 Integer* pReqId = null;
167 _DataControlRequestInfo* pReqInfo = null;
168 result r = E_SUCCESS;
171 _AppControlManager* pAppManagerImpl = _AppControlManager::GetInstance();
173 // Check the request count of DataControl operation
174 int count = pAppManagerImpl->GetLaunchRequestCount();
175 SysLog(NID_APP, "Current launch request count: %d", count);
177 SysTryReturnResult(NID_APP, count < MAX_REQUEST_COUNT, E_MAX_EXCEEDED, "The number of requests has exceeded the maximum limit.");
179 _AppArg* pArg = new (std::nothrow) _AppArg; // XXX: pArg will be released in _AppManagerImpl::LaunchApp().
180 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "insufficient memory");
182 pArg->Construct(*this, static_cast <_DataControlRequestType>(type), pDataList);
184 if (__pSqlDataControlEvent)
186 // reqId is system-wide id because the bundle is system-wide.
188 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, __pSqlDataControlEvent, -1);
189 req = reqObj.GetRequestNumber();
191 _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
192 _AppControlManager::_RequestGuard reqObj = _AppControlManager::_RequestGuard(*pAppManagerImpl, pArg, SqlDataControlCallback, pDcMgr, -1);
193 req = reqObj.GetRequestNumber();
195 pReqId = new (std::nothrow) Integer(req);
196 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
197 "[E_OUT_OF_MEMORY] The memory is insufficient");
199 pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pSqlDataControlEvent);
200 SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
201 "[E_OUT_OF_MEMORY] The memory is insufficient");
203 r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
204 SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
206 r = pAppManagerImpl->LaunchApp(__appId, pArg, req);
209 SysPropagate(NID_APP, r);
211 pDcMgr->RemoveRequestInfo(*pReqId);
223 r = pAppManagerImpl->LaunchApp(__appId, pArg);
224 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
238 _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, const String* pWhere,
239 const String *pOrder, RequestId& reqId, int pageNo, int countPerPage)
241 SysTryReturnResult(NID_APP, pageNo > 0, E_INVALID_ARG, "The specified pageNo parameter is less than 1");
242 SysTryReturnResult(NID_APP, countPerPage > 0, E_INVALID_ARG, "The specified countPerPage parameter is less than 1");
243 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_READ) > 0, E_ILLEGAL_ACCESS,
244 "The SELECT query is not permitted by DataControl provider.");
246 const String* pColumn = null;
248 result r = E_SUCCESS;
249 SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl SELECT");
251 ArrayList* pArgList = new ArrayList();
252 pArgList->Construct();
254 pArgList->Add(*(new String(dataId))); // list(0): data ID
255 long long argSize = dataId.GetLength() * sizeof(wchar_t);
257 if (pColumnList != null)
259 int columnCount = pColumnList->GetCount();
260 SysTryCatch(NID_APP, columnCount > 0, r = E_INVALID_ARG, E_INVALID_ARG,
261 "[E_INVALID_ARG] The specified pColumnList parameter is empty.");
263 pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): selected column count
264 SysLog(NID_APP, "[DC_CALLER_SEND] selected column count: %d", columnCount);
267 while (i < columnCount) // list(2): column list
269 pColumn = dynamic_cast< const String* >(pColumnList->GetAt(i));
270 SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
271 "[E_INVALID_ARG] The object is not String class.");
273 pArgList->Add(*(new String(*pColumn)));
274 argSize += pColumn->GetLength() * sizeof(wchar_t);
275 SysLog(NID_APP, "[DC_CALLER_SEND] column[%d]: %ls", i, pColumn->GetPointer());
281 pArgList->Add(*(new String(L"NULL")));
284 if (pWhere != null) // list(3): where clause
286 pArgList->Add(*(new String(*pWhere)));
287 argSize += pWhere->GetLength() * sizeof(wchar_t);
288 SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
292 pArgList->Add(*(new String(L"NULL")));
295 if (pOrder != null) // list(4): order clause
297 pArgList->Add(*(new String(*pOrder)));
298 argSize += pOrder->GetLength() * sizeof(wchar_t);
299 SysLog(NID_APP, "[DC_CALLER_SEND] pOrder: %ls", pOrder->GetPointer());
303 pArgList->Add(*(new String(L"NULL")));
305 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
306 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
308 pArgList->Add(*(new String(Integer::ToString(pageNo)))); // list(5): page number
310 pArgList->Add(*(new String(Integer::ToString(countPerPage)))); // list(6): count per page
312 r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_QUERY, pArgList, &id);
313 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
315 reqId = static_cast< RequestId >(id);
317 SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, pColumnList: 0x%x, pWhere: 0x%x, pOrder: 0x%x, reqId: %d, pageNo: %d, countPerPage: %d",
318 dataId.GetPointer(), pColumnList, pWhere, pOrder, reqId, pageNo, countPerPage);
322 pArgList->RemoveAll(true);
329 _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg* pResArg, service_result_e res, int prop, int option)
331 ArrayList* pResultList = null;
332 String* pResult = null;
333 String* pProviderId = null;
334 String* pDataId = null;
335 String* pErrorMessage = null;
336 String* pErrorMsg = null;
337 String* pTmpPath = null;
338 String* pInsertRowId = null;
339 _DataControlResultSetEnumerator* pResultSetEnum = null;
344 bool providerResult = true;
345 //bundle* origBundle = null;
346 bundle* resBundle = null;
347 _SqlDataControlEventArg* pEventArg = null;
348 const char* p = null;
349 result r = E_SUCCESS;
351 SysTryReturnResult(NID_APP, pResArg != null, E_INVALID_ARG, "Empty result callback.");
352 SysLog(NID_APP, "appsvc result value: %d", res);
354 resBundle = pResArg->GetBundle();
357 p = appsvc_get_data(resBundle, OSP_K_REQUEST_ID);
358 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
362 _DataControlManager* pDcMgr = static_cast< _DataControlManager* >(data);
363 _DataControlRequestInfo* pReqInfo = pDcMgr->GetRequestInfo(key);
364 SysTryCatch(NID_APP, pReqInfo != null, r = E_SYSTEM, E_SYSTEM,
365 "[E_SYSTEM] Failed to get request info");
367 _SqlDataControlEvent* pSqlDataControlEvent = dynamic_cast< _SqlDataControlEvent* >(pReqInfo->GetEvent());
368 SysTryCatch(NID_APP, pSqlDataControlEvent != null, r = E_SYSTEM, E_SYSTEM,
369 "[E_SYSTEM] invalid request info");
371 pDcMgr->RemoveRequestInfo(key);
373 if (pSqlDataControlEvent != null && typeid(pSqlDataControlEvent) == typeid(_SqlDataControlEvent*))
376 pResultList = _AppArg::GetListN(resBundle, OSP_K_ARG);
377 SysTryCatch(NID_APP, pResultList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
379 pResult = dynamic_cast <String*>(pResultList->GetAt(0)); // result list[0]
380 SysTryCatch(NID_APP, pResult, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
381 Integer::Parse(*pResult, providerRes);
382 providerResult = static_cast< bool >(providerRes);
384 pErrorMessage = dynamic_cast< String* >(pResultList->GetAt(1)); // result list[1]
385 SysTryCatch(NID_APP, pErrorMessage, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
386 pErrorMsg = new (std::nothrow) String(*pErrorMessage);
387 SysTryCatch(NID_APP, pErrorMsg, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
388 "[E_OUT_OF_MEMORY] The memory is insufficient.");
391 //origBundle = pArg->GetBundle();
393 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_REQUEST_TYPE);
394 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
395 requestType = atoi(p);
397 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_PROVIDER);
398 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
399 pProviderId = new (std::nothrow) String(p);
400 SysTryCatch(NID_APP, pProviderId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
401 "[E_OUT_OF_MEMORY] The memory is insufficient.");
403 p = appsvc_get_data(resBundle, OSP_K_DATACONTROL_DATA);
404 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
405 pDataId = new (std::nothrow) String(p);
406 SysTryCatch(NID_APP, pDataId, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
407 "[E_OUT_OF_MEMORY] The memory is insufficient.");
409 SysLog(NID_APP, "[DC_CALLER_RECV] provider result: %ld, requestType: %d, reqId: %d, providerId: %ls, dataId: %ls, errorMsg: %ls ",
410 providerRes, requestType, reqId, pProviderId->GetPointer(), pDataId->GetPointer(), pErrorMsg->GetPointer());
412 switch (static_cast <_DataControlRequestType>(requestType))
414 case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
416 pResultSetEnum = new (std::nothrow) _DataControlResultSetEnumerator;
417 SysTryCatch(NID_APP, pResultSetEnum, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
418 "[E_OUT_OF_MEMORY] The memory is insufficient.");
420 if (providerResult == true)
422 pTmpPath = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
423 if (pTmpPath == null)
425 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid result");
426 delete pResultSetEnum;
430 SysLog(NID_APP, "[DC_CALLER_RECV] tempPath: %ls", pTmpPath->GetPointer());
431 if (pTmpPath->Equals(L"NoResultSet", true) == false) // Result set exists
433 pResultSetEnum->SetPath(*pTmpPath);
437 pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_QUERY, static_cast <RequestId>(reqId),
438 *pProviderId, *pDataId, pResultSetEnum, -1, providerResult, pErrorMsg);
439 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
440 pSqlDataControlEvent->Fire(*pEventArg);
444 r = File::Remove(*pTmpPath); // Remove temporary file after releasing _ResultSetEnumerator.
445 SysTryLog(NID_APP, !IsFailed(r), "Failed to remove temp file for result set: %ls", pTmpPath->GetPointer());
450 case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
452 long long insertRowId = -1;
453 if (providerResult == true)
455 pInsertRowId = dynamic_cast< String* >(pResultList->GetAt(2)); // result list[2]
456 SysTryCatch(NID_APP, pInsertRowId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid result");
458 LongLong::Parse(*pInsertRowId, insertRowId);
461 pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, static_cast <RequestId>(reqId),
462 *pProviderId, *pDataId, null, insertRowId, providerResult, pErrorMsg);
463 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
464 pSqlDataControlEvent->Fire(*pEventArg);
467 case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
469 pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, static_cast <RequestId>(reqId),
470 *pProviderId, *pDataId, null, -1, providerResult, pErrorMsg);
471 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
472 pSqlDataControlEvent->Fire(*pEventArg);
475 case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
477 pEventArg = new (std::nothrow) _SqlDataControlEventArg(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, static_cast <RequestId>(reqId),
478 *pProviderId, *pDataId, null, -1, providerResult, pErrorMsg);
479 SysTryCatch(NID_APP, pEventArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
480 pSqlDataControlEvent->Fire(*pEventArg);
487 pResultList->RemoveAll(true);
493 p = appsvc_get_data(pArg->GetBundle(), OSP_K_REQUEST_ID);
494 SysTryCatch(NID_APP, p, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid bundle");
495 launchReqId = atoi(p);
497 // Remove the request count
498 SysLog(NID_APP, "Remove a launch request: reqId: %d", launchReqId);
499 _AppControlManager::GetInstance()->RemoveLaunchRequest(launchReqId);
506 pResultList->RemoveAll(true);
515 _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, RequestId& reqId)
517 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
518 "The INSERT query is not permitted by DataControl provider.");
523 result r = E_SUCCESS;
524 SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl INSERT");
526 columnCount = insertMap.GetCount();
527 SysTryReturnResult(NID_APP, columnCount > 0, E_INVALID_ARG, "The specified insertMap parameter is empty.");
529 ArrayList* pArgList = new ArrayList();
530 pArgList->Construct();
532 pArgList->Add(*(new String(dataId))); // list(0): data ID
533 long long argSize = dataId.GetLength() * sizeof(wchar_t);
535 pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): inserted column count
536 SysLog(NID_APP, "[DC_CALLER_SEND] inserted column count: %d", columnCount);
538 IMapEnumerator* pMapEnum = const_cast< IMap* >(&insertMap)->GetMapEnumeratorN();
539 while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
541 String* pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
542 SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
543 "[E_INVALID_ARG] The object is not String class.");
545 pArgList->Add(*(new String(*pColumn)));
546 SysLog(NID_APP, "[DC_CALLER_SEND] pColumn[%d]: %ls", i, pColumn->GetPointer());
548 String* pValue = dynamic_cast< String* >(pMapEnum->GetValue());
549 SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
550 "[E_INVALID_ARG] The object is not String class.");
552 pArgList->Add(*(new String(*pValue)));
553 SysLog(NID_APP, "[DC_CALLER_SEND] pValue[%d]: %ls", i, pValue->GetPointer());
555 argSize += pColumn->GetLength() * sizeof(wchar_t);
556 argSize += pValue->GetLength() * sizeof(wchar_t);
559 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
560 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
562 r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, pArgList, &id);
563 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
565 reqId = static_cast< RequestId >(id);
567 SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, insertMap: 0x%x, reqId: %d", dataId.GetPointer(), &insertMap, reqId);
571 pArgList->RemoveAll(true);
579 _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const String* pWhere, RequestId& reqId)
581 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
582 "The UPDATE query is not permitted by DataControl provider.");
587 result r = E_SUCCESS;
588 SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl UPDATE");
590 columnCount = updateMap.GetCount();
591 SysTryReturnResult(NID_APP, columnCount > 0, E_INVALID_ARG, "The specified insertMap parameter is empty.");
593 ArrayList* pArgList = new ArrayList();
594 pArgList->Construct();
596 pArgList->Add(*(new String(dataId))); // list(0): data ID
597 long long argSize = dataId.GetLength() * sizeof(wchar_t);
599 pArgList->Add(*(new String(Integer::ToString(columnCount)))); // list(1): updated column count
600 SysLog(NID_APP, "[DC_CALLER_SEND] updated column count: %d", columnCount);
602 IMapEnumerator* pMapEnum = const_cast< IMap* >(&updateMap)->GetMapEnumeratorN();
603 while (pMapEnum->MoveNext() == E_SUCCESS) // list(2): column-value pairs
605 String* pColumn = dynamic_cast< String* >(pMapEnum->GetKey());
606 SysTryCatch(NID_APP, pColumn != null, r = E_INVALID_ARG, E_INVALID_ARG,
607 "[E_INVALID_ARG] The object is not String class.");
609 pArgList->Add(*(new String(*pColumn)));
610 SysLog(NID_APP, "[DC_CALLER_SEND] pColumn[%d]: %ls", i, pColumn->GetPointer());
612 String* pValue = dynamic_cast< String* >(pMapEnum->GetValue());
613 SysTryCatch(NID_APP, pValue != null, r = E_INVALID_ARG, E_INVALID_ARG,
614 "[E_INVALID_ARG] The object is not String class.");
616 pArgList->Add(*(new String(*pValue)));
617 SysLog(NID_APP, "[DC_CALLER_SEND] pValue[%d]: %ls", i, pValue->GetPointer());
619 argSize += pColumn->GetLength() * sizeof(wchar_t);
620 argSize += pValue->GetLength() * sizeof(wchar_t);
624 if (pWhere != null) // list(3): where clause
626 pArgList->Add(*(new String(*pWhere)));
627 argSize += pWhere->GetLength() * sizeof(wchar_t);
628 SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
632 pArgList->Add(*(new String(L"NULL")));
634 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
635 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
637 r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, pArgList, &id);
638 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
640 reqId = static_cast< RequestId >(id);
642 SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, updateMap: 0x%x, pWhere: 0x%x, reqId: %d",
643 dataId.GetPointer(), &updateMap, pWhere, reqId);
647 pArgList->RemoveAll(true);
655 _SqlDataControlImpl::Delete(const String& dataId, const String* pWhere, RequestId& reqId)
657 SysTryReturnResult(NID_APP, (__access & _DATACONTROL_ACCESS_WRITE) > 0, E_ILLEGAL_ACCESS,
658 "The DELETE query is not permitted by DataControl provider.");
661 result r = E_SUCCESS;
662 SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl DELETE");
664 ArrayList* pArgList = new ArrayList();
665 pArgList->Construct();
667 pArgList->Add(*(new String(dataId))); // list(0): data ID
668 long long argSize = dataId.GetLength() * sizeof(wchar_t);
670 if (pWhere != null) // list(1): where clause
672 pArgList->Add(*(new String(*pWhere)));
673 argSize += pWhere->GetLength() * sizeof(wchar_t);
674 SysLog(NID_APP, "[DC_CALLER_SEND] pWhere: %ls", pWhere->GetPointer());
678 pArgList->Add(*(new String(L"NULL")));
680 SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
681 "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
683 r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, pArgList, &id);
684 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
686 reqId = static_cast< RequestId >(id);
688 SysLog(NID_APP, "[DC_CALLER_SEND] dataId: %ls, pWhere: 0x%x, reqId: %d", dataId.GetPointer(), pWhere, reqId);
692 pArgList->RemoveAll(true);
699 _SqlDataControlImpl::SetSqlDataControlResponseListener(ISqlDataControlResponseListener* pListener)
701 result r = E_SUCCESS;
703 if (__pPreviousListener != null)
705 r = __pSqlDataControlEvent->RemoveListener(*__pPreviousListener);
706 SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "Remove listener failed.");
707 __pPreviousListener = null;
710 if (pListener != null)
712 r = __pSqlDataControlEvent->AddListener(*pListener);
717 case E_OBJ_ALREADY_EXIST:
719 case E_INVALID_OPERATION:
720 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] The thread setting the listener is worker thread.");
723 SysLogException(NID_APP, r, "[%s] Propagating to caller...", GetErrorMessage(r));
729 __pPreviousListener = pListener;
736 _SqlDataControlImpl::CreateSqlDataControl(const String& appId, const String& providerId, const String& access)
738 unique_ptr<SqlDataControl> pDc(new (std::nothrow) SqlDataControl);
739 SysTryReturn(NID_APP, pDc != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
741 _SqlDataControlImpl* pDcImpl = _SqlDataControlImpl::GetInstance(*pDc);
742 pDcImpl->__appId = appId;
743 pDcImpl->__providerId = providerId;
744 unique_ptr<_SqlDataControlEvent> pSqlDataControlEvent(new (std::nothrow) _SqlDataControlEvent);
745 SysTryReturn(NID_IO, pSqlDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
747 pDcImpl->__pSqlDataControlEvent = pSqlDataControlEvent.release();
749 if (access == L"readonly")
751 pDcImpl->__access = _DATACONTROL_ACCESS_READ;
753 else if (access == L"writeonly")
755 pDcImpl->__access = _DATACONTROL_ACCESS_WRITE;
757 else if (access == L"readwrite")
759 pDcImpl->__access = _DATACONTROL_ACCESS_READWRITE;
763 pDcImpl->__access = _DATACONTROL_ACCESS_UNDEFINED;
764 SysLog(NID_IO, "The accessibility of DataControl provider is invalid.");
767 return pDc.release();