Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions sfdx-source/apex-common/main/classes/fflib_Application.cls
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,32 @@
* of the Apex Enterprise Patterns, Service, Unit Of Work, Selector and Domain.
* See the sample applications Application.cls file for an example
**/
@NamespaceAccessible
public virtual class fflib_Application
{
/**
* Class implements a Unit of Work factory
**/
@NamespaceAccessible
public virtual class UnitOfWorkFactory implements fflib_IUnitOfWorkFactory
{
@NamespaceAccessible
protected List<SObjectType> m_objectTypes;
@NamespaceAccessible
protected fflib_ISObjectUnitOfWork m_mockUow;

/**
* Constructs a Unit Of Work factory
**/
@NamespaceAccessible
public UnitOfWorkFactory() { }

/**
* Constructs a Unit Of Work factory
*
* @param objectTypes List of SObjectTypes in dependency order
**/
@NamespaceAccessible
public UnitOfWorkFactory(List<SObjectType> objectTypes)
{
m_objectTypes = objectTypes.clone();
Expand All @@ -59,6 +65,7 @@ public virtual class fflib_Application
* SObjectType list provided in the constructor, returns a Mock implementation
* if set via the setMock method
**/
@NamespaceAccessible
public virtual fflib_ISObjectUnitOfWork newInstance()
{
// Mock?
Expand All @@ -72,6 +79,7 @@ public virtual class fflib_Application
* SObjectType list provided in the constructor, returns a Mock implementation
* if set via the setMock method
**/
@NamespaceAccessible
public virtual fflib_ISObjectUnitOfWork newInstance(fflib_SObjectUnitOfWork.IDML dml)
{
// Mock?
Expand All @@ -88,6 +96,7 @@ public virtual class fflib_Application
* @remark If mock is set, the list of SObjectType in the mock could be different
* than the list of SObjectType specified in this method call
**/
@NamespaceAccessible
public virtual fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes)
{
// Mock?
Expand All @@ -104,6 +113,7 @@ public virtual class fflib_Application
* @remark If mock is set, the list of SObjectType in the mock could be different
* than the list of SObjectType specified in this method call
**/
@NamespaceAccessible
public virtual fflib_ISObjectUnitOfWork newInstance(List<SObjectType> objectTypes, fflib_SObjectUnitOfWork.IDML dml)
{
// Mock?
Expand All @@ -113,6 +123,7 @@ public virtual class fflib_Application
}

@TestVisible
@NamespaceAccessible
protected virtual void setMock(fflib_ISObjectUnitOfWork mockUow)
{
m_mockUow = mockUow;
Expand All @@ -122,15 +133,19 @@ public virtual class fflib_Application
/**
* Simple Service Factory implementation
**/
@NamespaceAccessible
public virtual class ServiceFactory implements fflib_IServiceFactory
{
@NamespaceAccessible
protected Map<Type, Type> m_serviceInterfaceTypeByServiceImplType;

@NamespaceAccessible
protected Map<Type, Object> m_serviceInterfaceTypeByMockService;

/**
* Constructs a simple Service Factory
**/
@NamespaceAccessible
public ServiceFactory() { }

/**
Expand All @@ -141,6 +156,7 @@ public virtual class fflib_Application
*
* @param serviceInterfaceTypeByServiceImplType Map of interfaces to classes
**/
@NamespaceAccessible
public ServiceFactory(Map<Type, Type> serviceInterfaceTypeByServiceImplType)
{
m_serviceInterfaceTypeByServiceImplType = serviceInterfaceTypeByServiceImplType;
Expand All @@ -155,6 +171,7 @@ public virtual class fflib_Application
* @param serviceInterfaceType Apex interface type
* @exception Is thrown if there is no registered Apex class for the interface type
**/
@NamespaceAccessible
public virtual Object newInstance(Type serviceInterfaceType)
{
// Mock implementation?
Expand All @@ -169,6 +186,7 @@ public virtual class fflib_Application
}

@TestVisible
@NamespaceAccessible
protected virtual void setMock(Type serviceInterfaceType, Object serviceImpl)
{
m_serviceInterfaceTypeByMockService.put(serviceInterfaceType, serviceImpl);
Expand All @@ -178,14 +196,18 @@ public virtual class fflib_Application
/**
* Class implements a Selector class factory
**/
@NamespaceAccessible
public virtual class SelectorFactory implements fflib_ISelectorFactory
{
@NamespaceAccessible
protected Map<SObjectType, Type> m_sObjectBySelectorType;
@NamespaceAccessible
protected Map<SObjectType, fflib_ISObjectSelector> m_sObjectByMockSelector;

/**
* Constructs a simple Selector Factory
**/
@NamespaceAccessible
public SelectorFactory() { }

/**
Expand All @@ -195,6 +217,7 @@ public virtual class fflib_Application
*
* @param sObjectBySelectorType Map of SObjectType's to Selector Apex Classes
**/
@NamespaceAccessible
public SelectorFactory(Map<SObjectType, Type> sObjectBySelectorType)
{
m_sObjectBySelectorType = sObjectBySelectorType;
Expand All @@ -207,6 +230,7 @@ public virtual class fflib_Application
*
* @param sObjectType An SObjectType token, e.g. Account.SObjectType
**/
@NamespaceAccessible
public virtual fflib_ISObjectSelector newInstance(SObjectType sObjectType)
{
// Mock implementation?
Expand All @@ -230,6 +254,7 @@ public virtual class fflib_Application
* @param recordIds The SObject record Ids, must be all the same SObjectType
* @exception Is thrown if the record Ids are not all the same or the SObjectType is not registered
**/
@NamespaceAccessible
public virtual List<SObject> selectById(Set<Id> recordIds)
{
// No point creating an empty Domain class, nor can we determine the SObjectType anyway
Expand Down Expand Up @@ -258,6 +283,7 @@ public virtual class fflib_Application
* @param relatedRecords used to extract the related record Ids, e.g. Opportunity records
* @param relationshipField field in the passed records that contains the relationship records to query, e.g. Opportunity.AccountId
**/
@NamespaceAccessible
public virtual List<SObject> selectByRelationship(List<SObject> relatedRecords, SObjectField relationshipField)
{
Set<Id> relatedIds = new Set<Id>();
Expand All @@ -271,6 +297,7 @@ public virtual class fflib_Application
}

@TestVisible
@NamespaceAccessible
protected virtual void setMock(fflib_ISObjectSelector selectorInstance)
{
m_sObjectByMockSelector.put(selectorInstance.sObjectType(), selectorInstance);
Expand All @@ -280,17 +307,22 @@ public virtual class fflib_Application
/**
* Class implements a Domain class factory
**/
@NamespaceAccessible
public virtual class DomainFactory implements fflib_IDomainFactory
{
@NamespaceAccessible
protected fflib_Application.SelectorFactory m_selectorFactory;

@NamespaceAccessible
protected Map<Object, Type> constructorTypeByObject;

@NamespaceAccessible
protected Map<Object, fflib_IDomain> mockDomainByObject;

/**
* Constructs a Domain factory
**/
@NamespaceAccessible
public DomainFactory() { }

/**
Expand All @@ -302,6 +334,7 @@ public virtual class fflib_Application
* @param selectorFactory , e.g. Application.Selector
* @param constructorTypeByObject Map of Domain classes by ObjectType
**/
@NamespaceAccessible
public DomainFactory(fflib_Application.SelectorFactory selectorFactory,
Map<Object, Type> constructorTypeByObject)
{
Expand All @@ -319,6 +352,7 @@ public virtual class fflib_Application
* @param selectorFactory, e.g. Application.Selector
* @param sObjectByDomainConstructorType Map of Apex classes by SObjectType
**/
@NamespaceAccessible
public DomainFactory(fflib_Application.SelectorFactory selectorFactory,
Map<SObjectType, Type> sObjectByDomainConstructorType)
{
Expand All @@ -335,6 +369,7 @@ public virtual class fflib_Application
* @param recordIds A list of Id's of the same type
* @exception Throws an exception via the Selector Factory if the Ids are not all of the same SObjectType
**/
@NamespaceAccessible
public virtual fflib_IDomain newInstance(Set<Id> recordIds)
{
return newInstance(m_selectorFactory.selectById(recordIds));
Expand All @@ -349,6 +384,7 @@ public virtual class fflib_Application
* @exception Throws an exception if the SObjectType cannot be determined from the list
* or the constructor for Domain class was not registered for the SObjectType
**/
@NamespaceAccessible
public virtual fflib_IDomain newInstance(List<SObject> records)
{
SObjectType domainSObjectType = records.getSObjectType();
Expand All @@ -358,6 +394,7 @@ public virtual class fflib_Application
return newInstance((List<Object>) records, (Object) domainSObjectType);
}

@NamespaceAccessible
public virtual fflib_IDomain newInstance(List<Object> objects, Object objectType)
{
// Mock implementation?
Expand Down Expand Up @@ -401,6 +438,7 @@ public virtual class fflib_Application
* @remark Will support List<SObject> but all records in the list will be assumed to be of
* the type specified in sObjectType
**/
@NamespaceAccessible
public virtual fflib_IDomain newInstance(List<SObject> records, SObjectType domainSObjectType)
{
if(domainSObjectType==null)
Expand All @@ -413,17 +451,20 @@ public virtual class fflib_Application
}

@TestVisible
@NamespaceAccessible
protected virtual void setMock(fflib_ISObjectDomain mockDomain)
{
mockDomainByObject.put((Object) mockDomain.sObjectType(), (fflib_IDomain) mockDomain);
}

@TestVisible
@NamespaceAccessible
protected virtual void setMock(fflib_IDomain mockDomain)
{
mockDomainByObject.put(mockDomain.getType(), mockDomain);
}

@NamespaceAccessible
protected virtual Map<Object, Type> getConstructorTypeByObject(Map<SObjectType, Type> constructorTypeBySObjectType)
{
Map<Object, Type> result = new Map<Object, Type>();
Expand All @@ -438,10 +479,12 @@ public virtual class fflib_Application
}
}

@NamespaceAccessible
public class ApplicationException extends Exception { }

/**
* Exception representing a developer coding error, not intended for end user eyes
**/
@NamespaceAccessible
public class DeveloperException extends Exception { }
}
1 change: 1 addition & 0 deletions sfdx-source/apex-common/main/classes/fflib_IDomain.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_IDomain
{
Object getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_IDomainConstructor
{
fflib_IDomain construct(List<Object> objects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_IDomainFactory
{
fflib_IDomain newInstance(Set<Id> recordIds);
Expand Down
1 change: 1 addition & 0 deletions sfdx-source/apex-common/main/classes/fflib_IObjects.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_IObjects extends fflib_IDomain
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

@NamespaceAccessible
public interface fflib_ISObjectDomain extends fflib_IDomain
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

@NamespaceAccessible
public interface fflib_ISObjectSelector
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/**
* @see fflib_SObjectUnitOfWork
**/
@NamespaceAccessible
public interface fflib_ISObjectUnitOfWork
{
/**
Expand Down
1 change: 1 addition & 0 deletions sfdx-source/apex-common/main/classes/fflib_ISObjects.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_ISObjects extends fflib_IObjects
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_ISelectorFactory
{
fflib_ISObjectSelector newInstance(SObjectType sObjectType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_IServiceFactory
{
Object newInstance(Type serviceInterfaceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
@NamespaceAccessible
public interface fflib_IUnitOfWorkFactory
{
fflib_ISObjectUnitOfWork newInstance();
Expand Down
Loading