Skip to content

Commit 3d2d84b

Browse files
author
li6185377
committed
fix bug
1 parent 971e4e2 commit 3d2d84b

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

LKDBHelper/Helper/NSObject+LKModel.m

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,37 +353,53 @@ -(id)singlePrimaryKeyValue
353353
+(LKModelInfos *)getModelInfos
354354
{
355355
static __strong NSMutableDictionary* oncePropertyDic;
356+
static __strong NSRecursiveLock* lock;
357+
356358
static dispatch_once_t onceToken;
357359
dispatch_once(&onceToken, ^{
360+
lock = [[NSRecursiveLock alloc]init];
358361
oncePropertyDic = [[NSMutableDictionary alloc]initWithCapacity:8];
359362
});
360363

361364
LKModelInfos* infos;
362-
@synchronized(self)
365+
[lock lock];
366+
367+
infos = [oncePropertyDic objectForKey:NSStringFromClass(self)];
368+
if(infos == nil)
363369
{
364-
infos = [oncePropertyDic objectForKey:NSStringFromClass(self)];
365-
if(infos == nil)
370+
NSMutableArray* pronames = [NSMutableArray array];
371+
NSMutableArray* protypes = [NSMutableArray array];
372+
NSDictionary* keymapping = [self getTableMapping];
373+
[self getSelfPropertys:pronames protypes:protypes];
374+
375+
NSArray* pkArray = [self getPrimaryKeyUnionArray];
376+
if(pkArray.count == 0)
366377
{
367-
NSMutableArray* pronames = [NSMutableArray array];
368-
NSMutableArray* protypes = [NSMutableArray array];
369-
NSDictionary* keymapping = [self getTableMapping];
370-
[self getSelfPropertys:pronames protypes:protypes];
371-
372-
NSArray* pkArray = [self getPrimaryKeyUnionArray];
373-
if(pkArray.count == 0)
378+
pkArray = nil;
379+
NSString* pk = [self getPrimaryKey];
380+
if([LKDBUtils checkStringIsEmpty:pk] == NO)
374381
{
375-
pkArray = nil;
376-
NSString* pk = [self getPrimaryKey];
377-
if([LKDBUtils checkStringIsEmpty:pk] == NO)
382+
pkArray = [NSArray arrayWithObject:pk];
383+
}
384+
}
385+
if([self isContainParent] && [self superclass] != [NSObject class])
386+
{
387+
LKModelInfos* superInfos = [[self superclass] getModelInfos];
388+
for (int i=0; i<superInfos.count; i++) {
389+
LKDBProperty* db_p = [superInfos objectWithIndex:i];
390+
if(db_p.propertyName && db_p.propertyType && [db_p.propertyName isEqualToString:@"rowid"]==NO)
378391
{
379-
pkArray = [NSArray arrayWithObject:pk];
392+
[pronames addObject:db_p.propertyName];
393+
[protypes addObject:db_p.propertyType];
380394
}
381395
}
382-
383-
infos = [[LKModelInfos alloc]initWithKeyMapping:keymapping propertyNames:pronames propertyType:protypes primaryKeys:pkArray];
384-
[oncePropertyDic setObject:infos forKey:NSStringFromClass(self)];
385396
}
397+
398+
infos = [[LKModelInfos alloc]initWithKeyMapping:keymapping propertyNames:pronames propertyType:protypes primaryKeys:pkArray];
399+
[oncePropertyDic setObject:infos forKey:NSStringFromClass(self)];
386400
}
401+
402+
[lock unlock];
387403
return infos;
388404

389405
}
@@ -469,10 +485,6 @@ + (void)getSelfPropertys:(NSMutableArray *)pronames protypes:(NSMutableArray *)p
469485
}
470486
}
471487
free(properties);
472-
if([self isContainParent] && [self superclass] != [NSObject class])
473-
{
474-
[[self superclass] getSelfPropertys:pronames protypes:protypes];
475-
}
476488
}
477489

478490
#pragma mark - log all property

LKDBHelper/LKTestModels.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
#import <Foundation/Foundation.h>
1010
#import "LKDBHelper.h"
1111

12-
@interface LKTestForeign : NSObject
13-
@property int addid;
12+
@interface LKTestForeignSuper : NSObject
1413
@property(copy,nonatomic)NSString* address;
1514
@property int postcode;
1615
@end
1716

17+
@interface LKTestForeign : LKTestForeignSuper
18+
@property int addid;
19+
@end
20+
1821

1922

2023
@interface LKTest : NSObject

LKDBHelper/LKTestModels.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,18 @@ +(NSString *)getTableName
173173
{
174174
return @"LKTestAddress";
175175
}
176+
+(BOOL)isContainParent
177+
{
178+
return YES;
179+
}
176180
+(int)getTableVersion
177181
{
178182
return 1;
179183
}
180184
@end
181185

186+
@implementation LKTestForeignSuper
187+
@end
182188

183189

184190

0 commit comments

Comments
 (0)