Uh oh!
There was an error while loading. Please reload this page.
forked from bububa/MongoHub-Mac
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabasesArrayController.m
More file actions
Latest commit
85 lines (76 loc) · 2.52 KB
/
Copy pathDatabasesArrayController.m
File metadata and controls
85 lines (76 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// DatabasesArrayCollection.m
// MongoHub
//
// Created by Syd on 10-4-25.
// Copyright 2010 MusicPeace.ORG. All rights reserved.
//
#import"DatabasesArrayController.h"
#import"Connection.h"
#import"Database.h"
@implementationDatabasesArrayController
- (void)awakeFromNib
{
if ([NSArrayControllerinstancesRespondToSelector:@selector(awakeFromNib)])
{
[superawakeFromNib];
}
[selfsetClearsFilterPredicateOnInsertion:NO];
}
- (id)newObjectWithConn:(Connection *) connname:(NSString *)nameuser:(NSString *)userpassword:(NSString *)password
{
id newObj = [supernewObject];
[newObj setValue:conn forKey:@"connection"];
[newObj setValue:name forKey:@"name"];
[newObj setValue:user forKey:@"user"];
[newObj setValue:password forKey:@"password"];
return newObj;
}
- (void)clean:(Connection *)conndatabases:(NSArray *)databases
{
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"connection=%@", conn];
NSArray *dblist = [selfitemsUsingFetchPredicate:predicate];
for (Database *db in dblist) {
bool exist = false;
for (NSString *d in databases) {
if (db.name == d) {
exist = true;
break;
}
}
if (!exist) {
[superremove:db];
}
}
}
- (Database *)dbInfo:(Connection *) connname:(NSString *)name
{
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"connection=%@ AND name=%@", conn, name];
if ([[selfitemsUsingFetchPredicate:predicate] count]>0) {
return [[selfitemsUsingFetchPredicate:predicate] objectAtIndex:0];
}
returnnil;
}
- (BOOL)checkDuplicate:(Connection *) connname:(NSString *)name
{
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"connection=%@ AND name=%@", conn, name];
if ([[selfitemsUsingFetchPredicate:predicate] count]>0) {
returnYES;
}else {
returnNO;
}
}
- (NSArray *)itemsUsingFetchPredicate:(NSPredicate *)fetchPredicate
{
NSError *error = nil;
NSFetchRequest *request = [[[NSFetchRequestalloc] init] autorelease];
[request setEntity:[NSEntityDescriptionentityForName:[selfentityName]
inManagedObjectContext:[selfmanagedObjectContext]]];
NSArray *objects = [[selfmanagedObjectContext]
executeFetchRequest:request error:&error];
if (error) {
NSLog(@"Fetch error! In AWViewPositionArrayController:itemsUseingFetchPredicate");
}
return [objects filteredArrayUsingPredicate:fetchPredicate];
}
@end