2 // Copyright (c) 2012 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 FAppISqlDataControlProviderEventListener.h
19 * @brief This is the header file for the %ISqlDataControlProviderEventListener interface.
21 * This header file contains the declarations of the %ISqlDataControlProviderEventListener interface.
24 #ifndef _FAPP_ISQL_DATACONTROL_REQUESTEVENT_LISTENER_H_
25 #define _FAPP_ISQL_DATACONTROL_REQUESTEVENT_LISTENER_H_
27 #include <FBaseDataType.h>
28 #include <FBaseString.h>
29 #include <FBaseColIMapT.h>
30 #include <FBaseRtIEventListener.h>
32 namespace Tizen { namespace App
36 * @interface ISqlDataControlProviderEventListener
37 * @brief This interface defines a listener for dealing with SQL-friendly interface based data control request.
41 * The %ISqlDataControlProviderEventListener interface defines a listener for dealing with SQL-friendly interface based data control request.
43 * The following example demonstrates how to use the %ISqlDataControlProviderEventListener interface.
51 : public Tizen::App::ServiceApp
52 : public Tizen::App::ISqlDataControlProviderEventListener
56 virtual ~MyServiceApp(void);
58 virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
59 virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
61 virtual void OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
62 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
63 const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder);
64 virtual void OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
65 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap);
66 virtual void OnSqlDataControlUpdateRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
67 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
68 const Tizen::Base::String* pWhere);
69 virtual void OnSqlDataControlDeleteRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
70 const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere);
74 MyServiceApp::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
78 DataControlProviderManager* pDcMgr = DataControlProviderManager::GetInstance();
81 AppLog("Failed to get the instance of data control provider manager.");
85 r = pDcMgr->SetSqlDataControlProviderEventListener(this);
88 AppLog("Failed to set the data control provider listener.");
96 MyServiceApp::OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
97 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
98 const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder)
100 Database* pDb = null;
101 DbEnumerator* pDbEnum = null;
103 result r = E_SUCCESS;
105 if (providerId == L"http://tizen.org/datacontrol/provider/example")
107 if (dataId == L"test")
109 String sql = SqlStatementBuilder::CreateSelectStatement(dataId, pColumnList, pWhere, pOrder,
112 String dbPath(App::GetInstance()->GetAppDataPath() + L"test.db");
114 pDb = new Database();
117 errorMsg.Append(L"The memory is insufficient.");
121 r = pDb->Construct(dbPath, "r");
124 errorMsg.Append(L"The data control provider failed to open the database file.");
128 pDbEnum = pDb->QueryN(sql);
132 errorMsg.Append(L"The data control provider failed to execute SQL statement.");
138 errorMsg.Append(L"The data ID is invalid.");
143 errorMsg.Append(L"The provider ID is invalid.");
146 r = DataControlProviderManager::GetInstance()->SendSqlDataControlSelectResult(reqId, pDbEnum);
149 AppLog("The data control provider failed to send the result.");
157 r = DataControlProviderManager::Getinstance()->SendDataControlError(reqId, errorMsg);
160 AppLog("The data control provider failed to send the result.");
169 MyServiceApp::OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
170 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap)
172 Database* pDb = null;
174 long long insertRowId = -1;
175 result r = E_SUCCESS;
177 if (providerId == L"http://tizen.org/datacontrol/provider/example")
179 if (dataId == L"test")
181 String sql = SqlStatementBuilder::CreateInsertStatement(dataId, insertMap);
183 String dbPath(App::GetInstance()->GetAppDataPath() + L"test.db");
185 pDb = new Database();
188 errorMsg.Append(L"The memory is insufficient.");
192 r = pDb->Construct(dbPath, "a+");
195 errorMsg.Append(L"The data control provider failed to open the database file.");
199 r = pDb->ExcuteSql(sql, true);
202 errorMsg.Append(L"The data control provider failed to execute SQL statement.");
206 insertRowId = pDb->GetLastInsertRowId();
210 errorMsg.Append(L"The data ID is invalid.");
215 errorMsg.Append(L"The provider ID is invalid.");
218 r = DataControlProviderManager::GetInstance()->SendSqlDataControlInsertResult(reqId, insertRowId);
221 AppLog("The data control provider failed to send the result.");
228 r = DataControlProviderManager::Getinstance()->SendDataControlError(reqId, errorMsg);
231 AppLog("The data control provider failed to send the result.");
239 class _OSP_EXPORT_ ISqlDataControlProviderEventListener
240 : virtual public Tizen::Base::Runtime::IEventListener
245 * This polymorphic destructor should be overridden if required.
246 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
250 virtual ~ISqlDataControlProviderEventListener(void) {}
253 * Called when a select request is received from an application using SQL-friendly interface based data control. @n
254 * The provider must implement this listener for providing its own data.
258 * @param[in] reqId The request ID
259 * @param[in] providerId The provider ID for identifying the data control
260 * @param[in] dataId A string for identifying a specific table to query from @n
261 * The string consists of one or more components, separated by a slash('/').
262 * If the specified @c pColumnList is @c null, all columns are selected.
263 * @param[in] pColumnList A list of column names to query @n
264 * The type of objects contained in the specified @c pColumnList is
265 * Tizen::Base::String class.
266 * @param[in] pWhere A filter to select desired rows to query @n
267 * It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
268 * column1 = 'stringValue' AND column2 = numericValue.
269 * @param[in] pOrder The sorting order of rows to query @n
270 * It is an SQL 'ORDER BY' clause excluding the 'ORDER BY' itself.
271 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlSelectResult()
272 * or DataControlProviderManager::SendDataControlError().
274 virtual void OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
275 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
276 const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder) = 0;
279 * Called when an insert request is received from an application using SQL-friendly interface based data control. @n
280 * The provider must implement this listener for providing its own data.
284 * @param[in] reqId The request ID
285 * @param[in] providerId The provider ID for identifying the data control
286 * @param[in] dataId A string for identifying a specific table to insert into @n
287 * The string consists of one or more components, separated by a slash('/').
288 * @param[in] insertMap The field values in a record to insert @n
289 * The type of objects contained in the specified @c insertMap is
290 * Tizen::Base::String class.
291 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlInsertResult()
292 * or DataControlProviderManager::SendDataControlError().
294 virtual void OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
295 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap) = 0;
298 * Called when an update request is received from an application using SQL-friendly interface based data control. @n
299 * The provider must implement this listener for providing its own data.
303 * @param[in] reqId The request ID
304 * @param[in] providerId The provider ID for identifying the data control
305 * @param[in] dataId A string for identifying a specific table to update @n
306 * The string consists of one or more components, separated by a slash('/').
307 * @param[in] updateMap The field values in a record to update @n
308 * The type of objects contained in the specified @c updateMap is
309 * Tizen::Base::String class.
310 * @param[in] pWhere A filter to select desired rows to update @n
311 * It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
312 * column1 = 'stringValue' AND column2 = numericValue.
313 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlUpdateDeleteResult()
314 * or DataControlProviderManager::SendDataControlError().
316 virtual void OnSqlDataControlUpdateRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
317 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
318 const Tizen::Base::String* pWhere) = 0;
321 * Called when a delete request is received from an application using SQL-friendly interface based data control. @n
322 * The provider must implement this listener for providing its own data.
326 * @param[in] reqId The request ID
327 * @param[in] providerId The provider ID for identifying the data control
328 * @param[in] dataId A string for identifying a specific table to delete from @n
329 * The string consists of one or more components, separated by a slash('/').
330 * @param[in] pWhere A filter to select desired rows to delete @n
331 * It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
332 * column1 = 'stringValue' AND column2 = numericValue.
333 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlUpdateDeleteResult()
334 * or DataControlProviderManager::SendDataControlError().
336 virtual void OnSqlDataControlDeleteRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
337 const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere) = 0;
341 // This method is for internal use only.
342 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
344 // This method is reserved and may change its name at any time without prior notice.
348 virtual void ISqlDataControlProviderEventListener_Reserved1(void) {}
351 // This method is for internal use only.
352 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
354 // This method is reserved and may change its name at any time without prior notice.
358 virtual void ISqlDataControlProviderEventListener_Reserved2(void) {}
361 // This method is for internal use only.
362 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
364 // This method is reserved and may change its name at any time without prior notice.
368 virtual void ISqlDataControlProviderEventListener_Reserved3(void) {}
371 // This method is for internal use only.
372 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
374 // This method is reserved and may change its name at any time without prior notice.
378 virtual void ISqlDataControlProviderEventListener_Reserved4(void) {}
381 // This method is for internal use only.
382 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
384 // This method is reserved and may change its name at any time without prior notice.
388 virtual void ISqlDataControlProviderEventListener_Reserved5(void) {}
390 }; // ISqlDataControlProviderEventListener
394 #endif // _FAPP_ISQL_DATACONTROL_REQUESTEVENT_LISTENER_H_