Merge pull request #52 from wimvelzeboer/feature/ImprovedDynamicApplicationFactory
Feature/improved dynamic application factory
This commit is contained in:
+2
-1
@@ -59,7 +59,8 @@ public virtual class fflib_ClassicSelectorFactory
|
||||
* @param sObjectType The SObjectType of the Ids
|
||||
*
|
||||
* @return The queried records
|
||||
* @exception fflib_Application.DeveloperException is thrown if the Ids set is empty
|
||||
*
|
||||
* @throws fflib_Application.DeveloperException is thrown if the Ids set is empty
|
||||
*/
|
||||
public virtual List<SObject> selectById(Set<Id> recordIds, SObjectType sObjectType)
|
||||
{
|
||||
|
||||
@@ -38,7 +38,6 @@ public virtual class fflib_AppBinding
|
||||
protected System.Type interfaceType { get; set; }
|
||||
protected String namespacePrefix { get; set; }
|
||||
protected String packageName { get; set; }
|
||||
protected fflib_SharingMode sharingMode { get; set; }
|
||||
|
||||
public Integer compareTo(Object compareTo)
|
||||
{
|
||||
@@ -106,16 +105,6 @@ public virtual class fflib_AppBinding
|
||||
return this.bindingSequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns an enum value fflib_SharingMode that defines the type of sharing used in the implementation class
|
||||
*
|
||||
* @see fflib_SharingMode
|
||||
*/
|
||||
public virtual fflib_SharingMode getSharingMode()
|
||||
{
|
||||
return this.sharingMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the implementation for this binding.
|
||||
*
|
||||
@@ -224,19 +213,4 @@ public virtual class fflib_AppBinding
|
||||
this.bindingSequence = sequence;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an enum value fflib_SharingMode that defines the type of sharing used in the implementation class
|
||||
*
|
||||
* @param sharingMode A enum value of fflib_SharingMode representing the sharing mode
|
||||
*
|
||||
* @return An instance of itself to enable method chaining
|
||||
*
|
||||
* @see fflib_SharingMode
|
||||
*/
|
||||
public virtual fflib_IAppBinding setSharingMode(fflib_SharingMode sharingMode)
|
||||
{
|
||||
this.sharingMode = sharingMode;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-25
@@ -45,7 +45,6 @@ public with sharing class fflib_AppBindingMetaDataModule
|
||||
.setNamespacePrefix(binding.NamespacePrefix)
|
||||
.setPackageName(binding.ApplicationPackage__r.DeveloperName)
|
||||
.setSequence(binding.BindingSequence__c)
|
||||
.setSharingMode(getSharingModeFromString(binding.SharingMode__c))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -94,30 +93,6 @@ public with sharing class fflib_AppBindingMetaDataModule
|
||||
return bindingTypeByStrings.get(binding.Type__c.toUpperCase());
|
||||
}
|
||||
|
||||
private fflib_SharingMode getSharingModeFromString(String sharingMode)
|
||||
{
|
||||
switch on sharingMode.toUpperCase()
|
||||
{
|
||||
when 'WITH SHARING'
|
||||
{
|
||||
return fflib_SharingMode.WithSharing;
|
||||
}
|
||||
when 'WITHOUT SHARING'
|
||||
{
|
||||
return fflib_SharingMode.WithoutSharing;
|
||||
}
|
||||
when 'INHERITED SHARING'
|
||||
{
|
||||
return fflib_SharingMode.WithoutSharing;
|
||||
}
|
||||
when 'NONE'
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Type getSystemType(fflib_AppBinding__mdt binding, Schema.SObjectField sObjectField)
|
||||
{
|
||||
String systemTypeName = String.valueOf(binding.get(sObjectField));
|
||||
|
||||
-7
@@ -120,12 +120,6 @@ public virtual class fflib_AppBindingResolver
|
||||
return this;
|
||||
}
|
||||
|
||||
public fflib_IAppBindingResolver bySharingMode(fflib_SharingMode sharingMode)
|
||||
{
|
||||
this.bindingToResolve.setSharingMode(sharingMode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public fflib_IAppBindingResolver byNamespacePrefix(String namespacePrefix)
|
||||
{
|
||||
this.bindingToResolve.setNamespacePrefix(namespacePrefix);
|
||||
@@ -166,7 +160,6 @@ public virtual class fflib_AppBindingResolver
|
||||
.selectByType(bindingToResolve.getBindingType())
|
||||
.selectByInterfaceType(bindingToResolve.getInterfaceType())
|
||||
.selectByObject(bindingToResolve.getBindingObject())
|
||||
.selectBySharingMode(bindingToResolve.getSharingMode())
|
||||
.selectBySequence(bindingToResolve.getSequence());
|
||||
|
||||
this.bindingToResolve = internalBindings.newAppBinding();
|
||||
|
||||
@@ -182,20 +182,6 @@ public virtual class fflib_AppBindings
|
||||
return new fflib_AppBindings(result);
|
||||
}
|
||||
|
||||
public fflib_IAppBindings selectBySharingMode(fflib_SharingMode sharingMode)
|
||||
{
|
||||
if (null == sharingMode) return this;
|
||||
|
||||
List<fflib_IAppBinding> result = new List<fflib_IAppBinding>();
|
||||
for (fflib_IAppBinding binding : bindings)
|
||||
{
|
||||
if (binding.getSharingMode() != sharingMode) continue;
|
||||
|
||||
result.add(binding);
|
||||
}
|
||||
return new fflib_AppBindings(result);
|
||||
}
|
||||
|
||||
public fflib_IAppBindings selectByNamespacePrefix(String namespacePrefix)
|
||||
{
|
||||
if (null == namespacePrefix) return this;
|
||||
|
||||
-1
@@ -46,7 +46,6 @@ public virtual without sharing class fflib_AppBindingsSelector extends fflib_SOb
|
||||
fflib_AppBinding__mdt.NamespacePrefix,
|
||||
fflib_AppBinding__mdt.ImplementationType__c,
|
||||
fflib_AppBinding__mdt.InterfaceType__c,
|
||||
fflib_AppBinding__mdt.SharingMode__c,
|
||||
fflib_AppBinding__mdt.Type__c
|
||||
};
|
||||
}
|
||||
|
||||
-12
@@ -32,18 +32,6 @@ public abstract class fflib_DynamicAppFactory
|
||||
{
|
||||
protected String packageName;
|
||||
|
||||
protected fflib_SharingMode sharingMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (sharingMode == null)
|
||||
{
|
||||
sharingMode = fflib_SharingMode.WithSharing;
|
||||
}
|
||||
return sharingMode;
|
||||
}
|
||||
set;
|
||||
}
|
||||
protected fflib_IAppBindingResolver resolver;
|
||||
protected Map<System.Type, System.Type> routes;
|
||||
|
||||
|
||||
-7
@@ -94,12 +94,6 @@ public virtual class fflib_DynamicSelectorFactory
|
||||
this.selectorFactory.setMock(sObjectType, selectorInstance);
|
||||
}
|
||||
|
||||
public fflib_DynamicSelectorFactory setSharingMode(fflib_SharingMode sharingMode)
|
||||
{
|
||||
this.sharingMode = sharingMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void loadBindings()
|
||||
{
|
||||
fflib_IAppBindings appBindings = new fflib_AppBindings(resolver.resolve());
|
||||
@@ -112,7 +106,6 @@ public virtual class fflib_DynamicSelectorFactory
|
||||
|
||||
Map<SObjectType, Type> implementationBySObjectType =
|
||||
appBindings.selectByType(fflib_AppBindingType.Selector)
|
||||
.selectBySharingMode(this.sharingMode)
|
||||
.getImplementationBySObjectType();
|
||||
|
||||
this.selectorFactory = new fflib_ClassicSelectorFactory(implementationBySObjectType);
|
||||
|
||||
-6
@@ -66,12 +66,6 @@ public virtual class fflib_DynamicServiceFactory
|
||||
this.serviceFactory.setMock(serviceInterfaceType, serviceImpl);
|
||||
}
|
||||
|
||||
public fflib_DynamicServiceFactory setSharingMode(fflib_SharingMode sharingMode)
|
||||
{
|
||||
this.sharingMode = sharingMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void loadBindings()
|
||||
{
|
||||
fflib_IAppBindings appBindings = new fflib_AppBindings(resolver.resolve());
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* File Name: fflib_SharingMode
|
||||
* @description Enum with the Application Binding Sharing Modes
|
||||
|
||||
* @author architect ir. Wilhelmus G.J. Velzeboer
|
||||
*
|
||||
* Copyright (c), W.G.J. Velzeboer,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above author notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither the name of the author nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* 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.
|
||||
*/
|
||||
public enum fflib_SharingMode
|
||||
{
|
||||
WithSharing, WithoutSharing, InheritedSharing, None
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||
<apiVersion>57.0</apiVersion>
|
||||
<status>Active</status>
|
||||
</ApexClass>
|
||||
-18
@@ -66,13 +66,6 @@ public interface fflib_IAppBinding
|
||||
*/
|
||||
Decimal getSequence();
|
||||
|
||||
/**
|
||||
* @return Returns an enum value fflib_SharingMode that defines the type of sharing used in the implementation class
|
||||
*
|
||||
* @see fflib_SharingMode
|
||||
*/
|
||||
fflib_SharingMode getSharingMode();
|
||||
|
||||
/**
|
||||
* Creates a new instance of the implementation for this binding.
|
||||
*
|
||||
@@ -148,15 +141,4 @@ public interface fflib_IAppBinding
|
||||
* @return An instance of itself to enable method chaining
|
||||
*/
|
||||
fflib_IAppBinding setSequence(Decimal sequence);
|
||||
|
||||
/**
|
||||
* Sets an enum value fflib_SharingMode that defines the type of sharing used in the implementation class
|
||||
*
|
||||
* @param sharingMode A enum value of fflib_SharingMode representing the sharing mode
|
||||
*
|
||||
* @return An instance of itself to enable method chaining
|
||||
*
|
||||
* @see fflib_SharingMode
|
||||
*/
|
||||
fflib_IAppBinding setSharingMode(fflib_SharingMode sharingMode);
|
||||
}
|
||||
-1
@@ -35,7 +35,6 @@ public interface fflib_IAppBindingResolver
|
||||
fflib_IAppBindingResolver bySequence(Integer sequence);
|
||||
fflib_IAppBindingResolver byType(fflib_AppBindingType bindingType);
|
||||
fflib_IAppBindingResolver byInterfaceType(System.Type interfaceType);
|
||||
fflib_IAppBindingResolver bySharingMode(fflib_SharingMode sharingMode);
|
||||
fflib_IAppBindingResolver byNamespacePrefix(String namespacePrefix);
|
||||
fflib_IAppBindingResolver byPackageName(String packageName);
|
||||
List<fflib_IAppBinding> resolve();
|
||||
|
||||
-1
@@ -44,7 +44,6 @@ public interface fflib_IAppBindings
|
||||
fflib_IAppBindings selectBySequence(Decimal sequence);
|
||||
fflib_IAppBindings selectByType(fflib_AppBindingType bindingType);
|
||||
fflib_IAppBindings selectByInterfaceType(System.Type interfaceType);
|
||||
fflib_IAppBindings selectBySharingMode(fflib_SharingMode sharingMode);
|
||||
fflib_IAppBindings selectByNamespacePrefix(String namespacePrefix);
|
||||
fflib_IAppBindings selectByPackageName(String packageName);
|
||||
}
|
||||
-4
@@ -63,10 +63,6 @@
|
||||
<behavior>Required</behavior>
|
||||
<field>ImplementationType__c</field>
|
||||
</layoutItems>
|
||||
<layoutItems>
|
||||
<behavior>Required</behavior>
|
||||
<field>SharingMode__c</field>
|
||||
</layoutItems>
|
||||
</layoutColumns>
|
||||
<style>TwoColumnsLeftToRight</style>
|
||||
</layoutSections>
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
|
||||
<fullName>SharingMode__c</fullName>
|
||||
<defaultValue>"With Sharing"</defaultValue>
|
||||
<externalId>false</externalId>
|
||||
<fieldManageability>DeveloperControlled</fieldManageability>
|
||||
<label>Sharing mode</label>
|
||||
<required>true</required>
|
||||
<type>Picklist</type>
|
||||
<valueSet>
|
||||
<restricted>true</restricted>
|
||||
<valueSetDefinition>
|
||||
<sorted>false</sorted>
|
||||
<value>
|
||||
<fullName>With Sharing</fullName>
|
||||
<default>true</default>
|
||||
<label>With Sharing</label>
|
||||
</value>
|
||||
<value>
|
||||
<fullName>Without Sharing</fullName>
|
||||
<default>false</default>
|
||||
<label>Without Sharing</label>
|
||||
</value>
|
||||
<value>
|
||||
<fullName>Inherited Sharing</fullName>
|
||||
<default>false</default>
|
||||
<label>Inherited Sharing</label>
|
||||
</value>
|
||||
<value>
|
||||
<fullName>None</fullName>
|
||||
<default>false</default>
|
||||
<label>None</label>
|
||||
</value>
|
||||
</valueSetDefinition>
|
||||
</valueSet>
|
||||
</CustomField>
|
||||
+2
-4
@@ -179,8 +179,7 @@ public class fflib_DynamicDomainFactoryTest
|
||||
Type__c = 'Domain',
|
||||
BindingObject__c = '',
|
||||
BindingObjectAlternate__c = ACCOUNT_OBJECT_TYPE.getDescribe().getName(),
|
||||
ImplementationType__c = MyDomainConstructor.class.getName(),
|
||||
SharingMode__c = 'None'
|
||||
ImplementationType__c = MyDomainConstructor.class.getName()
|
||||
),
|
||||
new fflib_AppBinding__mdt(
|
||||
ApplicationPackage__c = otherApp.Id,
|
||||
@@ -188,8 +187,7 @@ public class fflib_DynamicDomainFactoryTest
|
||||
Type__c = 'Domain',
|
||||
BindingObject__c = '',
|
||||
BindingObjectAlternate__c = ACCOUNT_OBJECT_TYPE.getDescribe().getName(),
|
||||
ImplementationType__c = OtherDomainConstructor.class.getName(),
|
||||
SharingMode__c = 'None'
|
||||
ImplementationType__c = OtherDomainConstructor.class.getName()
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
+2
-4
@@ -37,8 +37,7 @@ public class fflib_DynamicSelectorFactoryTest
|
||||
|
||||
@TestVisible
|
||||
private static final fflib_DynamicSelectorFactory Selector =
|
||||
new fflib_DynamicSelectorFactory(bindingResolver)
|
||||
.setSharingMode(fflib_SharingMode.WithSharing);
|
||||
new fflib_DynamicSelectorFactory(bindingResolver);
|
||||
|
||||
private static final Type MY_SELECTOR_TYPE = fflib_DynamicSelectorFactoryTest.MySelector.class;
|
||||
|
||||
@@ -147,8 +146,7 @@ public class fflib_DynamicSelectorFactoryTest
|
||||
Type__c = 'Selector',
|
||||
BindingObject__c = '',
|
||||
BindingObjectAlternate__c = Schema.Account.SObjectType.getDescribe().getName(),
|
||||
ImplementationType__c = MY_SELECTOR_TYPE.getName(),
|
||||
SharingMode__c = 'With Sharing'
|
||||
ImplementationType__c = MY_SELECTOR_TYPE.getName()
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
+1
-7
@@ -112,7 +112,6 @@ public class fflib_DynamicServiceFactoryTest
|
||||
result.setBindingType(fflib_AppBindingType.Service);
|
||||
result.setInterfaceType(MY_SERVICE_TYPE);
|
||||
result.setImplementationType(MY_SERVICE_TYPE);
|
||||
result.setSharingMode(fflib_SharingMode.WithSharing);
|
||||
result.setSequence(2);
|
||||
return result;
|
||||
}
|
||||
@@ -129,8 +128,7 @@ public class fflib_DynamicServiceFactoryTest
|
||||
new fflib_AppBindingResolver();
|
||||
|
||||
private static final fflib_DynamicServiceFactory Service =
|
||||
new fflib_DynamicServiceFactory(bindingResolver)
|
||||
.setSharingMode(fflib_SharingMode.WithSharing);
|
||||
new fflib_DynamicServiceFactory(bindingResolver);
|
||||
|
||||
public interface IMyService {}
|
||||
|
||||
@@ -148,14 +146,12 @@ public class fflib_DynamicServiceFactoryTest
|
||||
Type__c = 'Service',
|
||||
InterfaceType__c = MY_SERVICE_INTERFACE_TYPE.getName(),
|
||||
ImplementationType__c = MY_SERVICE_TYPE.getName(),
|
||||
SharingMode__c = 'With Sharing',
|
||||
BindingSequence__c = 1
|
||||
),
|
||||
new fflib_AppBinding__mdt(
|
||||
Type__c = 'Service',
|
||||
InterfaceType__c = MY_SERVICE_INTERFACE_TYPE.getName(),
|
||||
ImplementationType__c = MY_ALT_SERVICE_TYPE.getName(),
|
||||
SharingMode__c = 'With Sharing',
|
||||
BindingSequence__c = 2
|
||||
)
|
||||
};
|
||||
@@ -172,14 +168,12 @@ public class fflib_DynamicServiceFactoryTest
|
||||
Type__c = 'Service',
|
||||
InterfaceType__c = MY_SERVICE_INTERFACE_TYPE.getName(),
|
||||
ImplementationType__c = MY_SERVICE_TYPE.getName(),
|
||||
SharingMode__c = 'With Sharing',
|
||||
BindingSequence__c = 2
|
||||
),
|
||||
new fflib_AppBinding__mdt(
|
||||
Type__c = 'Service',
|
||||
InterfaceType__c = MY_SERVICE_INTERFACE_TYPE.getName(),
|
||||
ImplementationType__c = MY_ALT_SERVICE_TYPE.getName(),
|
||||
SharingMode__c = 'With Sharing',
|
||||
BindingSequence__c = 1
|
||||
)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user