]> err.no Git - sope/commitdiff
improved qualifier=>predicate conversion
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 3 Oct 2005 19:18:50 +0000 (19:18 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 3 Oct 2005 19:18:50 +0000 (19:18 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1148 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-core/EOCoreData/ChangeLog
sope-core/EOCoreData/EOKeyComparisonQualifier+CoreData.m
sope-core/EOCoreData/EOKeyValueQualifier+CoreData.m
sope-core/EOCoreData/EOQualifier+CoreData.h
sope-core/EOCoreData/EOQualifier+CoreData.m
sope-core/EOCoreData/Version

index 6d9e8977c8fc93b7bab6a81e6cbeccf8360cc27d..d5095565e0e6614a76b010f85598b641b8a257cd 100644 (file)
@@ -1,3 +1,7 @@
+2005-10-03  Helge Hess  <helge.hess@opengroupware.org>
+
+       * improved qualifier=>predicate conversion support (v4.5.10)
+
 2005-08-23  Helge Hess  <helge.hess@opengroupware.org>
 
        * v4.5.9
index 15c62c9cb23c05c3ca74b12600f30a34fdb6b504..1c37d429650df9e07ba04767af4d825eabd74a07 100644 (file)
 }
 
 - (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 */
index 5c62198746ece6b6105a0860d4642a42353f6e6d..8562e65bec11c0aa0679c3694c20f0f5f9f6197b 100644 (file)
 }
 
 - (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 */
index 43e10161de4c40fcfc19e0291c72a9deab5243ba..79c48142277824c6969a78fbc0b0fabf1070b679 100644 (file)
 + (SEL)eoSelectorForForComparisonPredicate:(NSComparisonPredicate *)_p;
 + (NSPredicateOperatorType)predicateOperatorTypeForEOSelector:(SEL)_sel;
 
+- (NSPredicate *)predicateWithLeftExpression:(NSExpression *)_lhs
+  rightExpression:(NSExpression *)_rhs
+  eoSelector:(SEL)_selector;
+
 /* CoreData compatibility */
 
 + (NSPredicate *)andPredicateWithSubpredicates:(NSArray *)_sub;
index 6d255c97295107ffd82bb407a618866772e927a7..f39d5ac98b7103bfb31c872373ecada0381712be 100644 (file)
   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;
                                [_predicate asPredicate]];
 }
 
+- (NSPredicate *)predicateWithSubstitutionVariables:(NSDictionary *)_vars {
+  return [[self asPredicate] predicateWithSubstitutionVariables:_vars];
+}
+
+- (NSString *)predicateFormat {
+  return [[self asPredicate] predicateFormat];
+}
+
 @end /* EOQualifier(CoreData) */
index f725507183992c451c63ba6d27aef6b943c23b07..5e8237938bf25d5166612c59f78bed6ed7da850e 100644 (file)
@@ -1,3 +1,3 @@
 # version file
 
-SUBMINOR_VERSION:=9
+SUBMINOR_VERSION:=10