Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add statement cache and test case #73

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CTPersistance.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "CTPersistance"
s.version = "181"
s.version = "185"
s.summary = "Objective-C Model Layer with SQLite."

s.description = <<-DESC
Expand Down
96 changes: 90 additions & 6 deletions CTPersistance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
4AF38F2D1F6905DF00801322 /* TestRecord.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A0E00BA1F2CC25A00E6A4DA /* TestRecord.m */; };
4AF38F2F1F69068700801322 /* CTPersistanceTestTransaction.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AF38F2E1F69068700801322 /* CTPersistanceTestTransaction.m */; };
6284DE2109EF43B7A3D56F18 /* libPods-CTPersistance.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 24975DE09A62B809BFED181C /* libPods-CTPersistance.a */; };
7866EEC620F0ABB300819E75 /* CTPersistanceStatementCacheManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7866EEC520F0ABB300819E75 /* CTPersistanceStatementCacheManager.m */; };
786AD97020F88812005B33FB /* CTPersistanceStatementCacheItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 786AD96F20F88812005B33FB /* CTPersistanceStatementCacheItem.m */; };
DAEEF1BE411F617114764D0F /* libPods-CTPersistanceTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D31FADFF56BDD50C7FD9C94 /* libPods-CTPersistanceTests.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -233,6 +235,10 @@
4AE5541320AD1F190020BAC7 /* CTPersistanceTestUpsert.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTPersistanceTestUpsert.m; sourceTree = "<group>"; };
4AF38F2E1F69068700801322 /* CTPersistanceTestTransaction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTPersistanceTestTransaction.m; sourceTree = "<group>"; };
4D31FADFF56BDD50C7FD9C94 /* libPods-CTPersistanceTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CTPersistanceTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
7866EEC420F0ABB300819E75 /* CTPersistanceStatementCacheManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTPersistanceStatementCacheManager.h; sourceTree = "<group>"; };
7866EEC520F0ABB300819E75 /* CTPersistanceStatementCacheManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTPersistanceStatementCacheManager.m; sourceTree = "<group>"; };
786AD96E20F88812005B33FB /* CTPersistanceStatementCacheItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTPersistanceStatementCacheItem.h; sourceTree = "<group>"; };
786AD96F20F88812005B33FB /* CTPersistanceStatementCacheItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTPersistanceStatementCacheItem.m; sourceTree = "<group>"; };
89D41C6489863CB58D4966E5 /* Pods-CTPersistance.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CTPersistance.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CTPersistance/Pods-CTPersistance.debug.xcconfig"; sourceTree = "<group>"; };
AD102503C09A04454242FAC0 /* Pods-CTPersistanceTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CTPersistanceTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CTPersistanceTests/Pods-CTPersistanceTests.debug.xcconfig"; sourceTree = "<group>"; };
D9D5304E203B48D737D87E6F /* Pods-CTPersistanceTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CTPersistanceTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CTPersistanceTests/Pods-CTPersistanceTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -471,6 +477,9 @@
4A0E00741F2CBD6300E6A4DA /* QueryCommand */ = {
isa = PBXGroup;
children = (
7866EEC420F0ABB300819E75 /* CTPersistanceStatementCacheManager.h */,
7866EEC520F0ABB300819E75 /* CTPersistanceStatementCacheManager.m */,
786AD96D20F88755005B33FB /* StatementCache */,
4A5E3BEE1F403A3200946749 /* Statement */,
4A0E00751F2CBD6300E6A4DA /* Categories */,
4A0E00821F2CBD6300E6A4DA /* CTPersistanceQueryCommand.h */,
Expand Down Expand Up @@ -1046,6 +1055,15 @@
path = Upsert;
sourceTree = "<group>";
};
786AD96D20F88755005B33FB /* StatementCache */ = {
isa = PBXGroup;
children = (
786AD96E20F88812005B33FB /* CTPersistanceStatementCacheItem.h */,
786AD96F20F88812005B33FB /* CTPersistanceStatementCacheItem.m */,
);
path = StatementCache;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -1057,6 +1075,8 @@
4A0E00211F2C384E00E6A4DA /* Sources */,
4A0E00221F2C384E00E6A4DA /* Frameworks */,
4A0E00231F2C384E00E6A4DA /* Resources */,
10751F76ED1BC0072083D1EB /* [CP] Embed Pods Frameworks */,
8C4AC309B366006C6CA8BB6A /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -1075,6 +1095,8 @@
4A0E003A1F2C384E00E6A4DA /* Sources */,
4A0E003B1F2C384E00E6A4DA /* Frameworks */,
4A0E003C1F2C384E00E6A4DA /* Resources */,
BCC3FE446475752A1DF7D1B8 /* [CP] Embed Pods Frameworks */,
47D5EC83DAF4AF6795D548BD /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -1097,12 +1119,12 @@
TargetAttributes = {
4A0E00241F2C384E00E6A4DA = {
CreatedOnToolsVersion = 8.3.2;
DevelopmentTeam = THS9SRQVES;
DevelopmentTeam = 74MF5V7Z8J;
ProvisioningStyle = Automatic;
};
4A0E003D1F2C384E00E6A4DA = {
CreatedOnToolsVersion = 8.3.2;
DevelopmentTeam = THS9SRQVES;
DevelopmentTeam = 74MF5V7Z8J;
ProvisioningStyle = Automatic;
TestTargetID = 4A0E00241F2C384E00E6A4DA;
};
Expand Down Expand Up @@ -1149,6 +1171,36 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
10751F76ED1BC0072083D1EB /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CTPersistance/Pods-CTPersistance-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
47D5EC83DAF4AF6795D548BD /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CTPersistanceTests/Pods-CTPersistanceTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
810DA35DC562A3E4A0F26373 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -1167,6 +1219,36 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
8C4AC309B366006C6CA8BB6A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CTPersistance/Pods-CTPersistance-resources.sh\"\n";
showEnvVarsInLog = 0;
};
BCC3FE446475752A1DF7D1B8 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CTPersistanceTests/Pods-CTPersistanceTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
DFE4FB2A9CE5F55E85A7BA6A /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1212,8 +1294,10 @@
4A0E002D1F2C384E00E6A4DA /* AppDelegate.m in Sources */,
4A0E00A41F2CBD6300E6A4DA /* CTPersistanceVersionRecord.m in Sources */,
4A0238741F3FFBA800EE91C7 /* TestTable.m in Sources */,
786AD97020F88812005B33FB /* CTPersistanceStatementCacheItem.m in Sources */,
4AC74A631FBE7DC60092B636 /* ViewRecordAndMergeDemoViewController.m in Sources */,
4AC74A731FBE7EC90092B636 /* ItemDetailTable.m in Sources */,
7866EEC620F0ABB300819E75 /* CTPersistanceStatementCacheManager.m in Sources */,
4A0E002A1F2C384E00E6A4DA /* main.m in Sources */,
4A5E3BF11F403A4A00946749 /* CTPersistanceSqlStatement.m in Sources */,
4ACE635B1F340E54007F3E6D /* NSDictionary+KeyValueBind.m in Sources */,
Expand Down Expand Up @@ -1409,7 +1493,7 @@
baseConfigurationReference = 89D41C6489863CB58D4966E5 /* Pods-CTPersistance.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = THS9SRQVES;
DEVELOPMENT_TEAM = 74MF5V7Z8J;
INFOPLIST_FILE = CTPersistance/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -1423,7 +1507,7 @@
baseConfigurationReference = 0E3659C0BE44F61448420F54 /* Pods-CTPersistance.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = THS9SRQVES;
DEVELOPMENT_TEAM = 74MF5V7Z8J;
INFOPLIST_FILE = CTPersistance/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -1437,7 +1521,7 @@
baseConfigurationReference = AD102503C09A04454242FAC0 /* Pods-CTPersistanceTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = THS9SRQVES;
DEVELOPMENT_TEAM = 74MF5V7Z8J;
INFOPLIST_FILE = CTPersistanceTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = casa.CTPersistanceTests;
Expand All @@ -1451,7 +1535,7 @@
baseConfigurationReference = D9D5304E203B48D737D87E6F /* Pods-CTPersistanceTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = THS9SRQVES;
DEVELOPMENT_TEAM = 74MF5V7Z8J;
INFOPLIST_FILE = CTPersistanceTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = casa.CTPersistanceTests;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
4 changes: 4 additions & 0 deletions CTPersistance/CTPersistance/Database/CTPersistanceDataBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "CTPersistanceVersionTable.h"
#import <CTMediator/CTMediator.h>

#import "CTPersistanceStatementCacheManager.h"

extern SQLITE_API int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);
extern SQLITE_API int sqlite3_rekey(sqlite3 *db, const void *pKey, int nKey);

Expand Down Expand Up @@ -115,6 +117,8 @@ - (void)closeDatabase

_database = NULL;
_databaseFilePath = nil;

[[CTPersistanceStatementCacheManager sharedInstance] clearDatabaseStatementCache:self.databaseName];
}

#pragma mark - private methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ - (instancetype)initWithDatabaseName:(NSString *)databaseName

- (CTPersistanceSqlStatement *)compileSqlString:(NSString *)sqlString bindValueList:(NSMutableArray <NSInvocation *> *)bindValueList error:(NSError *__autoreleasing *)error
{
CTPersistanceSqlStatement *statement = [[CTPersistanceSqlStatement alloc] initWithSqlString:sqlString bindValueList:bindValueList database:self.database error:error];
return statement;
return [[CTPersistanceSqlStatement alloc] initWithSqlString:sqlString bindValueList:bindValueList database:self.database error:error];
}

#pragma mark - getters and setters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CTPersistanceStatementCacheManager.h
// CTPersistance
//
// Created by longjianjiang on 2018/7/7.
// Copyright © 2018年 casa. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CTPersistanceStatementCacheItem.h"

@interface CTPersistanceStatementCacheManager : NSObject

+ (instancetype)sharedInstance;

- (void)setCachedStatement:(CTPersistanceStatementCacheItem *)pStmt forSQLString:(NSString *)sqlString atDatabase:(NSString *)databaseName;
- (CTPersistanceStatementCacheItem *)getCachedStatementWithSQLString:(NSString *)sqlString atDatabase:(NSString *)databaseName;
- (void)removeCachedStatement:(CTPersistanceStatementCacheItem *)pStmt forSQLString:(NSString *)sqlString atDatabase:(NSString *)databaseName;

- (void)clearDatabaseStatementCache:(NSString *)databaseName;

@end
Loading