Skip to content

Commit

Permalink
Use the Mongo Obj-C driver to get data
Browse files Browse the repository at this point in the history
  • Loading branch information
francois committed Jun 16, 2010
1 parent bfb1303 commit f427d13
Show file tree
Hide file tree
Showing 5 changed files with 783 additions and 261 deletions.
3 changes: 3 additions & 0 deletions DatabaseController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <Cocoa/Cocoa.h>
@class MEConnection;
@class MEDatabase;

@interface DatabaseController : NSWindowController {
MEConnection *connection;
Expand All @@ -16,6 +17,8 @@
@property(nonatomic, copy) NSDictionary *connectionInfo;
@property(nonatomic, retain) IBOutlet NSDrawer *drawer;
@property(nonatomic, copy) NSArray *databases;
@property(nonatomic, retain) IBOutlet NSArrayController *arrayController;
@property(nonatomic, retain) MEDatabase *database;

-(id)initWithConnectionOptions:(NSDictionary *)connectionOptions;

Expand Down
19 changes: 15 additions & 4 deletions DatabaseController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#import "DatabaseController.h"
#import "NewConnectionController.h"
#import "MEConnection.h"
#import "MEDatabase.h"

@implementation DatabaseController

@synthesize connectionInfo, drawer, databases;
@synthesize connectionInfo, drawer, databases, arrayController, database;

-(id)initWithConnectionOptions:(NSDictionary *)connectionOptions {
if (![super initWithWindowNibName:@"Database"]) return nil;
Expand All @@ -29,21 +30,31 @@ -(void)dealloc {
[super dealloc];
}

-(void)updateWindowTitle {
if (connection && [connection connected]) {
self.window.title = [NSString stringWithFormat:@"%@ (connected)", [connection connectionString]];
} else {
self.window.title = [NSString stringWithFormat:@"%@:%@ (disconnected)", [self.connectionInfo objectForKey:MEHost], [self.connectionInfo objectForKey:MEPort]];
}
}

-(void)windowDidLoad {
self.window.title = [NSString stringWithFormat:@"%@:%@", [self.connectionInfo objectForKey:MEHost], [self.connectionInfo objectForKey:MEPort]];
[self updateWindowTitle];
[self.window makeKeyWindow];
[self.drawer openOnEdge:NSMinXEdge];

connection = [[MEConnection alloc] initWithConnectionInfo:self.connectionInfo];
int result = [connection connect];
if (0 == result) {
[self updateWindowTitle];
self.databases = [[connection databases] allObjects];
return;
}

NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText: @"Connection Failure"];
[alert setInformativeText: [NSString stringWithFormat:@"Failed to connect to mongo://%@:%@@%@:%d - mongo_connect() returned: %d",
connection.username, connection.password, connection.host, connection.port, result]];
[alert setInformativeText: [NSString stringWithFormat:@"Failed to connect to %@ - mongo_connect() returned: %d",
connection.connectionString, result]];
[alert beginSheetModalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil];
[alert release];
}
Expand Down
Loading

0 comments on commit f427d13

Please sign in to comment.