-
Notifications
You must be signed in to change notification settings - Fork 8
Added support for database access levels and new query methods with binds #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
superkensington
wants to merge
7
commits into
jongpie:main
from
superkensington:feature/issues-35-36
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
00d196d
Bumped API versions to 60.0 (Spring '24)
superkensington 82c6d68
Added support for using System.AccessLevel (#36)
superkensington 100d090
Added support for using bind variables with new Database query method…
superkensington f183a76
Update project API version to 60.0 (Spring '24)
superkensington 158db75
Rename method parameter names for consistency
superkensington f497090
Set SOSL access level in base class
superkensington 9a3f1c7
Bumped API versions to 61.0 (Summer '24)
superkensington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ global class AggregateQuery extends SOQL { | |
| private SOQL.GroupingDimension groupingDimension; | ||
| private List<AggregateField> aggregateFields; | ||
| private List<String> havingConditions; | ||
| private String countQuery; | ||
|
|
||
| global AggregateQuery(Schema.SObjectType sobjectType) { | ||
| super(sobjectType, false); | ||
|
|
@@ -79,19 +80,48 @@ global class AggregateQuery extends SOQL { | |
| return this.havingAggregate(aggregateFunction, new SOQL.QueryField(field), operator, value); | ||
| } | ||
|
|
||
| global AggregateQuery havingAggregate(SOQL.Aggregate aggregateFunction, Schema.SObjectField field, SOQL.Operator operator, Object value, String bindWithKey) { | ||
| return this.havingAggregate(aggregateFunction, new SOQL.QueryField(field), operator, value, bindWithKey); | ||
| } | ||
|
|
||
| global AggregateQuery havingAggregate(SOQL.Aggregate aggregateFunction, SOQL.QueryField queryField, SOQL.Operator operator, Object value) { | ||
| this.havingConditions.add(aggregateFunction.name() + '(' + queryField + ') ' + SOQL.getOperatorValue(operator) + ' ' + value); | ||
| return this.havingAggregate(aggregateFunction, queryField, operator, value, null); | ||
| } | ||
|
|
||
| global AggregateQuery havingAggregate(SOQL.Aggregate aggregateFunction, SOQL.QueryField queryField, SOQL.Operator operator, Object value, String bindWithKey) { | ||
| this.havingConditions.add( | ||
| String.format( | ||
| '{0}({1}) {2} {3}', | ||
| new List<String> { | ||
| aggregateFunction.name(), | ||
| queryField.toString(), | ||
| SOQL.getOperatorValue(operator), | ||
| (String.isNotBlank(bindWithKey) ? ':' + bindWithKey : new QueryArgument(value).toString()) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love how you've kept it backwards compatible with |
||
| } | ||
| ) | ||
| ); | ||
| if (String.isNotBlank(bindWithKey)) { | ||
| this.bindsMap.put(bindWithKey, value); | ||
| } | ||
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery filterWhere(Schema.SObjectField field, SOQL.Operator operator, Object value) { | ||
| return this.filterWhere(new SOQL.QueryField(field), operator, value); | ||
| } | ||
|
|
||
| global AggregateQuery filterWhere(Schema.SObjectField field, SOQL.Operator operator, Object value, String bindWithKey) { | ||
| return this.filterWhere(new SOQL.QueryField(field), operator, value, bindWithKey); | ||
| } | ||
|
|
||
| global AggregateQuery filterWhere(SOQL.QueryField queryField, SOQL.Operator operator, Object value) { | ||
| return this.filterWhere(new SOQL.QueryFilter(queryField, operator, value)); | ||
| } | ||
|
|
||
| global AggregateQuery filterWhere(SOQL.QueryField queryField, SOQL.Operator operator, Object value, String bindWithKey) { | ||
| return this.filterWhere(new SOQL.QueryFilter(queryField, operator, value, bindWithKey)); | ||
| } | ||
|
|
||
| global AggregateQuery filterWhere(SOQL.QueryFilter filter) { | ||
| return this.filterWhere(new List<SOQL.QueryFilter>{ filter }); | ||
| } | ||
|
|
@@ -106,6 +136,11 @@ global class AggregateQuery extends SOQL { | |
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery withAccessLevel(System.AccessLevel accessLevel) { | ||
| super.doWithAccessLevel(accessLevel); | ||
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery orderByField(Schema.SObjectField field) { | ||
| return this.orderByField(field, null); | ||
| } | ||
|
|
@@ -166,6 +201,26 @@ global class AggregateQuery extends SOQL { | |
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery setBind(String key, Object value) { | ||
| super.doSetBind(key, value); | ||
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery setBinds(Map<String, Object> binds) { | ||
| super.doSetBinds(binds); | ||
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery removeBind(String key) { | ||
| super.doRemoveBind(key); | ||
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| global AggregateQuery clearBinds() { | ||
| super.doClearBinds(); | ||
| return this.setHasChanged(); | ||
| } | ||
|
|
||
| // TODO decide if this should be global | ||
| public AggregateQuery cacheResults() { | ||
| super.doCacheResults(); | ||
|
|
@@ -206,10 +261,12 @@ global class AggregateQuery extends SOQL { | |
| return this.query; | ||
| } | ||
|
|
||
| // TODO consider renaming to getCountResult() | ||
| @SuppressWarnings('PMD.ApexSOQLInjection') | ||
| global Integer getResultCount() { | ||
| String countQuery = | ||
| global String getCountQuery() { | ||
| if (this.countQuery != null && !this.hasChanged) { | ||
| return this.countQuery; | ||
| } | ||
|
|
||
| this.countQuery = | ||
| 'SELECT COUNT()' + | ||
| ' FROM ' + | ||
| this.sobjectType + | ||
|
|
@@ -220,7 +277,19 @@ global class AggregateQuery extends SOQL { | |
| super.doGetOrderByString() + | ||
| super.doGetLimitCountString() + | ||
| super.doGetOffetString(); | ||
| return Database.countQuery(countQuery); | ||
|
|
||
| System.debug(System.LoggingLevel.FINEST, this.countQuery); | ||
| return this.countQuery; | ||
| } | ||
|
|
||
| // TODO consider renaming to getCountResult() | ||
| @SuppressWarnings('PMD.ApexSOQLInjection') | ||
| global Integer getResultCount() { | ||
| return Database.countQueryWithBinds( | ||
| this.getCountQuery(), | ||
| this.doGetBindsMap(), | ||
| this.doGetAccessLevel() | ||
| ); | ||
| } | ||
|
|
||
| global AggregateResult getFirstResult() { | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
nebula-query-and-search/main/classes/AggregateQuery.cls-meta.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>61.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>61.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>61.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>58.0</apiVersion> | ||
| <apiVersion>61.0</apiVersion> | ||
| <status>Active</status> | ||
| </ApexClass> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this new method overload signature makes sense, especially for trying to keep things backwards compatible with
QueryArgument. But my small complaint is:QueryArgumentSo I'm thinking there could be another method to enable automatically generating bind variable names. Something like this:
And then in this
havingAggregate()overload, auto-generate the bind var name when enabled:Example usage would look something like this:
I think the same idea would apply in the
Queryclass too. Let me know what you think.