Skip to content

Commit 69400b6

Browse files
committed
format
1 parent 4980414 commit 69400b6

7 files changed

Lines changed: 1315 additions & 1437 deletions

File tree

CCSQLite/CCKeyValue.m

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,54 @@
1111

1212
@interface CCKeyValue ()
1313

14-
@property (atomic, copy) NSString *path;
14+
@property (atomic, copy) NSString * path;
1515

1616
@property (atomic, copy) CCSQLiteSerializer objectSerializer;
1717
@property (atomic, copy) CCSQLiteDeserializer objectDeserializer;
1818

19-
- (void) setObject: (id) object key : (NSString *) key;
20-
- (id) objectForKey : (NSString *) key;
19+
- (void) setObject:(id)object key:(NSString *)key;
20+
- (id) objectForKey:(NSString *)key;
2121

2222
@end
2323

2424
@implementation CCKeyValue
2525

26-
+ (CCKeyValue *) defaultKeyValueWithPath : (NSString *)path {
27-
static CCKeyValue *kv = nil;
28-
26+
+ (CCKeyValue *) defaultKeyValueWithPath:(NSString *)path {
27+
static CCKeyValue * kv = nil;
28+
2929
static dispatch_once_t onceToken;
30+
3031
dispatch_once(&onceToken, ^{
3132
kv = [CCKeyValue new];
3233
kv.valueType = CCKeyValueTypeDefault;
3334
});
34-
35+
3536
kv.path = path;
36-
37+
3738
return kv;
3839
}
3940

40-
- (void) setObject: (id) object key : (NSString *) key inCollection: (NSString *) collection metadata: (NSData *)metadata {
41+
- (void) setObject:(id)object key:(NSString *)key inCollection:(NSString *)collection metadata:(NSData *)metadata {
4142
if (!_path || ![_path isKindOfClass:[NSString class]]) {
4243
NSLog(@"The actual path of the database must be obtained!");
4344
return;
4445
}
45-
46-
NSString *c = nil;
47-
46+
47+
NSString * c = nil;
48+
4849
if (!collection || ![collection isKindOfClass:[NSString class]]) {
4950
c = CCSQLiteCollection;
5051
} else {
5152
c = collection;
5253
}
53-
54+
5455
if (!key || ![key isKindOfClass:[NSString class]]) {
5556
NSLog(@"key is illegal");
5657
return;
5758
}
58-
59+
5960
self.objectSerializer = [CCSQLite defaultSerializer];
60-
61+
6162
switch (_valueType) {
6263
case CCKeyValueTypePropertyList:
6364
self.objectSerializer = [CCSQLite propertyListSerializer];
@@ -71,45 +72,45 @@ - (void) setObject: (id) object key : (NSString *) key inCollection: (NSString *
7172
default:
7273
break;
7374
}
74-
75-
NSData *data = self.objectSerializer(c, key, object);
76-
77-
CCSQLiteQueue *innerQueue = [CCSQLiteQueue databaseQueueWithPath: _path];
75+
76+
NSData * data = self.objectSerializer(c, key, object);
77+
78+
CCSQLiteQueue * innerQueue = [CCSQLiteQueue databaseQueueWithPath:_path];
7879

7980
__block BOOL isOK = NO;
80-
[innerQueue inTransaction:^(CCSQLite *db, BOOL *rollback) {
81-
isOK = [db executeUpdate:@"insert into 'CCSQLite.Database2' (collection, key, data, metadata) values (?, ?, ?, ?);", c, key, data, metadata];
82-
83-
if (!isOK) {
84-
isOK = [db executeUpdate:@"update 'CCSQLite.Database2' set data = ? , metadata = ? where collection = ? and key = ?;", data, metadata, c, key];
85-
}
86-
87-
if (!isOK) {
88-
NSLog(@"execute excpetion!");
89-
}
90-
91-
*rollback = !isOK;
92-
}];
93-
}
81+
[innerQueue inTransaction:^(CCSQLite * db, BOOL * rollback) {
82+
isOK = [db executeUpdate:@"insert into 'CCSQLite.Database2' (collection, key, data, metadata) values (?, ?, ?, ?);", c, key, data, metadata];
83+
84+
if (!isOK) {
85+
isOK = [db executeUpdate:@"update 'CCSQLite.Database2' set data = ? , metadata = ? where collection = ? and key = ?;", data, metadata, c, key];
86+
}
9487

88+
if (!isOK) {
89+
NSLog(@"execute excpetion!");
90+
}
9591

96-
- (id) objectForKey : (NSString *) key inCollection: (NSString *) collection {
97-
NSString *c = nil;
92+
*rollback = !isOK;
93+
}];
94+
} /* setObject */
95+
96+
97+
- (id) objectForKey:(NSString *)key inCollection:(NSString *)collection {
98+
NSString * c = nil;
9899
__block id object = nil;
99-
100+
100101
if (!collection || ![collection isKindOfClass:[NSString class]]) {
101102
c = CCSQLiteCollection;
102103
} else {
103104
c = collection;
104105
}
105-
106+
106107
if (!key || ![key isKindOfClass:[NSString class]]) {
107108
NSLog(@"key is illegal");
108109
return object;
109110
}
110-
111+
111112
self.objectDeserializer = [CCSQLite defaultDeserializer];
112-
113+
113114
switch (_valueType) {
114115
case CCKeyValueTypePropertyList:
115116
self.objectDeserializer = [CCSQLite propertyListDeserializer];
@@ -124,30 +125,30 @@ - (id) objectForKey : (NSString *) key inCollection: (NSString *) collection {
124125
break;
125126
}
126127

127-
CCSQLiteQueue *innerQueue = [CCSQLiteQueue databaseQueueWithPath: _path];
128-
129-
NSString *sql = [NSString stringWithFormat:@"select * from '%@' where key = '%@' and collection = '%@';", CCSQLiteDatabase2, key, c];
130-
131-
__block NSData *data = nil;
132-
[innerQueue inDatabase:^(CCSQLite *db) {
133-
CCResultSet *r = [db executeQuery:sql];
134-
while ([r next]) {
135-
data = [r dataForColumn:CCKeyValueDataKey];
136-
object = self.objectDeserializer(c, key, data);
137-
break;
138-
}
139-
140-
[r close];
141-
}];
142-
128+
CCSQLiteQueue * innerQueue = [CCSQLiteQueue databaseQueueWithPath:_path];
129+
130+
NSString * sql = [NSString stringWithFormat:@"select * from '%@' where key = '%@' and collection = '%@';", CCSQLiteDatabase2, key, c];
131+
132+
__block NSData * data = nil;
133+
[innerQueue inDatabase:^(CCSQLite * db) {
134+
CCResultSet * r = [db executeQuery:sql];
135+
while ([r next]) {
136+
data = [r dataForColumn:CCKeyValueDataKey];
137+
object = self.objectDeserializer(c, key, data);
138+
break;
139+
}
140+
141+
[r close];
142+
}];
143+
143144
return object;
144-
}
145+
} /* objectForKey */
145146

146-
- (void) setObject: (id) object key : (NSString *) key {
147+
- (void) setObject:(id)object key:(NSString *)key {
147148
[self setObject:object key:key inCollection:nil metadata:nil];
148149
}
149150

150-
- (id) objectForKey : (NSString *) key {
151+
- (id) objectForKey:(NSString *)key {
151152
return [self objectForKey:key inCollection:nil];
152153
}
153154

CCSQLite/CCOptions.m

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ @implementation CCOptions
3737
@synthesize aggressiveWALTruncationSize = aggressiveWALTruncationSize;
3838
@synthesize enableMultiProcessSupport = enableMultiProcessSupport;
3939

40-
- (id)init
41-
{
42-
if ((self = [super init]))
43-
{
40+
- (id) init {
41+
if ((self = [super init])) {
4442
corruptAction = CCOptionsCorruptAction_Rename;
4543
pragmaSynchronous = CCOptionsPragmaSynchronous_Full;
4644
pragmaJournalSizeLimit = 0;
@@ -52,9 +50,9 @@ - (id)init
5250
return self;
5351
}
5452

55-
- (id)copyWithZone:(NSZone __unused *)zone
56-
{
57-
CCOptions *copy = [[[self class] alloc] init];
53+
- (id) copyWithZone:(NSZone __unused *)zone {
54+
CCOptions * copy = [[[self class] alloc] init];
55+
5856
copy->corruptAction = corruptAction;
5957
copy->pragmaSynchronous = pragmaSynchronous;
6058
copy->pragmaJournalSizeLimit = pragmaJournalSizeLimit;
@@ -68,7 +66,7 @@ - (id)copyWithZone:(NSZone __unused *)zone
6866
#endif
6967
copy->aggressiveWALTruncationSize = aggressiveWALTruncationSize;
7068
copy->enableMultiProcessSupport = enableMultiProcessSupport;
71-
69+
7270
return copy;
7371
}
7472

0 commit comments

Comments
 (0)