PageRenderTime 29ms CodeModel.GetById 21ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/database/ENSyncObject.m

http://github.com/enloyee/ENSQLite
Objective C | 75 lines | 53 code | 15 blank | 7 comment | 2 complexity | 15885759b29fd5f2b33dc3b41567b370 MD5 | raw file
 1//
 2//  ENSyncObject.m
 3//  Jacob's Menu
 4//
 5//  Created by enloyee on 11-11-14.
 6//  Copyright (c) 2011enloyee. All rights reserved.
 7//
 8
 9#import "ENSyncObject.h"
10
11#define kENCreateDateKey    @"create_date"
12#define kENUpdateDateKey    @"update_date"
13
14@interface ENSyncObject()
15
16@property (retain, nonatomic) NSDate *createDate;
17@property (retain, nonatomic) NSDate *updateDate;
18
19@end
20
21@implementation ENSyncObject
22
23- (id)init
24{
25    if (self = [super init])
26    {
27        self.createDate = nil;
28        self.updateDate = nil;
29    }
30    return self;
31}
32
33- (NSDate *)createDate
34{
35    double value = [self doubleForKey:kENCreateDateKey];
36    return [NSDate dateWithTimeIntervalSince1970:value];
37}
38
39- (void)setCreateDate:(NSDate *)createDate
40{
41    [self setDouble:[createDate timeIntervalSince1970] forKey:kENCreateDateKey];
42}
43
44- (NSDate *)updateDate
45{
46    double value = [self doubleForKey:kENUpdateDateKey];
47    return [NSDate dateWithTimeIntervalSince1970:value];
48}
49
50- (void)setUpdateDate:(NSDate *)updateDate
51{
52    [self setDouble:[updateDate timeIntervalSince1970] forKey:kENUpdateDateKey];
53}
54
55- (BOOL)store
56{
57    return [self storeUseTransactions:YES];
58}
59
60- (BOOL)storeUseTransactions:(BOOL)useTransactions
61{
62    BOOL update = [self isSaved];
63    NSDate *date = [NSDate date];
64    if (update)
65        self.updateDate = date;
66    else
67    {
68        self.createDate = date;
69        self.updateDate = date;
70    }
71    
72    return [super storeUseTransactions:useTransactions];
73}
74
75@end