forked from apaffenholz/PolyViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseAccess.m
More file actions
106 lines (78 loc) · 3.63 KB
/
DatabaseAccess.m
File metadata and controls
106 lines (78 loc) · 3.63 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// DatabaseAccess.m
// PolyViewer
//
// Created by Andreas Paffenholz on 08/02/14.
//
//
#import "DatabaseAccess.h"
#import "AppController.h"
@implementation DatabaseAccess
@synthesize database = _database;
@synthesize collection = _collection;
@synthesize ID = _ID;
@synthesize databases = _databases;
@synthesize collections = _collections;
@synthesize reportNumberOfResults = _reportNumberOfResults;
@synthesize amount = _amount;
@synthesize skip = _skip;
/***************************************************************/
-(id) init {
NSLog(@"[DatabaseAccess init] called");
self = [super init];
if ( self ) {
_databases = [[[NSApp delegate] databaseNames] retain];
[self setSkip:@"0"];
[self setAmount:@"10"];
}
return self;
}
/***************************************************************/
- (IBAction)updateAdditionalPropertiesDict:(id)sender {
NSLog(@"[DatabaseAccess updateAdditionalPropertiesDict] recieved: %@", sender);
NSString * props = [sender stringValue];
NSLog(@"[DatabaseAccess updateAdditionalPropertiesDict] extracted props: %@", props);
NSMutableDictionary *propDict = [[NSMutableDictionary alloc] init];
if ( [props length] > 0 ) {
NSArray *objects = [props componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"=,"]];
NSLog(@"[DatabaseAccess updateAdditionalPropertiesDict] additional properties as array: %@", objects);
for (int i=0; i<[objects count]; i=i+2) {
[propDict setObject:[objects[i+1] stringByReplacingOccurrencesOfString:@">" withString:@""] forKey:[objects[i] stringByReplacingOccurrencesOfString:@"\"" withString:@""]];
}
}
_additionalPropertiesDict = [propDict retain];
NSLog(@"[DatabaseAccess updateAdditionalPropertiesDict] additional properties as dict: %@", _additionalPropertiesDict);
}
/***************************************************************/
- (NSString *) additionalPropertiesAsString {
NSLog(@"[DatabaseAccess additionalPropertiesAsString] entering, current dict is: %@", _additionalPropertiesDict);
NSString * props = [[NSString alloc] init];
for ( NSString *prop in [_additionalPropertiesDict allKeys] ) {
props = [props stringByAppendingFormat:@"\"%@\"=>%@,",prop,[_additionalPropertiesDict objectForKey:prop]];
}
if ([props length] > 0) {
props = [props substringToIndex:[props length] - 1];
}
NSLog(@"[DatabaseAccess additionalPropertiesAsString] returning: %@", props);
return props;
}
/***************************************************************/
- (NSInteger)queryDBwithDatabase:db andCollection:coll {
NSLog(@"[DatabaseAcces queryDBwithDatabase: andCollection:] selected database: %@ and collection: %@", db, coll);
NSInteger count = 0;
if ( [coll length] != 0 && coll != NULL && coll != nil )
count = [[NSApp delegate] countForDatabase:db
andCollection:coll
withAddtionalProperties:[self additionalPropertiesAsString]];
return count;
}
/***************************************************************/
- (NSArray *)getIDsForDatabase:db andCollection:coll {
_IDs = [[NSApp delegate] idsForDatabase:db
andCollection:coll
withAddtionalProperties:[self additionalPropertiesAsString]
restrictToAmount:[[self amount] intValue]
startingAt:[[self skip] intValue]];
return _IDs;
}
@end