Skip to content

Commit

Permalink
Merge pull request #164 from JonnyPower/feature/QueryFactory_OffsetSu…
Browse files Browse the repository at this point in the history
…pport

Add offsetCount to fflib_QueryFactory
  • Loading branch information
afawcett authored Apr 15, 2017
2 parents b503f84 + 36621d5 commit d0e8ff5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions fflib/src/classes/fflib_QueryFactory.cls
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
private Set<String> fields;
private String conditionExpression;
private Integer limitCount;
private Integer offset;
private Integer offsetCount;
private List<Ordering> order;
/**
* Integrate checking for READ Field Level Security within the selectField(s) methods
Expand Down Expand Up @@ -318,6 +318,19 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
public Integer getLimit(){
return this.limitCount;
}
/**
* @param offsetCount if not null causes a OFFSET caluse to be added to the resulting query.
**/
public fflib_QueryFactory setOffset(Integer offsetCount){
this.offsetCount = offsetCount;
return this;
}
/**
* @returns the current value of the OFFSET clause, if any.
**/
public Integer getOffset(){
return this.offsetCount;
}
/**
* @param o an instance of {@link fflib_QueryFactory.Ordering} to be added to the query's ORDER BY clause.
**/
Expand Down Expand Up @@ -589,6 +602,10 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr

if(limitCount != null)
result += ' LIMIT '+limitCount;

if(offsetCount != null)
result += ' OFFSET '+offsetCount;

return result;
}

Expand All @@ -600,6 +617,7 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr

fflib_QueryFactory clone = new fflib_QueryFactory(this.table)
.setLimit(this.limitCount)
.setOffset(this.offsetCount)
.setCondition(this.conditionExpression)
.setEnforceFLS(this.enforceFLS);

Expand Down Expand Up @@ -675,4 +693,4 @@ public class fflib_QueryFactory { //No explicit sharing declaration - inherit fr
public class InvalidFieldSetException extends Exception{}
public class NonReferenceFieldException extends Exception{}
public class InvalidSubqueryRelationshipException extends Exception{}
}
}

0 comments on commit d0e8ff5

Please sign in to comment.