mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Remove hard-coded registration of known backend-modules from QBackendModuleDispatcher, in favor of all modules self-registering in static-init block
This commit is contained in:
@ -27,21 +27,18 @@ import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QModuleDispatchException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** This class is responsible for loading a backend module, by its name, and
|
||||
** returning an instance.
|
||||
**
|
||||
** TODO - make this mapping runtime-bound, not pre-compiled in.
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class QBackendModuleDispatcher
|
||||
{
|
||||
private static final QLogger LOG = QLogger.getLogger(QBackendModuleDispatcher.class);
|
||||
|
||||
private static Map<String, String> backendTypeToModuleClassNameMap;
|
||||
private static Map<String, String> backendTypeToModuleClassNameMap = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
@ -50,51 +47,6 @@ public class QBackendModuleDispatcher
|
||||
*******************************************************************************/
|
||||
public QBackendModuleDispatcher()
|
||||
{
|
||||
initBackendTypeToModuleClassNameMap();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static void initBackendTypeToModuleClassNameMap()
|
||||
{
|
||||
if(backendTypeToModuleClassNameMap != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> newMap = new HashMap<>();
|
||||
|
||||
String[] moduleClassNames = new String[]
|
||||
{
|
||||
// todo - let modules somehow "export" their types here?
|
||||
// e.g., backend-core shouldn't need to "know" about the modules.
|
||||
"com.kingsrook.qqq.backend.core.modules.backend.implementations.mock.MockBackendModule",
|
||||
"com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryBackendModule",
|
||||
"com.kingsrook.qqq.backend.core.modules.backend.implementations.enumeration.EnumerationBackendModule",
|
||||
"com.kingsrook.qqq.backend.module.rdbms.RDBMSBackendModule",
|
||||
"com.kingsrook.qqq.backend.module.filesystem.local.FilesystemBackendModule",
|
||||
"com.kingsrook.qqq.backend.module.filesystem.s3.S3BackendModule",
|
||||
"com.kingsrook.qqq.backend.module.api.APIBackendModule"
|
||||
};
|
||||
|
||||
for(String moduleClassName : moduleClassNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> moduleClass = Class.forName(moduleClassName);
|
||||
QBackendModuleInterface module = (QBackendModuleInterface) moduleClass.getConstructor().newInstance();
|
||||
newMap.put(module.getBackendType(), moduleClassName);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.debug("Backend module could not be loaded", e, logPair("moduleClassName", moduleClassName));
|
||||
}
|
||||
}
|
||||
|
||||
backendTypeToModuleClassNameMap = newMap;
|
||||
}
|
||||
|
||||
|
||||
@ -104,7 +56,6 @@ public class QBackendModuleDispatcher
|
||||
*******************************************************************************/
|
||||
public static void registerBackendModule(QBackendModuleInterface moduleInstance)
|
||||
{
|
||||
initBackendTypeToModuleClassNameMap();
|
||||
String backendType = moduleInstance.getBackendType();
|
||||
if(backendTypeToModuleClassNameMap.containsKey(backendType))
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails
|
||||
/*******************************************************************************
|
||||
** Interface that a QBackendModule must implement.
|
||||
**
|
||||
** Note, some methods all have a default version, which throws a 'not implemented'
|
||||
** Note, all methods have a default version, which throws a 'not implemented'
|
||||
** exception.
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.modules.backend.implementations.enumerati
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.CountInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
|
||||
|
||||
@ -37,6 +38,10 @@ import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
*******************************************************************************/
|
||||
public class EnumerationBackendModule implements QBackendModuleInterface
|
||||
{
|
||||
static
|
||||
{
|
||||
QBackendModuleDispatcher.registerBackendModule(new EnumerationBackendModule());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** Method where a backend module must be able to provide its type (name).
|
||||
|
@ -28,6 +28,7 @@ import com.kingsrook.qqq.backend.core.actions.interfaces.DeleteInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.InsertInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.UpdateInterface;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
|
||||
|
||||
@ -42,6 +43,12 @@ import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
*******************************************************************************/
|
||||
public class MemoryBackendModule implements QBackendModuleInterface
|
||||
{
|
||||
static
|
||||
{
|
||||
QBackendModuleDispatcher.registerBackendModule(new MemoryBackendModule());
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Method where a backend module must be able to provide its type (name).
|
||||
*******************************************************************************/
|
||||
|
@ -28,6 +28,7 @@ import com.kingsrook.qqq.backend.core.actions.interfaces.InsertInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.UpdateInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
|
||||
|
||||
@ -40,6 +41,11 @@ import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
*******************************************************************************/
|
||||
public class MockBackendModule implements QBackendModuleInterface
|
||||
{
|
||||
static
|
||||
{
|
||||
QBackendModuleDispatcher.registerBackendModule(new MockBackendModule());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** Method where a backend module must be able to provide its type (name).
|
||||
*******************************************************************************/
|
||||
|
@ -30,6 +30,7 @@ import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.UpdateInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
import com.kingsrook.qqq.backend.module.api.actions.APICountAction;
|
||||
import com.kingsrook.qqq.backend.module.api.actions.APIDeleteAction;
|
||||
@ -44,6 +45,11 @@ import com.kingsrook.qqq.backend.module.api.actions.APIUpdateAction;
|
||||
*******************************************************************************/
|
||||
public class APIBackendModule implements QBackendModuleInterface
|
||||
{
|
||||
static
|
||||
{
|
||||
QBackendModuleDispatcher.registerBackendModule(new APIBackendModule());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** Method where a backend module must be able to provide its type (name).
|
||||
*******************************************************************************/
|
||||
|
@ -29,6 +29,7 @@ import com.kingsrook.qqq.backend.core.actions.interfaces.QueryInterface;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.UpdateInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.base.FilesystemBackendModuleInterface;
|
||||
import com.kingsrook.qqq.backend.module.filesystem.base.actions.AbstractBaseFilesystemAction;
|
||||
@ -48,6 +49,10 @@ public class S3BackendModule implements QBackendModuleInterface, FilesystemBacke
|
||||
{
|
||||
public static final String BACKEND_TYPE = "s3";
|
||||
|
||||
static
|
||||
{
|
||||
QBackendModuleDispatcher.registerBackendModule(new S3BackendModule());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** For filesystem backends, get the module-specific action base-class, that helps
|
||||
|
@ -35,6 +35,7 @@ import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableBackendDetails;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleDispatcher;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.QBackendModuleInterface;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.actions.AbstractRDBMSAction;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.actions.RDBMSAggregateAction;
|
||||
@ -55,7 +56,10 @@ public class RDBMSBackendModule implements QBackendModuleInterface
|
||||
{
|
||||
private static final QLogger LOG = QLogger.getLogger(RDBMSBackendModule.class);
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
QBackendModuleDispatcher.registerBackendModule(new RDBMSBackendModule());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** Method where a backend module must be able to provide its type (name).
|
||||
|
Reference in New Issue
Block a user