From: helge Date: Mon, 3 Oct 2005 19:18:50 +0000 (+0000) Subject: improved qualifier=>predicate conversion X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=395ac62f477736210e608dc1360110e089c7670d;p=sope improved qualifier=>predicate conversion git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1148 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/EOCoreData/ChangeLog b/sope-core/EOCoreData/ChangeLog index 6d9e8977..d5095565 100644 --- a/sope-core/EOCoreData/ChangeLog +++ b/sope-core/EOCoreData/ChangeLog @@ -1,3 +1,7 @@ +2005-10-03 Helge Hess + + * improved qualifier=>predicate conversion support (v4.5.10) + 2005-08-23 Helge Hess * v4.5.9 diff --git a/sope-core/EOCoreData/EOKeyComparisonQualifier+CoreData.m b/sope-core/EOCoreData/EOKeyComparisonQualifier+CoreData.m index 15c62c9c..1c37d429 100644 --- a/sope-core/EOCoreData/EOKeyComparisonQualifier+CoreData.m +++ b/sope-core/EOCoreData/EOKeyComparisonQualifier+CoreData.m @@ -38,9 +38,21 @@ } - (NSPredicate *)asPredicate { - NSLog(@"TODO(%s): implement me for class %@!", __PRETTY_FUNCTION__, - NSStringFromClass([self class])); - return nil; + NSExpression *lhs, *rhs; + id tmp; + + tmp = [self leftKey]; + lhs = [tmp isKindOfClass:[EOQualifierVariable class]] + ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]] + : [NSExpression expressionForKeyPath:tmp]; + + tmp = [self rightKey]; + rhs = [tmp isKindOfClass:[EOQualifierVariable class]] + ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]] + : [NSExpression expressionForKeyPath:tmp]; + + return [self predicateWithLeftExpression:lhs rightExpression:rhs + eoSelector:[self selector]]; } /* CoreData compatibility */ diff --git a/sope-core/EOCoreData/EOKeyValueQualifier+CoreData.m b/sope-core/EOCoreData/EOKeyValueQualifier+CoreData.m index 5c621987..8562e65b 100644 --- a/sope-core/EOCoreData/EOKeyValueQualifier+CoreData.m +++ b/sope-core/EOCoreData/EOKeyValueQualifier+CoreData.m @@ -39,9 +39,25 @@ } - (NSPredicate *)asPredicate { - NSLog(@"TODO(%s): implement me for class %@!", __PRETTY_FUNCTION__, - NSStringFromClass([self class])); - return nil; + /* + EOKeyValueQualifier has a key/value path expression on the left side + and a constant value expression on the right side. + */ + NSExpression *lhs, *rhs; + id tmp; + + tmp = [self key]; + lhs = [tmp isKindOfClass:[EOQualifierVariable class]] + ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]] + : [NSExpression expressionForKeyPath:tmp]; + + tmp = [self value]; + rhs = [tmp isKindOfClass:[EOQualifierVariable class]] + ? [NSExpression expressionForVariable:[(EOQualifierVariable *)tmp key]] + : [NSExpression expressionForConstantValue:tmp]; + + return [self predicateWithLeftExpression:lhs rightExpression:rhs + eoSelector:[self selector]]; } /* CoreData compatibility */ diff --git a/sope-core/EOCoreData/EOQualifier+CoreData.h b/sope-core/EOCoreData/EOQualifier+CoreData.h index 43e10161..79c48142 100644 --- a/sope-core/EOCoreData/EOQualifier+CoreData.h +++ b/sope-core/EOCoreData/EOQualifier+CoreData.h @@ -47,6 +47,10 @@ + (SEL)eoSelectorForForComparisonPredicate:(NSComparisonPredicate *)_p; + (NSPredicateOperatorType)predicateOperatorTypeForEOSelector:(SEL)_sel; +- (NSPredicate *)predicateWithLeftExpression:(NSExpression *)_lhs + rightExpression:(NSExpression *)_rhs + eoSelector:(SEL)_selector; + /* CoreData compatibility */ + (NSPredicate *)andPredicateWithSubpredicates:(NSArray *)_sub; diff --git a/sope-core/EOCoreData/EOQualifier+CoreData.m b/sope-core/EOCoreData/EOQualifier+CoreData.m index 6d255c97..f39d5ac9 100644 --- a/sope-core/EOCoreData/EOQualifier+CoreData.m +++ b/sope-core/EOCoreData/EOQualifier+CoreData.m @@ -138,6 +138,40 @@ return sel; } +- (NSPredicate *)predicateWithLeftExpression:(NSExpression *)_lhs + rightExpression:(NSExpression *)_rhs + eoSelector:(SEL)_selector +{ + // TODO: create non-custom predicate if possible + NSComparisonPredicateModifier pmod; + NSPredicateOperatorType ptype; + unsigned popts; + + if (_selector == NULL) { + NSLog(@"ERROR(0x%08X/%@): missing selector for predicate construction: %@", + self, NSStringFromClass([self class]), self); + return nil; + } + + ptype = [EOQualifier predicateOperatorTypeForEOSelector:_selector]; + + if (ptype == NSCustomSelectorPredicateOperatorType) { + return [NSComparisonPredicate predicateWithLeftExpression:_lhs + rightExpression:_rhs + customSelector:_selector]; + } + + pmod = NSDirectPredicateModifier; + popts = 0; + + if (SEL_EQ(_selector, EOQualifierOperatorCaseInsensitiveLike)) + popts = NSCaseInsensitivePredicateOption; + + return [NSComparisonPredicate predicateWithLeftExpression:_lhs + rightExpression:_rhs + modifier:pmod type:ptype options:popts]; +} + + (EOQualifier *)qualifierForPredicate:(NSPredicate *)_predicate { if (_predicate == nil) return nil; @@ -183,4 +217,12 @@ [_predicate asPredicate]]; } +- (NSPredicate *)predicateWithSubstitutionVariables:(NSDictionary *)_vars { + return [[self asPredicate] predicateWithSubstitutionVariables:_vars]; +} + +- (NSString *)predicateFormat { + return [[self asPredicate] predicateFormat]; +} + @end /* EOQualifier(CoreData) */ diff --git a/sope-core/EOCoreData/Version b/sope-core/EOCoreData/Version index f7255071..5e823793 100644 --- a/sope-core/EOCoreData/Version +++ b/sope-core/EOCoreData/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=9 +SUBMINOR_VERSION:=10