Merge "Beautified source code of appfw/src/base/utility" into tizen_2.2
[platform/framework/native/appfw.git] / inc / FAppSqlDataControl.h
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.h
19 * @brief      This is the header file for the %SqlDataControl class.
20 *
21 * This header file contains the declarations of the %SqlDataControl class.
22 */
23
24 #ifndef _FAPP_SQL_DATA_CONTROL_H_
25 #define _FAPP_SQL_DATA_CONTROL_H_
26
27 #include <FOspConfig.h>
28 #include <FBaseDataType.h>
29 #include <FBaseObject.h>
30
31 namespace Tizen { namespace Base
32 {
33 class String;
34 namespace Collection {
35 class IList;
36 class IMap;
37 }
38 }}
39
40 namespace Tizen { namespace App
41 {
42
43 class _SqlDataControlImpl;
44 class ISqlDataControlResponseListener;
45
46 /**
47  * @class   SqlDataControl
48  * @brief   This class represents the SQL-friendly interface based data control behavior.
49  *
50  * @since       2.0
51  *
52  * @final   This class is not intended for extension.
53  *
54  * The %SqlDataControl class represents the data control behavior, that provides a standard mechanism
55  * for accessing specific data exported by other applications.
56  * Data control provider can share its own data to data control consumers.
57  *
58  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/app/data_controls.htm">Data Controls</a>.
59  *
60  * @see Tizen::App::AppManager
61  *
62  * @code
63  *
64  * #include <FBase.h>
65  * #include <FIo.h>
66  *
67  * using namespace Tizen::Base;
68  * using namespace Tizen::Io;
69  *
70  * class MySqlDataControlResponseListener:
71  *      : public Tizen::App::ISqlDataControlResponseListener
72  * {
73  * public:
74  *      void OnSqlDataControlInsertResponseReceived(RequestId reqId, const String& providerId, const String& dataId, long long insertRowId, bool providerResult, const String* pErrorMsg)
75  *      {
76  *              AppLog("Row Id = %d", insertRowId);
77  *      }
78  * };
79  *
80  * void
81  * MyClass::Execute(void)
82  * {
83  *              String providerId(L"http://tizen.org/datacontrol/provider/example");
84  *              SqlDataControl* pDc = AppManager::GetSqlDataControlN(providerId);
85  *
86  *              MySqlDataControlResponseListener* pResponseListener = new MySqlDataControlResponseListener();
87  *
88  *              pDc->SetSqlDataControlResponseListener(pResponseListener);
89  *
90  *              String dataId(L"test");
91  *              String person(L"person");
92  *              String number(L"number");
93  *              RequestId reqId;
94  *
95  *              ArrayList columnList(SingleObjectDeleter);
96  *              columnList.Construct();
97  *
98  *              columnList.Add(person);
99  *              columnList.Add(number);
100  *
101  *              String where(L"group = 'friend'");
102  *              String order(L"person ASC");
103  *
104  *              pDc->Select(dataId, &columnList, &where, &order, reqId);
105  * }
106  *
107  * @endcode
108
109  */
110
111 class _OSP_EXPORT_ SqlDataControl
112         : public Tizen::Base::Object
113 {
114
115 public:
116         /**
117         * This destructor overrides Tizen::Base::Object::~Object().
118         *
119         * @since        2.0
120         */
121         virtual ~SqlDataControl(void);
122
123         /**
124         * Selects the specified columns to be queried. @n
125         * The result set of the specified columns is retrieved from a table owned by an SQL-friendly interface based data control provider. @n
126         * The %Select() method is asynchronous.
127         * For receiving the response from the data control provider, set the listener with
128         * SqlDataControl::SetSqlDataControlResponseListener(). @n
129         * When the requested result set has been received from the data control provider,
130         * the ISqlDataControlResponseListener::OnSqlDataControlSelectResponseReceived() method is called.
131         *
132         * @since        2.0
133         *
134         * @return               An error code
135         * @param[in]    dataId                          A string for identifying specific data, usually a database table to query from @n
136         *                                                                       The string consists of one or more components, separated by a slash('/').
137         * @param[in]    pColumnList                     A list of column names to query @n
138         *                                                                       The type of objects contained in the specified @c pColumnList must be
139         *                                                                       Tizen::Base::String class.
140         *                                                                       If the specified @c pColumnList is @c null, all columns are selected.
141         * @param[in]    pWhere                          A filter to select desired rows to query @n
142         *                                                                       It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
143         *                                                                       column1 = 'stringValue' AND column2 = numericValue. @n\r
144         *                                                                       If the value is string, the value must be wrapped in single quotes.\r
145         *                                                                       Otherwise it is not needed to wrap the numeric value in single quotes.\r
146         *                                                                       For more information on the SQL statement, see SQLite SQL documents.\r
147         * @param[in]    pOrder                          The sorting order of rows to query @n
148         *                                                                       It is an SQL 'ORDER BY' clause excluding the 'ORDER BY' itself.
149         * @param[out]   reqId                           The request ID
150         * @param[in]    pageNo                          The page number of the result set @n It starts from @c 1.
151         * @param[in]    countPerPage            The desired maximum count of rows on a page
152         * @exception    E_SUCCESS                       The method is successful.
153         * @exception    E_INVALID_STATE         This instance has not been properly constructed.
154         * @exception    E_INVALID_ARG           Either of the following conditions has occurred: @n
155         *                                                                       - The specified @c pColumnList is empty.
156         *                                                                       - The specified @c pageNo parameter is less than @c 1.
157         *                                                                       - The specified @c countPerPage parameter is less than @c 1.
158         * @exception    E_ILLEGAL_ACCESS        Either of the following conditions has occurred: @n
159         *                                                                       - Access is denied due to insufficient permission.
160         *                                                                       - The application using this method is not signed with the same certificate of provider application. @b Since: @b 2.1
161         * @exception    E_MAX_EXCEEDED          Either of the following conditions has occurred:
162         *                                                                       - The size of sending buffer has exceeded the maximum limit.
163         *                                                                       - The number of sending requests has exceeded the maximum limit.
164         * @exception    E_SYSTEM                        A system error has occurred.
165         * @remarks      The recommended data size is under 16KB because severe system performance degradation may occur for large messages. @c E_MAX_EXCEEDED may be returned for messages over 16KB size.\r
166         */
167         result Select(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IList* pColumnList,
168                         const Tizen::Base::String* pWhere, const Tizen::Base::String *pOrder, RequestId& reqId,
169                         int pageNo = 1, int countPerPage = 20);
170
171         /**
172         * Inserts new rows into a table owned by an SQL-friendly interface based data control provider. @n
173         * The %Insert() method is asynchronous.
174         * For receiving the response from the data control provider, set the listener with
175         * SqlDataControl::SetSqlDataControlResponseListener(). @n
176         * When the response has been received from the data control provider,
177         * the ISqlDataControlResponseListener::OnSqlDataControlInsertResponseReceived() method is called.
178         *
179         * @since        2.0
180         *
181         * @return               An error code
182         * @param[in]    dataId                          A string for identifying specific data, usually a database table to insert into @n
183         *                                                                       The string consists of one or more components, separated by a slash('/').
184         * @param[in]    insertMap                       The column-value pairs to insert @n
185         *                                                                       The type of objects must be Tizen::Base::String class. @n\r
186         *                                                                       If the value is string, the value must be wrapped in\r
187         *                                                                       single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.\r
188         *                                                                       For more information on the SQL statement, see SQLite SQL documents.\r
189         * @param[out]   reqId                           The request ID
190         * @exception    E_SUCCESS                       The method is successful.
191         * @exception    E_INVALID_STATE         This instance has not been properly constructed.
192         * @exception    E_INVALID_ARG           The specified @c insertMap is empty.
193         * @exception    E_ILLEGAL_ACCESS        Either of the following conditions has occurred: @n
194         *                                                                       - Access is denied due to insufficient permission.
195         *                                                                       - The application using this method is not signed with the same certificate of provider application. @b Since: @b 2.1
196         * @exception    E_MAX_EXCEEDED          Either of the following conditions has occurred:
197         *                                                                       - The size of sending buffer has exceeded the maximum limit.
198         *                                                                       - The number of sending requests has exceeded the maximum limit.
199         * @exception    E_SYSTEM                        A system error has occurred.
200         * @remarks      The recommended data size is under 1MB because severe system performance degradation may occur for large messages. @c E_MAX_EXCEEDED may be returned for messages over 1MB size.\r
201         */
202         result Insert(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& insertMap, RequestId& reqId);
203
204         /**
205         * Updates values of a table owned by an SQL-friendly interface based data control provider. @n
206         * The %Update() method is asynchronous.
207         * For receiving the response from the data control provider, set the listener with
208         * SqlDataControl::SetSqlDataControlResponseListener(). @n
209         * When the response has been received from the data control provider,
210         * the ISqlDataControlResponseListener::OnSqlDataControlUpdateResponseReceived() method is called.
211         *
212         * @since        2.0
213         *
214         * @return               An error code
215         * @param[in]    dataId                          A string for identifying specific data, usually a database table to update @n
216         *                                                                       The string consists of one or more components, separated by a slash('/').
217         * @param[in]    updateMap                       The column-value pairs to update @n
218         *                                                                       The type of objects must be Tizen::Base::String class. @n\r
219         *                                                                       If the value is string, the value must be wrapped in\r
220         *                                                                       single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.\r
221         *                                                                       For more information on the SQL statement, see SQLITE SQL documents.\r
222         * @param[in]    pWhere                          A filter to select desired rows to update @n
223         *                                                                       It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
224         *                                                                       column1 = 'stringValue' AND column2 = numericValue. @n\r
225         *                                                                       If the value is string, the value must be wrapped in\r
226         *                                                                       single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.\r
227         *                                                                       For more information on the SQL statement, see SQLITE SQL documents.\r
228         * @param[out]   reqId                           The request ID
229         * @exception    E_SUCCESS                       The method is successful.
230         * @exception    E_INVALID_STATE         This instance has not been properly constructed.
231         * @exception    E_INVALID_ARG           The specified @c updateMap is empty.
232         * @exception    E_ILLEGAL_ACCESS        Either of the following conditions has occurred: @n
233         *                                                                       - Access is denied due to insufficient permission.
234         *                                                                       - The application using this method is not signed with the same certificate of provider application. @b Since: @b 2.1
235         * @exception    E_MAX_EXCEEDED          Either of the following conditions has occurred:
236         *                                                                       - The size of sending buffer has exceeded the maximum limit.
237         *                                                                       - The number of sending requests has exceeded the maximum limit.
238         * @exception    E_SYSTEM                        A system error has occurred.
239         * @remarks      The recommended data size is under 1MB because severe system performance degradation may occur for large messages. @c E_MAX_EXCEEDED may be returned for messages over 1MB size.\r
240         */
241         result Update(const Tizen::Base::String& dataId, const Tizen::Base::Collection::IMap& updateMap,
242                         const Tizen::Base::String* pWhere, RequestId& reqId);
243
244         /**
245         * Deletes rows of a table owned by an SQL-friendly interface based data control provider. @n
246         * The %Delete() method is asynchronous.
247         * For receiving the response from the data control provider, set the listener with
248         * SqlDataControl::SetSqlDataControlResponseListener(). @n
249         * When the response has been received from the data control provider,
250         * the ISqlDataControlResponseListener::OnSqlDataControlDeleteResponseReceived() method is called.
251         *
252         * @since        2.0
253         *
254         * @return               An error code
255         * @param[in]    dataId                          A string for identifying specific data, usually a database table to delete from @n
256         *                                                                       The string consists of one or more components, separated by a slash('/').
257         * @param[in]    pWhere                          A filter to select desired rows to delete @n
258         *                                                                       It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
259         *                                                                       column1 = 'stringValue' AND column2 = numericValue.
260         *                                                                       If it is @c null, all rows are deleted. @n\r
261         *                                                                       If the value is string, the value must be wrapped in\r
262         *                                                                       single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.\r
263         *                                                                       For more information on the SQL statement, see SQLITE SQL documents.\r
264         * @param[out]   reqId                           The request ID
265         * @exception    E_SUCCESS                       The method is successful.
266         * @exception    E_INVALID_STATE         This instance has not been properly constructed.
267         * @exception    E_INVALID_ARG           A specified parameter is invalid.
268         * @exception    E_ILLEGAL_ACCESS        Either of the following conditions has occurred: @n
269         *                                                                       - Access is denied due to insufficient permission.
270         *                                                                       - The application using this method is not signed with the same certificate of provider application. @b Since: @b 2.1
271         * @exception    E_MAX_EXCEEDED          Either of the following conditions has occurred:
272         *                                                                       - The size of sending buffer has exceeded the maximum limit.
273         *                                                                       - The number of sending requests has exceeded the maximum limit.
274         * @exception    E_SYSTEM                        A system error has occurred.
275         * @remarks      The recommended data size is under 16KB because severe system performance degradation may occur for large messages. @c E_MAX_EXCEEDED may be returned for messages over 16KB size.\r
276         */
277         result Delete(const Tizen::Base::String& dataId, const Tizen::Base::String* pWhere, RequestId& reqId);
278
279         /**
280         * Sets an SQL-friendly interface based data control listener to this instance.
281         *
282         * @since        2.0
283         *
284         * @return               An error code
285         * @param[in]    pListener                       The data control callback listener @n
286         *                                                                       Some data controls need to get the callback result by implementing
287         *                                                                       the ISqlDataControlResponseListener interface.
288         * @exception    E_SUCCESS                       The method is successful.
289         * @exception    E_INVALID_STATE         This instance has not been properly constructed.
290         * @exception    E_SYSTEM                        A system error has occurred.
291         */
292         result SetSqlDataControlResponseListener(ISqlDataControlResponseListener* pListener);
293
294 private:
295         /**
296         * This default constructor is intentionally declared as private so that only the platform can create an instance.
297         *
298         * @since        2.0
299         */
300         SqlDataControl(void);
301
302         /**
303         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
304         *
305         * @since        2.0
306         * @remarks      This constructor is hidden.
307         */
308         SqlDataControl(const SqlDataControl& rhs);
309
310         /**
311         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
312         *
313         * @since        2.0
314         * @remarks      This operator is hidden.
315         */
316         SqlDataControl& operator =(const SqlDataControl& rhs);
317
318         class _SqlDataControlImpl* __pSqlDataControlImpl;
319
320         friend class _SqlDataControlImpl;
321
322 }; // SqlDataControl
323
324 }} // Tizen::App
325
326 #endif // _FAPP_SQL_DATA_CONTROL_H_
327