DADataTable/briefcase combo

I want to use a a DADataTable/briefcase combo in iOS, and though it’s not strictly a Fire question, is this a sensible thing to use when it’s just local, rather than using SQL lite? If so, are there any docs on how to create a table to add to a briefcase for local storage using Xcode or Oxygene (which is what I’m using of course).

Moved to DA category, so the DA support team can answer this. Short answer: yes should be feasible, but you’ll have to create the DADataTable schema from code, probably, if you have no remote schema to load it from.

Hi Jeremy,

You can think about briefcase as about persistent local data cache at the client side.

Briefcases can solve several problems:

  1. Minimize traffic between the client and the server.
    For example, if you have some stable reference data then there is no need to send it to the client application each time when it being started. You can read it once and then store it in the local briefcase and then load it when you need it.

  2. Persisting data between application sessions. As the sample - you can work with the data in “offline” mode, without persistent connection to the server.
    In this case you can write down your tables data with the changes to the briefcase and shut down your application.
    Later, when you will be able to reach the server you can run your application again and apply the persisted changes back to the server.

Internally briefcase is just set of serialized DADataTables with their data and changes (plus set of custom properties).
Thus common way of using briefcases is following:

// 
// ------------------------------------------------------------------------
// 

// here you get your table with the data from the server
DADataTable *table = [dataAdapter getDataTable:@"Clients"];

// you can change something in that table for certain row ..
DADataTableRow *r = table.rows[0];
NSDate *currentDate = [NSDate date];
r[@"RegistrationDate"] = currentDate;

// and now you can save that table to the briefcase

// Make some preparations like define the name and destination for your briefcase (you need to do that only once)
NSArray *appSupportPath = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *appHomeFolder = [appSupportPath[0] stringByAppendingString:@"/RemObjects/Briefcase"] ;
[[NSFileManager defaultManager] createDirectoryAtPath:appHomeFolder withIntermediateDirectories:YES attributes:nil error:nil];
NSString *fullBriefcaseName = [appHomeFolder stringByAppendingFormat:@"/%@", @"MyBriefcase"];

// Create briefcase
DABriefcase *briefcase = [DABriefcase briefcaseWithFolder:fullBriefcaseName];

// Add tables to the briefcase
[briefcase addTables:@[ordersTable, detailsTable]];


// You also can specify some additional properties for your briefcase (that's an optional step)
briefcase.properties[@"VERSION"] = @"v.0.1";
briefcase.properties[@"DATE"] = [NSDate date];
        
// Write briefcase to file system...
[briefcase writeBriefcase];


// 
// ------------------------------------------------------------------------
// 
// Now imagine that your application was restarted ....
// And you can restore previously saved briefcase back into DADataTables
// 
// ------------------------------------------------------------------------
//


// open briefcase
DABriefcase *briefcase = [DABriefcase briefcaseWithFolder:fullBriefcaseName];

// You can access its properties and implement some logic according your needs...
NSLog(@"Briefcase version is: %@", briefcase.properties[@"VERSION"]);
NSLog(@"Briefcase update date is: %@", briefcase.properties[@"DATE"]);

// And now restore table...
DADataTable *clientsTable = [briefcase tableNamed:@"Clients"];

// Note that all data including pending change was restored
BOOL hasChanges = [clientsTable hasChanges];

// And finally you can try to apply pending changes at the server side:
[dataAdapter applyChangesForTable:clientsTable];

// don't forget to sync changed table back to the briefcase
[briefcase addTable:clientsTable];
[briefcase writeBriefcase];

// 
// ------------------------------------------------------------------------
//

Thanks Alex, I understand. I have created 2 briefcases, one for data that does come from a server (static, changes only a few times a year), which is just for lookups on the device, and a second for user’s data.

I was looking for some info on creating a DA table in code, though I’ve now just created it on the server and let the schema handle it as that got me going, but also, is this a sensible thing to do, given that the user data tables are never going to be applied back to the server, they will remain local on the device.

hm, if you don’t need to save your data to the DA server then I can suggest to use CoreData with SQLite or XML storages (depending on amount of your data and ways of using these data. Briefcases are good when you need to persist your DADataTables data and changes.

OK, thanks Alex, I will do that.