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 FAppISqlDataControlProviderEventListener.h
20 * @brief This is the header file for the %ISqlDataControlProviderEventListener interface.
22 * This header file contains the declarations of the %ISqlDataControlProviderEventListener interface.
25 #ifndef _FAPP_ISQL_DATACONTROL_REQUESTEVENT_LISTENER_H_
26 #define _FAPP_ISQL_DATACONTROL_REQUESTEVENT_LISTENER_H_
28 #include <FBaseDataType.h>
29 #include <FBaseString.h>
30 #include <FBaseColIMapT.h>
31 #include <FBaseRtIEventListener.h>
33 namespace Tizen { namespace App
37 * @interface ISqlDataControlProviderEventListener
38 * @brief This interface defines a listener for dealing with SQL-type data control request.
42 * The %ISqlDataControlProviderEventListener interface defines a listener for dealing with SQL-type data control request.
44 * The following example demonstrates how to use the %ISqlDataControlProviderEventListener interface.
52 : public Tizen::App::ServiceApp
53 : public Tizen::App::ISqlDataControlProviderEventListener
57 virtual ~MyServiceApp(void);
59 virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
60 virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
62 virtual void OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
63 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
64 const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder);
65 virtual void OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
66 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap);
67 virtual void OnSqlDataControlUpdateRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
68 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
69 const Tizen::Base::String* pWhere);
70 virtual void OnSqlDataControlDeleteRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
71 const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere);
75 MyServiceApp::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
79 DataControlProviderManager* pDcMgr = DataControlProviderManager::GetInstance();
82 AppLog("Failed to get the instance of data control provider manager.");
86 r = pDcMgr->SetSqlDataControlProviderEventListener(this);
89 AppLog("Failed to set the data control provider listener.");
97 MyServiceApp::OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
98 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
99 const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder)
101 Database* pDb = null;
102 DbEnumerator* pDbEnum = null;
104 result r = E_SUCCESS;
106 if (providerId == L"http://tizen.org/datacontrol/provider/example")
108 if (dataId == L"test")
110 String sql = SqlStatementBuilder::CreateSelectStatement(dataId, pColumnList, pWhere, pOrder,
113 String dbPath(App::GetInstance()->GetAppDataPath() + L"test.db");
115 pDb = new Database();
118 errorMsg.Append(L"The memory is insufficient.");
122 r = pDb->Construct(dbPath, "r");
125 errorMsg.Append(L"The data control provider failed to open the database file.");
129 pDbEnum = pDb->QueryN(sql);
133 errorMsg.Append(L"The data control provider failed to execute SQL statement.");
139 errorMsg.Append(L"The data ID is invalid.");
144 errorMsg.Append(L"The provider ID is invalid.");
147 r = DataControlProviderManager::GetInstance()->SendSqlDataControlSelectResult(reqId, pDbEnum);
150 AppLog("The data control provider failed to send the result.");
158 r = DataControlProviderManager::Getinstance()->SendDataControlError(reqId, errorMsg);
161 AppLog("The data control provider failed to send the result.");
170 MyServiceApp::OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
171 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap)
173 Database* pDb = null;
175 long long insertRowId = -1;
176 result r = E_SUCCESS;
178 if (providerId == L"http://tizen.org/datacontrol/provider/example")
180 if (dataId == L"test")
182 String sql = SqlStatementBuilder::CreateInsertStatement(dataId, insertMap);
184 String dbPath(App::GetInstance()->GetAppDataPath() + L"test.db");
186 pDb = new Database();
189 errorMsg.Append(L"The memory is insufficient.");
193 r = pDb->Construct(dbPath, "a+");
196 errorMsg.Append(L"The data control provider failed to open the database file.");
200 r = pDb->ExcuteSql(sql, true);
203 errorMsg.Append(L"The data control provider failed to execute SQL statement.");
207 insertRowId = pDb->GetLastInsertRowId();
211 errorMsg.Append(L"The data ID is invalid.");
216 errorMsg.Append(L"The provider ID is invalid.");
219 r = DataControlProviderManager::GetInstance()->SendSqlDataControlInsertResult(reqId, insertRowId);
222 AppLog("The data control provider failed to send the result.");
229 r = DataControlProviderManager::Getinstance()->SendDataControlError(reqId, errorMsg);
232 AppLog("The data control provider failed to send the result.");
240 class _OSP_EXPORT_ ISqlDataControlProviderEventListener
241 : virtual public Tizen::Base::Runtime::IEventListener
246 * This polymorphic destructor should be overridden if required.
247 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
251 virtual ~ISqlDataControlProviderEventListener(void) {}
254 * Called when a select request is received from an application using SQL-type data control. @n
255 * The provider must implement this listener for providing its own data.
259 * @param[in] reqId The request ID
260 * @param[in] providerId The provider ID for identifying the data control
261 * @param[in] dataId A string for identifying a specific table to query from @n
262 * The string consists of one or more components, separated by a slash('/').
263 * If the specified @c pColumnList is @c null, all columns are selected.
264 * @param[in] pColumnList A list of column names to query @n
265 * The type of objects contained in the specified @c pColumnList is
266 * Tizen::Base::String class.
267 * @param[in] pWhere A filter to select desired rows to query @n
268 * It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
269 * column1 = 'stringValue' AND column2 = numericValue.
270 * @param[in] pOrder The sorting order of rows to query @n
271 * It is an SQL 'ORDER BY' clause excluding the 'ORDER BY' itself.
272 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlSelectResult()
273 * or DataControlProviderManager::SendDataControlError().
275 virtual void OnSqlDataControlSelectRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
276 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
277 const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder) = 0;
280 * Called when an insert request is received from an application using SQL-type data control. @n
281 * The provider must implement this listener for providing its own data.
285 * @param[in] reqId The request ID
286 * @param[in] providerId The provider ID for identifying the data control
287 * @param[in] dataId A string for identifying a specific table to insert into @n
288 * The string consists of one or more components, separated by a slash('/').
289 * @param[in] insertMap The column-value pairs to insert @n
290 * The type of objects contained in the specified @c insertMap is
291 * Tizen::Base::String class.
292 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlInsertResult()
293 * or DataControlProviderManager::SendDataControlError().
295 virtual void OnSqlDataControlInsertRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
296 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap) = 0;
299 * Called when an update request is received from an application using SQL-type data control. @n
300 * The provider must implement this listener for providing its own data.
304 * @param[in] reqId The request ID
305 * @param[in] providerId The provider ID for identifying the data control
306 * @param[in] dataId A string for identifying a specific table to update @n
307 * The string consists of one or more components, separated by a slash('/').
308 * @param[in] updateMap The column-value pairs to update @n
309 * The type of objects contained in the specified @c updateMap is
310 * Tizen::Base::String class.
311 * @param[in] pWhere A filter to select desired rows to update @n
312 * It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
313 * column1 = 'stringValue' AND column2 = numericValue.
314 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlUpdateDeleteResult()
315 * or DataControlProviderManager::SendDataControlError().
317 virtual void OnSqlDataControlUpdateRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
318 const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
319 const Tizen::Base::String* pWhere) = 0;
322 * Called when a delete request is received from an application using SQL-type data control. @n
323 * The provider must implement this listener for providing its own data.
327 * @param[in] reqId The request ID
328 * @param[in] providerId The provider ID for identifying the data control
329 * @param[in] dataId A string for identifying a specific table to delete from @n
330 * The string consists of one or more components, separated by a slash('/').
331 * @param[in] pWhere A filter to select desired rows to delete @n
332 * It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
333 * column1 = 'stringValue' AND column2 = numericValue.
334 * @remarks For replying to the data control request, use DataControlProviderManager::SendSqlDataControlUpdateDeleteResult()
335 * or DataControlProviderManager::SendDataControlError().
337 virtual void OnSqlDataControlDeleteRequestReceived(RequestId reqId, const Tizen::Base::String& providerId,
338 const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere) = 0;
342 // This method is for internal use only.
343 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
345 // This method is reserved and may change its name at any time without prior notice.
349 virtual void ISqlDataControlProviderEventListener_Reserved1(void) {}
352 // This method is for internal use only.
353 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
355 // This method is reserved and may change its name at any time without prior notice.
359 virtual void ISqlDataControlProviderEventListener_Reserved2(void) {}
362 // This method is for internal use only.
363 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
365 // This method is reserved and may change its name at any time without prior notice.
369 virtual void ISqlDataControlProviderEventListener_Reserved3(void) {}
372 // This method is for internal use only.
373 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
375 // This method is reserved and may change its name at any time without prior notice.
379 virtual void ISqlDataControlProviderEventListener_Reserved4(void) {}
382 // This method is for internal use only.
383 // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
385 // This method is reserved and may change its name at any time without prior notice.
389 virtual void ISqlDataControlProviderEventListener_Reserved5(void) {}
391 }; // ISqlDataControlProviderEventListener
395 #endif // _FAPP_ISQL_DATACONTROL_REQUESTEVENT_LISTENER_H_