Sync with tizen_2.2.1 appfw spec
[platform/framework/native/appfw.git] / src / app / FAppSqlDataControl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FAppSqlDataControl.cpp
19  * @brief       This is the implementation for the %SqlDataControl class.
20  */
21
22 #include <FAppSqlDataControl.h>
23
24 #include <FBaseSysLog.h>
25 #include <FBase_NativeError.h>
26
27 #include "FApp_SqlDataControlImpl.h"
28 #include <FSec_AccessController.h>
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace App
35 {
36
37 SqlDataControl::SqlDataControl(void)
38         : __pSqlDataControlImpl(null)
39 {
40         __pSqlDataControlImpl = new _SqlDataControlImpl;
41 }
42
43 SqlDataControl::~SqlDataControl(void)
44 {
45         delete __pSqlDataControlImpl;
46 }
47
48 result
49 SqlDataControl::Select(const String& dataId, const IList* pColumnList, const String* pWhere,
50                 const String *pOrder, RequestId& reqId, int pageNo, int countPerPage)
51 {
52         result r = _AccessController::CheckUserPrivilege(_PRV_DATACONTROL_CONSUMER);
53         SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
54
55         SysTryReturnResult(NID_APP, __pSqlDataControlImpl, E_INVALID_STATE,
56                         "This instance has not been properly constructed.");
57
58         return __pSqlDataControlImpl->Select(dataId, pColumnList, pWhere, pOrder, reqId, pageNo, countPerPage);
59 }
60
61 result
62 SqlDataControl::Insert(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap,
63                 RequestId& reqId)
64 {
65         result r = _AccessController::CheckUserPrivilege(_PRV_DATACONTROL_CONSUMER);
66         SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
67
68         SysTryReturnResult(NID_APP, __pSqlDataControlImpl, E_INVALID_STATE,
69                         "This instance has not been properly constructed.");
70
71         return __pSqlDataControlImpl->Insert(dataId, insertMap, reqId);
72 }
73
74 result
75 SqlDataControl::Update(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
76                         const Tizen::Base::String* pWhere, RequestId& reqId)
77 {
78         result r = _AccessController::CheckUserPrivilege(_PRV_DATACONTROL_CONSUMER);
79         SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
80
81         SysTryReturnResult(NID_APP, __pSqlDataControlImpl, E_INVALID_STATE, "This instance has not been properly constructed.");
82
83         return __pSqlDataControlImpl->Update(dataId, updateMap, pWhere, reqId);
84 }
85
86 result
87 SqlDataControl::Delete(const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere, RequestId& reqId)
88 {
89         result r = _AccessController::CheckUserPrivilege(_PRV_DATACONTROL_CONSUMER);
90         SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
91
92         SysTryReturnResult(NID_APP, __pSqlDataControlImpl, E_INVALID_STATE,
93                         "This instance has not been properly constructed.");
94
95         return __pSqlDataControlImpl->Delete(dataId, pWhere, reqId);
96 }
97
98 result
99 SqlDataControl::SetSqlDataControlResponseListener(ISqlDataControlResponseListener* pListener)
100 {
101         SysTryReturnResult(NID_APP, __pSqlDataControlImpl, E_INVALID_STATE,
102                                          "This instance has not been properly constructed yet.");
103
104         return __pSqlDataControlImpl->SetSqlDataControlResponseListener(pListener);
105 }
106
107 }} // Tizen::App
108