Skip to content

Commit

Permalink
Added cacheability to the dynamic Sobject Selector
Browse files Browse the repository at this point in the history
Added a bit more robustness to the cache
  • Loading branch information
rob-baillie-ortoo committed Mar 7, 2022
1 parent a188674 commit a2f3aa6
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public inherited sharing class OrgCachedSoqlExecutor
*/
public List<Sobject> query( String soql )
{
Contract.requires( soql != null, 'query called with a null soql' );

String key = generateKey( soql );
List<Sobject> returnValues = null;

Expand Down Expand Up @@ -95,6 +97,8 @@ public inherited sharing class OrgCachedSoqlExecutor
*/
public void clearCacheFor( String soql )
{
Contract.requires( soql != null, 'clearCacheFor called with a null soql' );

if ( ! hasAccessToCache )
{
throw new OrgCacheAccessViolationException( Label.ortoo_core_soql_cache_access_violation )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,44 @@ public inherited sharing class ortoo_DynamicSobjectSelector extends ortoo_Sobjec
*/
public List<Sobject> selectByCriteria( ortoo_Criteria criteria )
{
Contract.requires( criteria != null, 'selectByCriteria called with a null criteria' );
return selectByCriteria( criteria, false );
}

/**
* Retrieve the records that match the passed criteria, optionally via the Org Level SOQL Cache
*
* @param ortoo_Criteria The criteria that should be used to derive the records to return
* @param Boolean Should the query go via the Org Level SOQL Cache?
* @return List<Sobject> The result of the Selection
*/
public List<Sobject> selectByCriteria( ortoo_Criteria criteria, Boolean cached )
{
Contract.requires( criteria != null, 'selectByCriteria called with a null criteria' );
Contract.requires( cached != null, 'selectByCriteria called with a null cached' );
Contract.assert( sobjectType != null, 'selectByCriteria called when sobjectType has not been set' );

return Database.query( generateSoqlByCriteria( criteria ) );
String soql = generateSoqlByCriteria( criteria );
if ( cached )
{
return ((OrgCachedSoqlExecutor)Application.APP_LOGIC.newInstance( OrgCachedSoqlExecutor.class ))
.query( soql );
}
return Database.query( soql );
}

/**
* Request that the cached results for the given criteria be cleared.
* Assumes that the fields are set up correctly.
*
* @param ortoo_Criteria The criteria that should be used to derive the SOQL results to clear
*/
public ortoo_DynamicSobjectSelector clearCacheFor( ortoo_Criteria criteria )
{
Contract.requires( criteria != null, 'clearCacheFor called with a null criteria' );

((OrgCachedSoqlExecutor)Application.APP_LOGIC.newInstance( OrgCachedSoqlExecutor.class ))
.clearCacheFor( generateSoqlByCriteria( criteria ) );
return this;
}

/**
Expand Down
Loading

0 comments on commit a2f3aa6

Please sign in to comment.