libs-gdl2/Examples/eoexample.m
David Ayers 4d73ac52dd * Documentation/GDL2Intro/Examples: Move to ...
* Examples: ... here.
	* Examples/GNUmakefile: Adapt to new location.
	* Documentation/GDL2Intro/GNUmakefile: Remove subproject.
	* Documentation/GDL2Intro/GDL2Intro.texi: Update references to new
	location.
	* Trading: Move to ...
	* Examples/Trading: ... here.
	* Examples/Trading/GNUmakefile: Adapte to new location.
	* Examples/GNUmakefile: Add Trading.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@27918 72102866-910b-0410-8b05-ffd578937521
2009-02-18 17:21:05 +00:00

62 lines
1.6 KiB
Objective-C

#include <Foundation/Foundation.h>
#include <EOAccess/EOAccess.h>
#include <EOControl/EOControl.h>
int
main(int arcg, char *argv[], char **envp)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
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)
{
NSString *path = @"./library.eomodel";
model = [[EOModel alloc] initWithContentsOfFile: path];
[group addModel:model];
[model release];
}
adaptor = [EOAdaptor adaptorWithModel:model];
context = [adaptor createAdaptorContext];
channel = [context createAdaptorChannel];
ec = [[EOEditingContext alloc] init];
authorsDS
= [[EODatabaseDataSource alloc] initWithEditingContext: ec
entityName:@"authors"];
[channel openChannel];
/* 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]);
[channel closeChannel];
[pool release];
return 0;
}