Skip to content

Commit 0d790fc

Browse files
committed
Bug #162 - added methods to reset condition, including default
1 parent 70002fb commit 0d790fc

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

fflib/src/classes/fflib_QueryFactory.cls

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
338338
this.order.add(o);
339339
return this;
340340
}
341+
/**
342+
* @param o an instance of {@link fflib_QueryFactory.Ordering} to remove all existing (for instance defaults) and be added to the query's ORDER BY clause.
343+
**/
344+
public fflib_QueryFactory setOrdering(Ordering o){
345+
this.order = new List<Ordering>{ o };
346+
return this;
347+
}
341348
/**
342349
* @returns the list of orderings that will be used as the query's ORDER BY clause. You may remove elements from the returned list, or otherwise mutate it, to remove previously added orderings.
343350
**/
@@ -507,6 +514,23 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
507514
);
508515
return this;
509516
}
517+
/**
518+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
519+
* related through an object lookup or master-detail relationship.
520+
* Use the set to store unique field names, since we only want to sort
521+
* by the same field one time. The sort expressions are stored in a list
522+
* so that they are applied to the SOQL in the same order that they
523+
* were added in.
524+
* @param fieldName The string value of the field to be sorted on
525+
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
526+
* @param nullsLast whether to sort null values last (NULLS LAST keyword included).
527+
**/
528+
public fflib_QueryFactory setOrdering(String fieldName, SortOrder direction, Boolean nullsLast){
529+
order = new List<Ordering> {
530+
new Ordering(getFieldToken(fieldName), direction, nullsLast)
531+
};
532+
return this;
533+
}
510534

511535
/**
512536
* Add a field to be sorted on. This may be a direct field or a field
@@ -526,6 +550,24 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
526550
return this;
527551
}
528552

553+
/**
554+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
555+
* related through an object lookup or master-detail relationship.
556+
* Use the set to store unique field names, since we only want to sort
557+
* by the same field one time. The sort expressions are stored in a list
558+
* so that they are applied to the SOQL in the same order that they
559+
* were added in.
560+
* @param field The SObjectfield to sort. This can only be a direct reference.
561+
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
562+
* @param nullsLast whether to sort null values last (NULLS LAST keyword included).
563+
**/
564+
public fflib_QueryFactory setOrdering(SObjectField field, SortOrder direction, Boolean nullsLast){
565+
order = new List<Ordering> {
566+
new Ordering(new QueryField(field), direction, nullsLast)
567+
};
568+
return this;
569+
}
570+
529571
/**
530572
* Add a field to be sorted on. This may be a direct field or a field
531573
* related through an object lookup or master-detail relationship.
@@ -545,6 +587,25 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
545587
return this;
546588
}
547589

590+
/**
591+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
592+
* related through an object lookup or master-detail relationship.
593+
* Use the set to store unique field names, since we only want to sort
594+
* by the same field one time. The sort expressions are stored in a list
595+
* so that they are applied to the SOQL in the same order that they
596+
* were added in.
597+
* The "NULLS FIRST" keywords will be included by default. If "NULLS LAST"
598+
* is required, use one of the overloaded addOrdering methods which include this parameter.
599+
* @param fieldName The string value of the field to be sorted on
600+
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
601+
**/
602+
public fflib_QueryFactory setOrdering(String fieldName, SortOrder direction){
603+
order = new List<Ordering> {
604+
new Ordering(getFieldToken(fieldName), direction)
605+
};
606+
return this;
607+
}
608+
548609
/**
549610
* Add a field to be sorted on. This may be a direct field or a field
550611
* related through an object lookup or master-detail relationship.
@@ -564,6 +625,25 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
564625
return this;
565626
}
566627

628+
/**
629+
* Remove existing ordering and set a field to be sorted on. This may be a direct field or a field
630+
* related through an object lookup or master-detail relationship.
631+
* Use the set to store unique field names, since we only want to sort
632+
* by the same field one time. The sort expressions are stored in a list
633+
* so that they are applied to the SOQL in the same order that they
634+
* were added in.
635+
* The "NULLS FIRST" keywords will be included by default. If "NULLS LAST"
636+
* is required, use one of the overloaded addOrdering methods which include this parameter.
637+
* @param field The SObjectfield to sort. This can only be a direct reference.
638+
* @param SortOrder the direction to be sorted on (ASCENDING or DESCENDING)
639+
**/
640+
public fflib_QueryFactory setOrdering(SObjectField field, SortOrder direction){
641+
order = new List<Ordering> {
642+
new Ordering(new QueryField(field), direction)
643+
};
644+
return this;
645+
}
646+
567647
/**
568648
* Convert the values provided to this instance into a full SOQL string for use with Database.query
569649
* Check to see if subqueries queries need to be added after the field list.

0 commit comments

Comments
 (0)