2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using static Interop.Calendar.Query;
20 namespace Tizen.Pims.Calendar
22 /// A query is used to retrieve data which satisfies given criteria.
25 /// A query is used to retrieve calendar data which satisfies a given criteria,
26 /// such as an integer property being greater than a given value,
27 /// or a string property containing a given substring.
28 /// A query needs a filter which can set the conditions for the search.
30 public class CalendarQuery : IDisposable
32 internal IntPtr _queryHandle;
37 /// <param name="viewUri">The view URI of a query</param>
38 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
39 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
40 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
41 public CalendarQuery(string viewUri)
43 int error = Interop.Calendar.Query.Create(viewUri, out _queryHandle);
44 if (CalendarError.None != (CalendarError)error)
46 Log.Error(Globals.LogTag, "CalendarQuery Failed with error " + error);
47 throw CalendarErrorFactory.GetException(error);
51 internal CalendarQuery(IntPtr handle)
53 _queryHandle = handle;
61 #region IDisposable Support
62 private bool disposedValue = false;
64 protected virtual void Dispose(bool disposing)
68 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
70 int error = Interop.Calendar.Query.Destroy(_queryHandle);
71 if (CalendarError.None != (CalendarError)error)
73 Log.Error(Globals.LogTag, "CalendarQueryDestroy Failed with error " + error);
74 throw CalendarErrorFactory.GetException(error);
81 /// Releases all resources used by the CalendarQuery.
82 /// It should be called after finished using of the object.
91 /// Adds property IDs for projection.
93 /// <param name="propertyIdArray">The property ID array </param>
94 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
95 public void SetProjection(uint[] propertyIdArray)
97 int error = Interop.Calendar.Query.SetProjection(_queryHandle, propertyIdArray, propertyIdArray.Length);
98 if (CalendarError.None != (CalendarError)error)
100 Log.Error(Globals.LogTag, "SetProjection Failed with error " + error);
101 throw CalendarErrorFactory.GetException(error);
106 /// Sets the "distinct" option for projection.
108 /// <param name="set">If true it is set, otherwise if false it is unset</param>
109 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
110 public void SetDistinct(bool set)
112 int error = Interop.Calendar.Query.SetDistinct(_queryHandle, set);
113 if (CalendarError.None != (CalendarError)error)
115 Log.Error(Globals.LogTag, "SetDistinct Failed with error " + error);
116 throw CalendarErrorFactory.GetException(error);
121 /// Sets the filter for a query.
123 /// <param name="filter">The filter</param>
124 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
125 public void SetFilter(CalendarFilter filter)
127 int error = Interop.Calendar.Query.SetFilter(_queryHandle, filter._filterHandle);
128 if (CalendarError.None != (CalendarError)error)
130 Log.Error(Globals.LogTag, "SetFilter Failed with error " + error);
131 throw CalendarErrorFactory.GetException(error);
136 /// Sets the sort mode for a query.
138 /// <param name="propertyId">The property ID to sort</param>
139 /// <param name="isAscending">If true it sorts in the ascending order, otherwise if false it sorts in the descending order</param>
140 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
141 public void SetSort(uint propertyId, bool isAscending)
143 int error = Interop.Calendar.Query.SetSort(_queryHandle, propertyId, isAscending);
144 if (CalendarError.None != (CalendarError)error)
146 Log.Error(Globals.LogTag, "SetSort Failed with error " + error);
147 throw CalendarErrorFactory.GetException(error);