This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
COStore.m
95 lines (76 loc) · 2.4 KB
/
COStore.m
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
#import "COStore.h"
#import <EtoileFoundation/Macros.h>
#import "COPersistentRootPrivate.h"
#import "COSQLiteStore.h"
@implementation COStore
- (id)initWithURL: (NSURL*)aURL
{
SUPERINIT;
store_ = [[COSQLiteStore alloc] initWithURL: aURL];
return self;
}
- (void)dealloc
{
[store_ release];
[rootForUUID_ release];
[super dealloc];
}
- (NSURL*)URL
{
return [store_ URL];
}
- (void) fetchPersistentRoots
{
if (rootForUUID_ == nil)
{
rootForUUID_ = [[NSMutableDictionary alloc] init];
for (COUUID *uuid in [store_ persistentRootUUIDs])
{
[self cachePersistentRootEditPlist: [store_ persistentRootWithUUID: uuid]];
}
}
}
- (COPersistentRoot *) cachePersistentRootEditPlist: (COPersistentRootState *)persistentRoot
{
[self fetchPersistentRoots];
COPersistentRoot *root = [[[COPersistentRoot alloc] initWithStoreEditQueue: self
persistentRoot: persistentRoot] autorelease];
[rootForUUID_ setObject: root forKey: [root UUID]];
return root;
}
- (NSSet *) persistentRoots
{
[self fetchPersistentRoots];
return [NSSet setWithArray: [rootForUUID_ allValues]];
}
- (COPersistentRoot *) persistentRootWithUUID: (COUUID *)aUUID
{
[self fetchPersistentRoots];
COPersistentRoot *root = [rootForUUID_ objectForKey: aUUID];
return root;
}
- (COPersistentRoot *) createPersistentRootWithInitialContents: (COEditingContext *)contents
metadata: (NSDictionary *)metadata
{
COPersistentRootState *persistentRoot = [store_ createPersistentRootWithInitialContents: contents metadata: metadata];
return [self cachePersistentRootEditPlist: persistentRoot];
}
- (COPersistentRoot *) createPersistentRootWithInitialRevision: (CORevisionID *)aRevision
metadata: (NSDictionary *)metadata
{
COPersistentRootState *persistentRoot = [store_ createPersistentRootWithInitialRevision: aRevision metadata: metadata ];
return [self cachePersistentRootEditPlist: persistentRoot];
}
- (void) deletePersistentRootWithUUID: (COUUID *)aUUID
{
[self fetchPersistentRoots];
[store_ deletePersistentRoot: aUUID];
[rootForUUID_ removeObjectForKey: aUUID];
}
@end
@implementation COStore (Private)
- (COSQLiteStore *)store
{
return store_;
}
@end