Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling (Jesper) #25

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7ce1d3d
Work in progress…. (error handling)
jjepsen Oct 15, 2013
64db362
Work in progress….
jjepsen Oct 15, 2013
4788fab
Work in progress...
jjepsen Oct 15, 2013
2daebff
Work in progress...
jjepsen Oct 15, 2013
ce7fb05
Error handling strategy updated.
jjepsen Oct 17, 2013
35ef80c
Setters updated to conform with new error strategy.
jjepsen Oct 18, 2013
5e4671a
Work in progress..
jjepsen Oct 22, 2013
b975bfd
First version of new error handling which passes all unit tests.
jjepsen Oct 22, 2013
ba3512e
Updated read and write transactions in shared groups.
jjepsen Oct 24, 2013
abf4fad
Work in progress...
jjepsen Oct 25, 2013
57dabc4
Error handling for shared groups completed
jjepsen Oct 28, 2013
23c48f8
Error handing updated for groups.
jjepsen Oct 29, 2013
5f7a2f4
Merge branch 'error_handling' of github.com:Tightdb/tightdb_objc into…
Oct 30, 2013
6d551e8
sharedgroup doc intro NSError in transactions updated
Oct 30, 2013
98fcd25
group updated with new signatures + removed wrong method call in dyn …
Oct 30, 2013
ced7c98
Support for somthing like addOrInsertRowAtIndex:name:age:hired…..
jjepsen Oct 30, 2013
950f616
query fix
Oct 30, 2013
82bf12e
typo
Oct 30, 2013
47ae2a8
Merge branch 'error_handling' of github.com:Tightdb/tightdb_objc into…
Oct 30, 2013
f54c0d8
method insertAtIndex keeping
Oct 30, 2013
8263d67
Merge branch 'master' of github.com:Tightdb/tightdb_objc into error_h…
jjepsen Oct 30, 2013
11741e4
Work in progress….
jjepsen Oct 30, 2013
8ce1397
Merge pull request #12 from mekjaer/update_examples
jjepsen Oct 30, 2013
8f96f53
Updated two test cases which failed
jjepsen Oct 30, 2013
ff8a96c
More error handling in group.
jjepsen Oct 30, 2013
3a6554f
Merge branch 'master' into error_handling
kspangsege Feb 24, 2014
14fc4f6
Work in progress
kspangsege Feb 24, 2014
51d17b5
Work in progress
kspangsege Feb 24, 2014
b83b806
Work in progress
kspangsege Feb 24, 2014
5da7650
Work in progress
kspangsege Feb 24, 2014
212f150
Work in progress
kspangsege Feb 24, 2014
2f8be4b
Work in progress
kspangsege Feb 24, 2014
1b6980a
Merge branch 'master' into error_handling
kspangsege Feb 24, 2014
992f2d5
Merge branch 'master' into error_handling
kspangsege Feb 25, 2014
821333b
Work in progress
kspangsege Feb 25, 2014
3d365e4
Work in progress
kspangsege Feb 25, 2014
f65133f
Merge branch 'master' into error_handling
kspangsege Feb 25, 2014
67fbc88
Work in progress
kspangsege Feb 25, 2014
d037a98
Work in progress
kspangsege Feb 25, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions doc/error_handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Category 1: NSError for "expected" problems
===========================================
Characterized by: File access problem, network access problems.... User should be informed. Problems which cannot be eliminated during development.

- Writing a group to a file, with file access problems.


Category 2: NSException for "unexpected" problems - no recovery
===============================================================
Characterized by: Fatal errors. Wrong use of API. Application should rightfully crash. These problems should be eliminated during development. Feedback should be fast and direct in the form of an exception. The
application should not attempt to catch the exception.

- Indexing out of bounds.
- Passing illegal parameter type.
- Writing to read only table (working assumption).
- Core library exceptions.


Category 3: NSException for "unexpected" problems - with recovery
=================================================================
Technically possible with ARC safe exceptions flag. Leads to excessive release code (automatically inserted). Should not be needed.








19 changes: 9 additions & 10 deletions doc/ref/examples/ex_objc_group_intro.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ int main()

/* Creates a group and uses it to create a new table. */

TightdbGroup *group = [TightdbGroup group];
PeopleTable *table = [group getTable:@"people" withClass:[PeopleTable class]];
TightdbGroup* group = [TightdbGroup group];
PeopleTable* table = [group getTable:@"people" withClass:[PeopleTable class] error:nil];

/* Adds values to the table. */

Expand All @@ -31,26 +31,25 @@ int main()
/* Write the group (and the contained table) to a specified file. */

[[NSFileManager defaultManager] removeItemAtPath:@"filename.tightdb" error:nil];
[group write:@"filename.tightdb"];
[group writeToFile:@"filename.tightdb" withError:nil];

/* Adds another row to the table. Note the update is NOT persisted
automatically (delete the old file and use write again). */

[table addName:@"Sam" Age:17];

[[NSFileManager defaultManager] removeItemAtPath:@"filename.tightdb" error:nil];
[group write:@"filename.tightdb"];
[group writeToFile:@"filename.tightdb" withError:nil];

/* Retrieves an in memory buffer from the group. */

size_t size;
const char *buffer = [group writeToMem:&size];
TightdbBinary* buffer = [group writeToBuffer];

TightdbGroup *groupFromMemory = [TightdbGroup groupWithBuffer:buffer size:size];
PeopleTable *tableFromMemery = [groupFromMemory getTable:@"people" withClass:[PeopleTable class] error:nil];
/* Creates a group from an im memory buffer */
TightdbGroup* groupFromMemory = [TightdbGroup groupWithBuffer:buffer withError:nil];
PeopleTable* tableFromMemery = [groupFromMemory getTable:@"people" withClass:[PeopleTable class] error:nil];

for (PeopleTable_Cursor *cursor in tableFromMemery)
{
for (PeopleTable_Cursor* cursor in tableFromMemery) {
NSLog(@"Name: %@", cursor.Name);
}

Expand Down
60 changes: 51 additions & 9 deletions doc/ref/examples/ex_objc_sharedgroup_intro.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,94 @@
#import <tightdb/objc/table.h>
#import <tightdb/objc/tightdb.h>


TIGHTDB_TABLE_3(PeopleTable,
Name, String,
Age, Int,
Hired, Bool);




int main()
{
@autoreleasepool {

/* Creates a group and uses it to create a new table. */

TightdbSharedGroup *shared = [TightdbSharedGroup groupWithFilename:@"sharedgroup.tightdb"];
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:@"sharedgrouptest.tightdb" error:nil];
[fm removeItemAtPath:@"sharedgrouptest.tightdb.lock" error:nil];

TightdbSharedGroup *shared = [TightdbSharedGroup sharedGroupWithFile:@"sharedgrouptest.tightdb" withError:nil];
if (!shared) {
NSLog(@"Error");
}
else {
NSLog(@"%@", shared);
}

/* A write transaction (with rollback if not first writer to employees table). */
/* A write transaction (with commit). */

[shared writeTransaction:^(TightdbGroup *group) {
NSError *error = nil;
BOOL success;

success = [shared writeTransactionWithError:&error withBlock:^(TightdbGroup *group) {

/* Write transactions with the shared group are possible via the provided variable binding named group. */

PeopleTable *table = [group getTable:@"employees" withClass:[PeopleTable class]];
PeopleTable *table = [group getTable:@"employees" withClass:[PeopleTable class] error:nil];

if ([table count] > 0) {
NSLog(@"Not empty!");
return NO; /* Rollback */
}

[table addName:@"Bill" Age:53 Hired:YES];
NSLog(@"Row added!");
NSLog(@"Commit!");
return YES; /* Commit */
} ];

if(!success)
NSLog(@"Error : %@", [error localizedDescription]);

/* A write transaction (with rollback). */

success = [shared writeTransactionWithError:&error withBlock:^(TightdbGroup *group) {

/* Write transactions with the shared group are possible via the provided variable binding named group. */

PeopleTable *table = [group getTable:@"employees" withClass:[PeopleTable class] error:nil];

if ([table count] > 0) {
NSLog(@"Roll back!");
return NO; /* Rollback */
}

[table addName:@"Bill" Age:53 Hired:YES];
NSLog(@"Commit!");
return YES; /* Commit */
}];

if(!success)
NSLog(@"Error : %@", [error localizedDescription]);

}];

/* A read transaction */

[shared readTransaction:^(TightdbGroup *group) {
[shared readTransactionWithBlock:^(TightdbGroup *group) {

/* Read transactions with the shared group are possible via the provided variable binding named group. */

PeopleTable *table = [group getTable:@"employees" withClass:[PeopleTable class]];
PeopleTable *table = [group getTable:@"employees" withClass:[PeopleTable class] error:nil];

for (PeopleTable_Cursor *curser in table) {
NSLog(@"Name: %@", [curser Name]);
}
}];


}

}

/* @@EndExample@@ */
2 changes: 0 additions & 2 deletions doc/ref/examples/ex_objc_table_dynamic_intro.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ int main()
TightdbCursor *c2 = [table cursorAtIndex:[table count]];
if (c2 != nil)
NSLog(@"Should not get here.");


}
}

Expand Down
10 changes: 4 additions & 6 deletions doc/ref/examples/ex_objc_table_typed_intro.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* @@Example: ex_objc_table_typed_intro @@ */


#import <tightdb/objc/table.h>
#import <tightdb/objc/tightdb.h>

Expand Down Expand Up @@ -28,6 +27,10 @@ int main()
cursor.Name = @"Sofie";
cursor.Age = 40;

[table addOrInsertRowAtIndex:[table count]
Name:@"Jesper"
Age:200];

NSLog(@"The size of the table is now %zd", [table count]);

for (PeopleTable_Cursor *ite in table) {
Expand All @@ -50,12 +53,7 @@ int main()
TightdbCursor *c3 = [table cursorAtIndex:[table count]];
if (c3 != nil)
NSLog(@"Should not get here.");


}
}




/* @@EndExample@@ */
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main()
for (PeopleTable_Cursor *curser in query)
NSLog(@"Name: %lld", [curser Age]);

/* To avoid repeating the same quiry, the result may be stored in
/* To avoid repeating the same query, the result may be stored in
* a table view for multiple access. The following code executes the
* query once and saves the result in a table view. */

Expand Down
53 changes: 18 additions & 35 deletions src/tightdb/objc/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,15 @@
-(void)setNdx:(size_t)ndx;
-(size_t)index;

-(BOOL)setInt:(int64_t)value inColumn:(size_t)colNdx;
-(BOOL)setInt:(int64_t)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setString:(NSString *)value inColumn:(size_t)colNdx;
-(BOOL)setString:(NSString *)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setBool:(BOOL)value inColumn:(size_t)colNdx;
-(BOOL)setBool:(BOOL)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setFloat:(float)value inColumn:(size_t)colNdx;
-(BOOL)setFloat:(float)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setDouble:(double)value inColumn:(size_t)colNdx;
-(BOOL)setDouble:(double)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setDate:(time_t)value inColumn:(size_t)colNdx;
-(BOOL)setBinary:(TightdbBinary *)value inColumn:(size_t)colNdx;
-(BOOL)setBinary:(TightdbBinary *)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setMixed:(TightdbMixed *)value inColumn:(size_t)colNdx;
-(BOOL)setMixed:(TightdbMixed *)value inColumn:(size_t)colNdx error:(NSError *__autoreleasing *)error;
-(BOOL)setTable:(TightdbTable *)value inColumn:(size_t)colNdx;
-(void)setInt:(int64_t)value inColumn:(size_t)colNdx;
-(void)setString:(NSString *)value inColumn:(size_t)colNdx;
-(void)setBool:(BOOL)value inColumn:(size_t)colNdx;
-(void)setFloat:(float)value inColumn:(size_t)colNdx;
-(void)setDouble:(double)value inColumn:(size_t)colNdx;
-(void)setDate:(time_t)value inColumn:(size_t)colNdx;
-(void)setBinary:(TightdbBinary *)value inColumn:(size_t)colNdx;
-(void)setMixed:(TightdbMixed *)value inColumn:(size_t)colNdx;
-(void)setTable:(TightdbTable *)value inColumn:(size_t)colNdx;

-(int64_t)getIntInColumn:(size_t)colNdx;
-(NSString *)getStringInColumn:(size_t)colNdx;
Expand All @@ -66,31 +59,21 @@
@interface TightdbAccessor: NSObject
-(id)initWithCursor:(TightdbCursor *)cursor columnId:(size_t)columnId;
-(BOOL)getBool;
-(BOOL)setBool:(BOOL)value;
-(BOOL)setBool:(BOOL)value error:(NSError *__autoreleasing *)error;
-(void)setBool:(BOOL)value;
-(int64_t)getInt;
-(BOOL)setInt:(int64_t)value;
-(BOOL)setInt:(int64_t)value error:(NSError *__autoreleasing *)error;
-(void)setInt:(int64_t)value;
-(float)getFloat;
-(BOOL)setFloat:(float)value;
-(BOOL)setFloat:(float)value error:(NSError *__autoreleasing *)error;
-(void)setFloat:(float)value;
-(double)getDouble;
-(BOOL)setDouble:(double)value;
-(BOOL)setDouble:(double)value error:(NSError *__autoreleasing *)error;
-(void)setDouble:(double)value;
-(NSString *)getString;
-(BOOL)setString:(NSString *)value;
-(BOOL)setString:(NSString *)value error:(NSError *__autoreleasing *)error;
-(void)setString:(NSString *)value;
-(TightdbBinary *)getBinary;
-(BOOL)setBinary:(TightdbBinary *)value;
-(BOOL)setBinary:(TightdbBinary *)value error:(NSError *__autoreleasing *)error;
-(BOOL)setBinary:(const char *)data size:(size_t)size;
-(BOOL)setBinary:(const char *)data size:(size_t)size error:(NSError *__autoreleasing *)error;
-(void)setBinary:(TightdbBinary *)value;
-(time_t)getDate;
-(BOOL)setDate:(time_t)value;
-(BOOL)setDate:(time_t)value error:(NSError *__autoreleasing *)error;
-(BOOL)setSubtable:(TightdbTable *)subtable;
-(void)setDate:(time_t)value;
-(void)setSubtable:(TightdbTable *)value;
-(id)getSubtable:(Class)obj;
-(TightdbMixed *)getMixed;
-(BOOL)setMixed:(TightdbMixed *)value;
-(BOOL)setMixed:(TightdbMixed *)value error:(NSError *__autoreleasing *)error;
-(void)setMixed:(TightdbMixed *)value;
@end
Loading