Backend Synchronization

tenderlaΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

102 εμφανίσεις

FOR ANDROI D/
I OS

Backend Synchronization

Outline


What is Back
-
end Synchronization?


Why would I need it?


Design Considerations


How to implement it


Example


What is Backend Synchronization?


The process of establishing consistency among data
between a data source and target data storage, and
continuous harmonization over time.


General Types:


Wholesale Transfer


Timestamp Synchronization


Mathematical Synchronization


Reasons for Backend Synchronization


Front End for Data Entry Only


Data Entered and Needed on Multiple Devices


Offline Modes


Data Backup


Reporting

Options for Synchronizations


Microsoft SQL Server


Replication


Direct Copy of one DB to another


Merge Replication


Data from multiple sources updating


Primarily designed for Microsoft SQL DB’s


Oracle


SQLite Mobile Client


SQLite Data Sync


Create your own


This option is most common for mobile devices at this point


Parse.com*





Basic Synchronization Model


Design Considerations for Mobile


Do I need all of the data from the remote
db

on the
local device?


How much memory will be available for storage locally?


Will the data use discourage app use for people without large
data plans?


Will the same data be available to every user?


How often to Synchronize?


Is up to the minute data crucial locally?


Is up to the minute data crucial on remote server?


Design Considerations Continued


What items need synchronizing?


How
do I resolve conflicts between data entered on
separate devices?


How do I keep primary keys in order for data created
on multiple devices
?


How to Implement


Create a Synchronization procedure that processes
the data pull downs


Call the Synchronization procedure


After Launching Application (Wait to call until after successful
authentication if implemented)


From menu item for user chosen synchronization


Commit new and updated data as they happen (if
connection exists)


Implement means to synchronize data once
connection
is available

Examples


General


Off Shore Rig data


Reporting Servers for Very Active Database


Games (not online/multiplayer)


Mobile


MyFitnessPal


iTunes



Parse Example (
iOS
)


Saving an object


PFObject

*
gameScore

= [
PFObject

objectWithClassName
:@"
GameScore
"];


[
gameScore

setObject
:[
NSNumber

numberWithInt:1337]
forKey
:@"score"];


[
gameScore

setObject
:@"Sean
Plott
"
forKey
:@"
playerName
"];


[
gameScore

setObject
:[
NSNumber

numberWithBool:NO
]
forKey
:@"
cheatMode
"];


[
gameScore

saveEventually
];


Synchronization (dependent on having a locally stored
lastSyncTime
)


PFQuery

*query = [
PFQuery

queryWithClassName
:@"
GameScore
"];


[query
whereKey
:@"
playerName
"
equalTo
:@“Joe
Schmoe
"];


[query
whereKey
:@“
updatedAt
"
greaterThan:lastSyncTime
] ;


[query
findObjectsInBackgroundWithBlock
:^(
NSArray

*objects,
NSError

*error) {



if (!error)
{



NSLog
(@"Successfully retrieved %d scores.",
objects.count
);



} else {



// Log details of the failure



NSLog
(@"Error: %@ %@", error, [error
userInfo
]);



}


}];

Parse Example (Android)


Saving an object


ParseObject

gameScore

= new
ParseObject
("
GameScore
");


gameScore.put
("score", 1337);


gameScore.put
("
playerName
", "Sean
Plott
");


gameScore.put
("
cheatMode
", false);


gameScore.saveEventually
();


Synchronization (dependent on having a locally stored
lastSyncTime
)


ParseQuery

query = new
ParseQuery
("
GameScore
");


query.whereEqualTo
("
playerName
", "Dan
Stemkoski
");


q
uery.whereGreaterThan
(“
updateAt
”,
lastSyncTime
);


query.findInBackground
(new
FindCallback
() {



public void done(List<
ParseObject
>
scoreList
,
ParseException

e) {



if (e == null) {



Log.d
("score", "Retrieved " +
scoreList.size
() + " scores");



} else {



Log.d
("score", "Error: " +
e.getMessage
());



}



}


});

Parse Example (Both)


In order for the data to be available locally, the parse
queries must have the cache policy set


iOS


query.cachePolicy

=
kPFCachePolicyNetworkElseCache
;


Android


query.setCachePolicy
(
ParseQuery.CachePolicy.NETWORK_E
LSE_CACHE
);

Resources


http://fyrecloud.com/amsler


https
://
parse.com/docs/ios_guide


https://
parse.com/docs/android_guide


http://developer.android.com/training/cloudsync/i
ndex.html

Questions?