DADynamicWhereXmlGenerator

Overview

DADynamicWhereXmlGenerator class is used for transformation NSPredicate expression into Dynamic Where xml which could be used as the filter during fetching data from the server side.

In the world of Cocoa, to determine the various requests are widely used NSPredicate. This is a very handy feature. For example, if we have an array filled with objects that have a property Name, we can easily filter them by given name in following way:

 
NSPredicate *lFilter = [NSPredicate predicateWithFormat:@"name == %@", name];
NSArray* result = [collection filteredArrayUsingPredicate:lFilter];

Inside the Data Abstract we can use NSPredicate expressions for so called client-side filtering rows of the DADataTable.

 
// Client-side filtering data
NSPredicate * lFilter = [NSPredicate predicateWithFormat:@"WorkerPosition contains[cd] %@", @"Representative"]; 
self.rows = [[workersTable rows] filteredArrayUsingPredicate:lFilter];
[tableView reloadData];

But at the same time we can apply server-side filtering using the same NSPredicate expression. To do this we just need to transform given NSPredicate expression to the proper Dynamic Where xml which can be used in requesting data from the server side.

the DADynamicWhereXmlGenerator class provides such transformation for us.

 
// Server-side filtering data
NSPredicate * lFilter = [NSPredicate predicateWithFormat:@"WorkerPosition contains[cd] %@", @"Representative"]; 
NSString *dynWhereXml = [DADynamicWhereXmlGenerator generateXmlFromPredicate:lFilter autoIndent:YES];
DADynamicWhereClause *clause = [DADynamicWhereClause dynamicWhereClauseWithXmlString:dynWhereXml];
request = [rda beginGetDataTable:@"Workers" 
                          select:[self fieldsToSelect] 
                           where:clause
                           withBlock:^(DADataTable *table){
                              self.workersTable = table;
                              self.rows = [workersTable rows];
                              [tableView reloadData];
                           }];

in the code above [DADynamicWhereXmlGenerator generateXmlFromPredicate:lFilter] will produce following Dynamic Where xml:


<?xml version="1.0" encoding="utf-16"?>
<query xmlns="http://www.remobjects.com/schemas/dataabstract/queries/5.0" version="5.0">
  <where>
    <binaryoperation operator="Like">
      <field>WorkerPosition</field>
      <constant type="String" null="0">%Representative%</constant>
    </binaryoperation>
  </where>
</query>

Location


 

appendString:    (declared in DABaseXmlSerializer)

- (void) appendString:(NSString *)value

Parameters:

  • value:

appendTag:withValue:    (declared in DABaseXmlSerializer)

- (void) appendTag:(NSString *)name withValue:(NSString *)value

Parameters:

  • name:
  • value:

appendTag:withValue:asCDATA:    (declared in DABaseXmlSerializer)

- (void) appendTag:(NSString *)name withValue:(NSString *)value asCDATA:(BOOL)asCDATA

Parameters:

  • name:
  • value:
  • asCDATA:

beginGenerate

- (void) beginGenerate

decodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) decodeXmlStringValue:(NSString *)value

Parameters:

  • value:

encodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) encodeXmlStringValue:(NSString *)value

Parameters:

  • value:

endGenerate

- (void) endGenerate

generateXmlFromPredicate:

Class method generates XML string for given NSPredicate

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML

generateXmlFromPredicate:autoIndent:

Class method generates XML string for given NSPredicate. Allows to specify autoIndent flag. If autoIndent is YES then method returns formatted XML string with proper indentation.

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate autoIndent:(BOOL)autoIndent

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML
  • autoIndent: Boolean flag that specify apply auto-indentation for result XML string. Default value is NO

newLine    (declared in DABaseXmlSerializer)

- (void) newLine

performIndent    (declared in DABaseXmlSerializer)

- (void) performIndent

setAutoIndent:    (declared in DABaseXmlSerializer)

- (void) setAutoIndent:(BOOL)value

Parameters:

  • value:

stringFromPredicateOperatorType:

- (NSString *) stringFromPredicateOperatorType:(NSPredicateOperatorType)type

Parameters:

  • type:

visitAggregateExpression:

- (void) visitAggregateExpression:(NSExpression *)expression

Parameters:

  • expression:

visitBetweenPredicate:

- (void) visitBetweenPredicate:(NSComparisonPredicate *)predicate

Parameters:

  • predicate:

visitComparisonPredicate:

- (void) visitComparisonPredicate:(NSComparisonPredicate *)predicate

Parameters:

  • predicate:

visitCompoundPredicate:

- (void) visitCompoundPredicate:(NSCompoundPredicate *)predicate

Parameters:

  • predicate:

visitConstantValueExpression:

- (void) visitConstantValueExpression:(NSExpression *)expression

Parameters:

  • expression:

visitExpression:

- (void) visitExpression:(NSExpression *)expression

Parameters:

  • expression:

visitKeyPathExpression:

- (void) visitKeyPathExpression:(NSExpression *)expression

Parameters:

  • expression:

visitPredicate:

- (void) visitPredicate:(NSPredicate *)predicate

Parameters:

  • predicate:

xmlString    (declared in DABaseXmlSerializer)

- (NSString *) xmlString

 

decodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) decodeXmlStringValue:(NSString *)value

Parameters:

  • value:

encodeXmlStringValue:    (declared in DABaseXmlSerializer)

+ (NSString *) encodeXmlStringValue:(NSString *)value

Parameters:

  • value:

generateXmlFromPredicate:

Class method generates XML string for given NSPredicate

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML

generateXmlFromPredicate:autoIndent:

Class method generates XML string for given NSPredicate. Allows to specify autoIndent flag. If autoIndent is YES then method returns formatted XML string with proper indentation.

+ (NSString *) generateXmlFromPredicate:(NSPredicate *)predicate autoIndent:(BOOL)autoIndent

Parameters:

  • predicate: NSPredicate instance which should be translated into Dynamic Where XML
  • autoIndent: Boolean flag that specify apply auto-indentation for result XML string. Default value is NO

 

appendString:    (declared in DABaseXmlSerializer)

- (void) appendString:(NSString *)value

Parameters:

  • value:

appendTag:withValue:    (declared in DABaseXmlSerializer)

- (void) appendTag:(NSString *)name withValue:(NSString *)value

Parameters:

  • name:
  • value:

appendTag:withValue:asCDATA:    (declared in DABaseXmlSerializer)

- (void) appendTag:(NSString *)name withValue:(NSString *)value asCDATA:(BOOL)asCDATA

Parameters:

  • name:
  • value:
  • asCDATA:

beginGenerate

- (void) beginGenerate

endGenerate

- (void) endGenerate

newLine    (declared in DABaseXmlSerializer)

- (void) newLine

performIndent    (declared in DABaseXmlSerializer)

- (void) performIndent

setAutoIndent:    (declared in DABaseXmlSerializer)

- (void) setAutoIndent:(BOOL)value

Parameters:

  • value:

stringFromPredicateOperatorType:

- (NSString *) stringFromPredicateOperatorType:(NSPredicateOperatorType)type

Parameters:

  • type:

visitAggregateExpression:

- (void) visitAggregateExpression:(NSExpression *)expression

Parameters:

  • expression:

visitBetweenPredicate:

- (void) visitBetweenPredicate:(NSComparisonPredicate *)predicate

Parameters:

  • predicate:

visitComparisonPredicate:

- (void) visitComparisonPredicate:(NSComparisonPredicate *)predicate

Parameters:

  • predicate:

visitCompoundPredicate:

- (void) visitCompoundPredicate:(NSCompoundPredicate *)predicate

Parameters:

  • predicate:

visitConstantValueExpression:

- (void) visitConstantValueExpression:(NSExpression *)expression

Parameters:

  • expression:

visitExpression:

- (void) visitExpression:(NSExpression *)expression

Parameters:

  • expression:

visitKeyPathExpression:

- (void) visitKeyPathExpression:(NSExpression *)expression

Parameters:

  • expression:

visitPredicate:

- (void) visitPredicate:(NSPredicate *)predicate

Parameters:

  • predicate:

xmlString    (declared in DABaseXmlSerializer)

- (NSString *) xmlString