1 | /* |
---|
2 | * Funambol is a mobile platform developed by Funambol, Inc. |
---|
3 | * Copyright (C) 2008 Funambol, Inc. |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify it under |
---|
6 | * the terms of the GNU Affero General Public License version 3 as published by |
---|
7 | * the Free Software Foundation with the addition of the following permission |
---|
8 | * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED |
---|
9 | * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE |
---|
10 | * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
15 | * details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU Affero General Public License |
---|
18 | * along with this program; if not, see http://www.gnu.org/licenses or write to |
---|
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
20 | * MA 02110-1301 USA. |
---|
21 | * |
---|
22 | * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite |
---|
23 | * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com. |
---|
24 | * |
---|
25 | * The interactive user interfaces in modified source and object code versions |
---|
26 | * of this program must display Appropriate Legal Notices, as required under |
---|
27 | * Section 5 of the GNU Affero General Public License version 3. |
---|
28 | * |
---|
29 | * In accordance with Section 7(b) of the GNU Affero General Public License |
---|
30 | * version 3, these Appropriate Legal Notices must retain the display of the |
---|
31 | * "Powered by Funambol" logo. If the display of the logo is not reasonably |
---|
32 | * feasible for technical reasons, the Appropriate Legal Notices must display |
---|
33 | * the words "Powered by Funambol". |
---|
34 | */ |
---|
35 | |
---|
36 | package br.com.prognus.psync; |
---|
37 | |
---|
38 | |
---|
39 | import java.sql.Timestamp; |
---|
40 | import java.util.HashMap; |
---|
41 | |
---|
42 | import com.funambol.framework.engine.*; |
---|
43 | import com.funambol.framework.engine.source.*; |
---|
44 | import com.funambol.framework.logging.FunambolLogger; |
---|
45 | import com.funambol.framework.logging.FunambolLoggerFactory; |
---|
46 | import com.funambol.framework.tools.beans.LazyInitBean; |
---|
47 | |
---|
48 | /** |
---|
49 | * This is a simple SyncSource prototype. It implements the methods required by |
---|
50 | * the SyncSource interface. |
---|
51 | */ |
---|
52 | public class MySyncSource extends AbstractSyncSource |
---|
53 | implements SyncSource, LazyInitBean { |
---|
54 | |
---|
55 | // --------------------------------------------------------------- Constants |
---|
56 | |
---|
57 | public static final String LOG_NAME = "myconnector"; |
---|
58 | |
---|
59 | protected static final FunambolLogger log = FunambolLoggerFactory.getLogger(LOG_NAME); |
---|
60 | |
---|
61 | |
---|
62 | // ------------------------------------------------------------ Private data |
---|
63 | |
---|
64 | |
---|
65 | // -------------------------------------------------------------- Properties |
---|
66 | |
---|
67 | /** |
---|
68 | * A string parameter |
---|
69 | */ |
---|
70 | private String myString = null; |
---|
71 | |
---|
72 | /** |
---|
73 | * Getter for property myString |
---|
74 | * @return myString |
---|
75 | */ |
---|
76 | public String getMyString() { |
---|
77 | return myString; |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Setter for property myString |
---|
82 | * @param myString new value |
---|
83 | */ |
---|
84 | public void setMyString(String myString) { |
---|
85 | this.myString = myString; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * An int parameter |
---|
90 | */ |
---|
91 | private int myInt; |
---|
92 | |
---|
93 | /** |
---|
94 | * Getter for property myInt |
---|
95 | * @return myInt |
---|
96 | */ |
---|
97 | public int getMyInt() { |
---|
98 | return myInt; |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * Setter for property myInt |
---|
103 | * @param myInt new value |
---|
104 | */ |
---|
105 | public void setMyInt(int myInt) { |
---|
106 | this.myInt = myInt; |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * An complex parameter |
---|
111 | */ |
---|
112 | private HashMap myMap; |
---|
113 | |
---|
114 | /** |
---|
115 | * Getter for property myMap |
---|
116 | * @return myMap |
---|
117 | */ |
---|
118 | public HashMap getMyMap() { |
---|
119 | return myMap; |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * Setter for property myMap |
---|
124 | * @param myMap new value |
---|
125 | */ |
---|
126 | public void setMyMap(HashMap myMap) { |
---|
127 | this.myMap = myMap; |
---|
128 | } |
---|
129 | |
---|
130 | // ------------------------------------------------------------ Constructors |
---|
131 | |
---|
132 | public MySyncSource() { |
---|
133 | } |
---|
134 | |
---|
135 | // ---------------------------------------------------------- Public Methods |
---|
136 | |
---|
137 | /** |
---|
138 | * Invoked after class instantiation when a server bean is loaded. |
---|
139 | */ |
---|
140 | public void init() { |
---|
141 | // |
---|
142 | // When a bean is created, first of all the empty constructor is called |
---|
143 | // and the the bean properties are set. If a bean requires that its |
---|
144 | // properties have a proper value at initialization time, it must |
---|
145 | // implement com.funambol.framework.tools.beans.LazyInitBean, so that |
---|
146 | // the server beans factory has the opportunity to initialize the bean |
---|
147 | // after its creation, but before using it. |
---|
148 | // |
---|
149 | log.info("Initializing " + getClass().getName()); |
---|
150 | log.info("myString: " + myString); |
---|
151 | log.info("myInt: " + myInt ); |
---|
152 | log.info("myMap: " + myMap ); |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * Called before any other synchronization method. To interrupt the sync |
---|
157 | * process, throw a SyncSourceException. |
---|
158 | * |
---|
159 | * @param syncContext the context of the sync. |
---|
160 | * |
---|
161 | * @see SyncContext |
---|
162 | * |
---|
163 | * @throws SyncSourceException to interrupt the process with an error |
---|
164 | */ |
---|
165 | public void beginSync(SyncContext syncContext) throws SyncSourceException { |
---|
166 | log.info("Starting synchronization: " + syncContext); |
---|
167 | |
---|
168 | // |
---|
169 | // Put here your code if you need to do anything before data exchange |
---|
170 | // |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * Called after the modifications have been applied. |
---|
175 | * |
---|
176 | * @throws SyncSourceException to interrupt the process with an error |
---|
177 | */ |
---|
178 | public void endSync() throws SyncSourceException { |
---|
179 | log.info("Ending synchronization"); |
---|
180 | |
---|
181 | // |
---|
182 | // Put here your code if you need to do anything after data exchange |
---|
183 | // |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * Commits the changes applied during the sync session. If the underlying |
---|
188 | * datastore can not commit the changes, a SyncSourceException is thrown. |
---|
189 | * |
---|
190 | * @throws SyncSourceException if the changes cannot be committed |
---|
191 | */ |
---|
192 | public void commitSync() throws SyncSourceException { |
---|
193 | log.info("Committing synchronization"); |
---|
194 | |
---|
195 | // |
---|
196 | // Put here your code if you need to do anything to finally commit |
---|
197 | // changed data |
---|
198 | // |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * Called to get the keys of all items accordingly with the parameters |
---|
203 | * used in the beginSync call. |
---|
204 | * @return an array of all <code>SyncItemKey</code>s stored in this source. |
---|
205 | * If there are no items an empty array is returned. |
---|
206 | * |
---|
207 | * @throws SyncSourceException in case of error (for instance if the |
---|
208 | * underlying data store runs into problems) |
---|
209 | */ |
---|
210 | public SyncItemKey[] getAllSyncItemKeys() |
---|
211 | throws SyncSourceException { |
---|
212 | // |
---|
213 | // Put here your code to retrieve the keys for the all items in the data |
---|
214 | // store |
---|
215 | // |
---|
216 | log.info("getAllSyncItemKeys()"); |
---|
217 | return new SyncItemKey[0]; |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | * Called to get the keys of the items updated in the time frame sinceTs - untilTs. |
---|
222 | * <br><code>sinceTs</code> null means all keys of the items updated until <code>untilTs</code>. |
---|
223 | * <br><code>untilTs</code> null means all keys of the items updated since <code>sinceTs</code>. |
---|
224 | * |
---|
225 | * @param sinceTs consider the changes since this point in time. |
---|
226 | * @param untilTs consider the changes until this point in time. |
---|
227 | * |
---|
228 | * @return an array of keys containing the <code>SyncItemKey</code>'s key of the updated |
---|
229 | * items in the given time frame. It MUST NOT return null for |
---|
230 | * no keys, but instad an empty array. |
---|
231 | */ |
---|
232 | public SyncItemKey[] getUpdatedSyncItemKeys(Timestamp sinceTs , |
---|
233 | Timestamp untilTs ) |
---|
234 | throws SyncSourceException { |
---|
235 | // |
---|
236 | // Put here your code to retrieve the keys for the changed items |
---|
237 | // |
---|
238 | log.info("getUpdatedSyncItemKeys()"); |
---|
239 | return new SyncItemKey[0]; |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | * Called to get the keys of the items deleted in the time frame sinceTs - untilTs. |
---|
244 | * <br><code>sinceTs</code> null means all keys of the items deleted until <code>untilTs</code>. |
---|
245 | * <br><code>untilTs</code> null means all keys of the items deleted since <code>sinceTs</code>. |
---|
246 | * |
---|
247 | * @param sinceTs consider the changes since this point in time. |
---|
248 | * @param untilTs consider the changes until this point in time. |
---|
249 | * |
---|
250 | * @return an array of keys containing the <code>SyncItemKey</code>'s key of the deleted |
---|
251 | * items in the given time frame. It MUST NOT return null for |
---|
252 | * no keys, but instad an empty array. |
---|
253 | */ |
---|
254 | public SyncItemKey[] getDeletedSyncItemKeys(Timestamp sinceTs , |
---|
255 | Timestamp untilTs ) |
---|
256 | throws SyncSourceException { |
---|
257 | // |
---|
258 | // Put here your code to retrieve the keys for the deleted items |
---|
259 | // |
---|
260 | log.info("getDeletedSyncItemKeys()"); |
---|
261 | return new SyncItemKey[0]; |
---|
262 | } |
---|
263 | |
---|
264 | /** |
---|
265 | * Called to get the keys of the items created in the time frame sinceTs - untilTs. |
---|
266 | * <br><code>sinceTs</code> null means all keys of the items created until <code>untilTs</code>. |
---|
267 | * <br><code>untilTs</code> null means all keys of the items created since <code>sinceTs</code>. |
---|
268 | * |
---|
269 | * @param sinceTs consider the changes since this point in time. |
---|
270 | * @param untilTs consider the changes until this point in time. |
---|
271 | * |
---|
272 | * @return an array of keys containing the <code>SyncItemKey</code>'s key of the created |
---|
273 | * items in the given time frame. It MUST NOT return null for |
---|
274 | * no keys, but instad an empty array. |
---|
275 | */ |
---|
276 | public SyncItemKey[] getNewSyncItemKeys(Timestamp sinceTs , |
---|
277 | Timestamp untilTs ) |
---|
278 | throws SyncSourceException { |
---|
279 | // |
---|
280 | // Put here your code to retrieve the keys for the new items |
---|
281 | // |
---|
282 | log.info("getNewSyncItemKeys()"); |
---|
283 | return new SyncItemKey[0]; |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | /** |
---|
288 | * Adds a new <code>SyncItem</code>. |
---|
289 | * The item is also returned giving the opportunity to the |
---|
290 | * source to modify its content and return the updated item (i.e. updating |
---|
291 | * the id to the GUID). |
---|
292 | * |
---|
293 | * @param syncInstance the item to add |
---|
294 | * |
---|
295 | * @return the inserted item |
---|
296 | * |
---|
297 | * @throws SyncSourceException in case of error (for instance if the |
---|
298 | * underlying data store runs into problems) |
---|
299 | */ |
---|
300 | public SyncItem addSyncItem(SyncItem syncInstance) |
---|
301 | throws SyncSourceException { |
---|
302 | // |
---|
303 | // Put here your code to add a new item in the data store. Remember |
---|
304 | // to return the item with the new global id (GUID). |
---|
305 | // |
---|
306 | log.info("addSyncItem()"); |
---|
307 | return null; |
---|
308 | } |
---|
309 | |
---|
310 | /** |
---|
311 | * Update a <code>SyncItem</code>. |
---|
312 | * The item is also returned giving the opportunity to the |
---|
313 | * source to modify its content and return the updated item (i.e. updating |
---|
314 | * the id to the GUID). |
---|
315 | * |
---|
316 | * @param syncInstance the item to replace |
---|
317 | * |
---|
318 | * @return the updated item |
---|
319 | * |
---|
320 | * @throws SyncSourceException in case of error (for instance if the |
---|
321 | * underlying data store runs into problems) |
---|
322 | */ |
---|
323 | public SyncItem updateSyncItem(SyncItem syncInstance) |
---|
324 | throws SyncSourceException { |
---|
325 | // |
---|
326 | // Put here your code to update an item in the data store. |
---|
327 | // |
---|
328 | log.info("updateSyncItem()"); |
---|
329 | return null; |
---|
330 | } |
---|
331 | |
---|
332 | |
---|
333 | /** |
---|
334 | * Removes a SyncItem given its key. |
---|
335 | * |
---|
336 | * @param itemKey the key of the item to remove |
---|
337 | * @param time the time of the deletion |
---|
338 | * @param softDelete is a soft delete ? |
---|
339 | * |
---|
340 | * @throws SyncSourceException in case of error (for instance if the |
---|
341 | * underlying data store runs into problems) |
---|
342 | */ |
---|
343 | public void removeSyncItem(SyncItemKey itemKey, Timestamp time, boolean softDelete) |
---|
344 | throws SyncSourceException { |
---|
345 | // |
---|
346 | // Put here your code to remove an item from the data store. |
---|
347 | // |
---|
348 | log.info("removeSyncItem()"); |
---|
349 | } |
---|
350 | |
---|
351 | |
---|
352 | /** |
---|
353 | * Called to get the item with the given key. |
---|
354 | * |
---|
355 | * @return return the <code>SyncItem</code> corresponding to the given |
---|
356 | * key. If no item is found, null is returned. |
---|
357 | * |
---|
358 | * @param syncItemKey the key of the SyncItem to return |
---|
359 | * |
---|
360 | * @throws SyncSourceException in case of errors (for instance if the |
---|
361 | * underlying data store runs into problems) |
---|
362 | */ |
---|
363 | public SyncItem getSyncItemFromId(SyncItemKey syncItemKey) |
---|
364 | throws SyncSourceException { |
---|
365 | // |
---|
366 | // Put here your code to return a SyncItem from its Id |
---|
367 | // |
---|
368 | log.info("getSyncItemFromId()"); |
---|
369 | return null; |
---|
370 | } |
---|
371 | |
---|
372 | |
---|
373 | /** |
---|
374 | * Called to retrive the keys of the twins of the given item |
---|
375 | * |
---|
376 | * @param syncItem the twin item |
---|
377 | * |
---|
378 | * @return the keys of the twin. Each source implementation is free to |
---|
379 | * interpret this as it likes (i.e.: comparing all fields). |
---|
380 | * |
---|
381 | * |
---|
382 | * @throws SyncSourceException in case of errors (for instance if the |
---|
383 | * underlying data store runs into problems) |
---|
384 | */ |
---|
385 | public SyncItemKey[] getSyncItemKeysFromTwin(SyncItem syncItem) |
---|
386 | throws SyncSourceException { |
---|
387 | // |
---|
388 | // Put here your code to identify the twins (keys) of the given item |
---|
389 | // |
---|
390 | log.info("getSyncItemKeysFromTwin()"); |
---|
391 | return new SyncItemKey[0]; |
---|
392 | } |
---|
393 | |
---|
394 | |
---|
395 | /** |
---|
396 | * Called by the engine to notify an operation status. |
---|
397 | * @param operationName the name of the operation. |
---|
398 | * One between: |
---|
399 | * - Add |
---|
400 | * - Replace |
---|
401 | * - Delete |
---|
402 | * @param status the status of the operation |
---|
403 | * @param keys the keys of the items |
---|
404 | */ |
---|
405 | public void setOperationStatus(String operationName, int status, SyncItemKey[] keys) { |
---|
406 | // |
---|
407 | // Put here your code to handle the status code returned by the client |
---|
408 | // for a particular operation of the given keys |
---|
409 | // |
---|
410 | log.info("setOperationStatus()"); |
---|
411 | } |
---|
412 | |
---|
413 | |
---|
414 | } |
---|