You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by lg...@apache.org on 2014/04/24 08:51:56 UTC
svn commit: r1589611 [2/2] - in
/chemistry/objectivecmis/branches/browser-binding: ObjectiveCMIS.xcodeproj/
ObjectiveCMIS/ ObjectiveCMIS/Bindings/ ObjectiveCMIS/Bindings/Browser/
ObjectiveCMIS/Client/ ObjectiveCMIS/Common/
Added: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/CMISTypeDefinitionCache.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/CMISTypeDefinitionCache.m?rev=1589611&view=auto
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/CMISTypeDefinitionCache.m (added)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Bindings/CMISTypeDefinitionCache.m Thu Apr 24 06:51:55 2014
@@ -0,0 +1,141 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CMISTypeDefinitionCache.h"
+#import "CMISBindingSession.h"
+#import "CMISLog.h"
+
+// Default type definition cache size is 100 entries
+#define DEFAULT_TYPE_DEFINITION_CACHE_SIZE 100
+
+@interface TypeDefinitionCacheKey : NSObject
+
+@property (nonatomic, strong) NSString *repositoryId;
+@property (nonatomic, strong) NSString *typeDefinitionId;
+
+/// Designated Initializer
++ (TypeDefinitionCacheKey *) initWithTypeDefinitionId:(NSString *)typeDefinitionId repositoryId:(NSString *)repositoryId;
+
+@end
+
+@interface CMISTypeDefinitionCache () <NSCacheDelegate>
+
+@property (nonatomic, strong) NSCache *typeDefinitionCache;
+
+@end
+
+@implementation CMISTypeDefinitionCache
+
+- (id)initWithBindingSession:(CMISBindingSession *)bindingSession
+{
+ self = [super init];
+ if (self) {
+ [self setupTypeDefinitionCache:bindingSession];
+
+ }
+ return self;
+}
+
+- (void)setupTypeDefinitionCache:(CMISBindingSession *)bindingSession
+{
+ self.typeDefinitionCache = [[NSCache alloc] init];
+
+ id typeDefinitionCacheSize = [bindingSession objectForKey:kCMISSessionParameterTypeDefinitionCacheSize];
+ if (typeDefinitionCacheSize != nil) {
+ if ([[typeDefinitionCacheSize class] isEqual:[NSNumber class]]) {
+ self.typeDefinitionCache.countLimit = [(NSNumber *) typeDefinitionCacheSize unsignedIntValue];
+ } else {
+ CMISLogError(@"Invalid object set for %@ session parameter. Ignoring and using default instead", kCMISSessionParameterTypeDefinitionCacheSize);
+ }
+ }
+
+ if (self.typeDefinitionCache.countLimit <= 0) {
+ self.typeDefinitionCache.countLimit = DEFAULT_TYPE_DEFINITION_CACHE_SIZE;
+ }
+
+ // Uncomment for debugging
+ // self.typeDefinitionCache.delegate = self;
+}
+
+- (void)addTypeDefinition:(CMISTypeDefinition *)typeDefinition repositoryId:(NSString *)repositoryId
+{
+ TypeDefinitionCacheKey *key = [TypeDefinitionCacheKey initWithTypeDefinitionId:typeDefinition.id repositoryId:repositoryId];
+ [self.typeDefinitionCache setObject:typeDefinition forKey:key];
+
+}
+
+- (CMISTypeDefinition *)typeDefinitionForTypeId:(NSString *)typeId repositoryId:(NSString *)repositoryId
+{
+ TypeDefinitionCacheKey *key = [TypeDefinitionCacheKey initWithTypeDefinitionId:typeId repositoryId:repositoryId];
+ return [self.typeDefinitionCache objectForKey:key];
+}
+
+- (void)removeTypeDefinitionForTypeId:(NSString *)typeId repositoryId:(NSString *)repositoryId
+{
+ TypeDefinitionCacheKey *key = [TypeDefinitionCacheKey initWithTypeDefinitionId:typeId repositoryId:repositoryId];
+ [self.typeDefinitionCache removeObjectForKey:key];
+}
+
+- (void)removeAll
+{
+ [self.typeDefinitionCache removeAllObjects];
+
+}
+
+// Debugging
+//- (void)cache:(NSCache *)cache willEvictObject:(id)obj
+//{
+// CMISLogDebug(@"Type definition cache will evict cached type definitions for object '%@'", obj);
+//}
+
+@end
+
+@implementation TypeDefinitionCacheKey
+
++ (TypeDefinitionCacheKey *)initWithTypeDefinitionId:(NSString *)typeDefinitionId repositoryId:(NSString *)repositoryId
+{
+ TypeDefinitionCacheKey *key = [[TypeDefinitionCacheKey alloc] init];
+
+ key.typeDefinitionId = typeDefinitionId;
+ key.repositoryId = repositoryId;
+
+ return key;
+}
+
+-(BOOL)isEqual:(id)object{
+ if(![object isKindOfClass: [TypeDefinitionCacheKey class]]){
+ return NO;
+ }
+ TypeDefinitionCacheKey *otherKey = (TypeDefinitionCacheKey*)object;
+ if(![_repositoryId isEqualToString:otherKey.repositoryId]){
+ return NO;
+ }
+
+ if(![_typeDefinitionId isEqualToString:otherKey.typeDefinitionId]){
+ return NO;
+ }
+
+ return YES;
+}
+
+-(NSUInteger)hash{
+ return [_repositoryId hash] ^ [_typeDefinitionId hash];
+}
+
+@end
Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Client/CMISSession.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Client/CMISSession.m?rev=1589611&r1=1589610&r2=1589611&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Client/CMISSession.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Client/CMISSession.m Thu Apr 24 06:51:55 2014
@@ -116,7 +116,7 @@
self.objectConverter = [[CMISObjectConverter alloc] initWithSession:self];
}
- self.typeCache = [[NSMutableDictionary alloc] init];
+ self.typeCache = [[NSMutableDictionary alloc] init]; //TODO this typeCache should be replaced by a binding specific type definition cache
// TODO: setup locale
// TODO: setup default session parameters
Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.h?rev=1589611&r1=1589610&r2=1589611&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.h (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.h Thu Apr 24 06:51:55 2014
@@ -76,8 +76,6 @@ extern NSString * const kCMISParameterRe
extern NSString * const kCMISParameterMajor;
extern NSString * const kCMISParameterCheckin;
extern NSString * const kCMISParameterCheckinComment;
-extern NSString * const kCMISParameterSelector;
-extern NSString * const kCMISParameterSuccinct;
extern NSString * const kCMISParameterReturnVersion;
extern NSString * const kCMISParameterTypeId;
Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.m?rev=1589611&r1=1589610&r2=1589611&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISConstants.m Thu Apr 24 06:51:55 2014
@@ -80,8 +80,6 @@ NSString * const kCMISParameterRelativeP
NSString * const kCMISParameterMajor = @"major";
NSString * const kCMISParameterCheckin = @"checkin";
NSString * const kCMISParameterCheckinComment = @"checkinComment";
-NSString * const kCMISParameterSelector = @"cmisselector";
-NSString * const kCMISParameterSuccinct = @"succinct";
NSString * const kCMISParameterReturnVersion = @"returnVersion";
NSString * const kCMISParameterTypeId = @"typeId";
Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISPropertyData.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISPropertyData.m?rev=1589611&r1=1589610&r2=1589611&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISPropertyData.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISPropertyData.m Thu Apr 24 06:51:55 2014
@@ -104,7 +104,11 @@
if ([value isKindOfClass:[NSArray class]]) {
propertyData.values = [value copy];
} else {
- propertyData.values = [NSArray arrayWithObject:value];
+ if(value){
+ propertyData.values = [NSArray arrayWithObject:value];
+ } else {
+ propertyData.values = [NSArray array];
+ }
}
propertyData.type = type;
return propertyData;
Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.h?rev=1589611&r1=1589610&r2=1589611&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.h (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.h Thu Apr 24 06:51:55 2014
@@ -22,6 +22,7 @@
#import "CMISBinding.h"
#import "CMISAuthenticationProvider.h"
#import "CMISNetworkProvider.h"
+#import "CMISTypeDefinitionCache.h"
// Session param keys
@@ -39,6 +40,12 @@ extern NSString * const kCMISSessionPara
*/
extern NSString * const kCMISSessionParameterLinkCacheSize;
+/**
+ * Key for setting the value of the cache of type definitions.
+ * Value should be an NSNumber, indicating the amount of type defintions will be cached.
+ */
+extern NSString * const kCMISSessionParameterTypeDefinitionCacheSize;
+
@interface CMISSessionParameters : NSObject
@@ -59,6 +66,9 @@ extern NSString * const kCMISSessionPara
// Network I/O
@property (nonatomic, strong) id<CMISNetworkProvider> networkProvider;
+// Type definitions cache
+@property (nonatomic, strong) CMISTypeDefinitionCache *typeDefinitionCache;
+
/** init with binding type
*/
- (id)initWithBindingType:(CMISBindingType)bindingType;
Modified: chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.m?rev=1589611&r1=1589610&r2=1589611&view=diff
==============================================================================
--- chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.m (original)
+++ chemistry/objectivecmis/branches/browser-binding/ObjectiveCMIS/Common/CMISSessionParameters.m Thu Apr 24 06:51:55 2014
@@ -21,7 +21,8 @@
// Session param keys
NSString * const kCMISSessionParameterObjectConverterClassName = @"session_param_object_converter_class";
-NSString * const kCMISSessionParameterLinkCacheSize =@"session_param_cache_size_links";
+NSString * const kCMISSessionParameterLinkCacheSize = @"session_param_cache_size_links";
+NSString * const kCMISSessionParameterTypeDefinitionCacheSize = @"session_param_cache_size_type_definition";
@interface CMISSessionParameters ()