2007-01-03 05:41:16 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <EOAccess/EOAccess.h>
|
|
|
|
#include <EOControl/EOControl.h>
|
|
|
|
|
2007-05-01 20:51:18 +00:00
|
|
|
int
|
|
|
|
main(int arcg, char *argv[], char **envp)
|
2007-01-03 05:41:16 +00:00
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2007-01-05 15:06:22 +00:00
|
|
|
EOModelGroup *group = [EOModelGroup defaultGroup];
|
|
|
|
EOModel *model;
|
|
|
|
EOAdaptor *adaptor;
|
|
|
|
EOAdaptorContext *context;
|
|
|
|
EOAdaptorChannel *channel;
|
|
|
|
EOEditingContext *ec;
|
|
|
|
EODatabaseDataSource *authorsDS;
|
|
|
|
NSArray *authors;
|
|
|
|
id author;
|
|
|
|
|
|
|
|
model = [group modelNamed:@"library"];
|
|
|
|
|
|
|
|
/* Tools don't have resources so we have to add the model manually */
|
|
|
|
if (!model)
|
|
|
|
{
|
2007-05-01 20:51:18 +00:00
|
|
|
NSString *path = @"./library.eomodel";
|
|
|
|
model = [[EOModel alloc] initWithContentsOfFile: path];
|
2007-01-05 15:06:22 +00:00
|
|
|
[group addModel:model];
|
2007-05-01 20:51:18 +00:00
|
|
|
[model release];
|
2007-01-05 15:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adaptor = [EOAdaptor adaptorWithModel:model];
|
|
|
|
context = [adaptor createAdaptorContext];
|
|
|
|
channel = [context createAdaptorChannel];
|
|
|
|
ec = [[EOEditingContext alloc] init];
|
2007-05-01 20:51:18 +00:00
|
|
|
authorsDS
|
|
|
|
= [[EODatabaseDataSource alloc] initWithEditingContext: ec
|
|
|
|
entityName:@"authors"];
|
2007-01-03 05:41:16 +00:00
|
|
|
|
|
|
|
[channel openChannel];
|
|
|
|
|
2007-01-05 15:06:22 +00:00
|
|
|
/* Create a new author object */
|
|
|
|
author = [authorsDS createObject];
|
|
|
|
[author takeValue:@"Anonymous" forKey:@"name"];
|
|
|
|
[authorsDS insertObject:author];
|
|
|
|
[ec saveChanges];
|
|
|
|
|
|
|
|
|
|
|
|
/* Fetch the newly inserted object from the database */
|
|
|
|
authors = [authorsDS fetchObjects];
|
|
|
|
NSLog(@"%@", authors);
|
|
|
|
|
|
|
|
/* Update the authors name */
|
|
|
|
[[authors objectAtIndex:0]
|
|
|
|
takeValue:@"John Doe" forKey:@"name"];
|
|
|
|
[ec saveChanges];
|
|
|
|
|
|
|
|
NSLog(@"%@", [authorsDS fetchObjects]);
|
2007-01-03 05:41:16 +00:00
|
|
|
|
|
|
|
[channel closeChannel];
|
|
|
|
[pool release];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|