Checkpoint

This commit is contained in:
Darin Kelkhoff
2021-11-08 21:04:45 -06:00
parent d1884eace1
commit caf879dc9f
20 changed files with 1013 additions and 8 deletions

View File

@ -0,0 +1,36 @@
package com.kingsrook.qqq.backend.core.actions;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
import com.kingsrook.qqq.backend.core.model.actions.TableMetaDataRequest;
import com.kingsrook.qqq.backend.core.model.actions.TableMetaDataResult;
import com.kingsrook.qqq.backend.core.model.metadata.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.frontend.QFrontendTableMetaData;
/*******************************************************************************
**
*******************************************************************************/
public class TableMetaDataAction
{
/*******************************************************************************
**
*******************************************************************************/
public TableMetaDataResult execute(TableMetaDataRequest tableMetaDataRequest) throws QException
{
// todo pre-customization - just get to modify the request?
TableMetaDataResult tableMetaDataResult = new TableMetaDataResult();
QTableMetaData table = tableMetaDataRequest.getInstance().getTable(tableMetaDataRequest.getTableName());
if(table == null)
{
throw (new QUserFacingException("Table [" + tableMetaDataRequest.getTableName() + "] was not found."));
}
tableMetaDataResult.setTable(new QFrontendTableMetaData(table, true));
// todo post-customization - can do whatever w/ the result if you want
return tableMetaDataResult;
}
}

View File

@ -0,0 +1,29 @@
package com.kingsrook.qqq.backend.core.exceptions;
/*******************************************************************************
**
*******************************************************************************/
public class QUserFacingException extends QException
{
/*******************************************************************************
**
*******************************************************************************/
public QUserFacingException(String message)
{
super(message);
}
/*******************************************************************************
**
*******************************************************************************/
public QUserFacingException(String message, Throwable cause)
{
super(message, cause);
}
}

View File

@ -0,0 +1,54 @@
package com.kingsrook.qqq.backend.core.model.actions;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
/*******************************************************************************
**
*******************************************************************************/
public class TableMetaDataRequest extends AbstractQRequest
{
private String tableName;
/*******************************************************************************
**
*******************************************************************************/
public TableMetaDataRequest()
{
}
/*******************************************************************************
**
*******************************************************************************/
public TableMetaDataRequest(QInstance instance)
{
super(instance);
}
/*******************************************************************************
** Getter for tableName
**
*******************************************************************************/
public String getTableName()
{
return tableName;
}
/*******************************************************************************
** Setter for tableName
**
*******************************************************************************/
public void setTableName(String tableName)
{
this.tableName = tableName;
}
}

View File

@ -0,0 +1,36 @@
package com.kingsrook.qqq.backend.core.model.actions;
import com.kingsrook.qqq.backend.core.model.metadata.frontend.QFrontendTableMetaData;
/*******************************************************************************
* Result for a metaData action
*
*******************************************************************************/
public class TableMetaDataResult extends AbstractQResult
{
QFrontendTableMetaData table;
/*******************************************************************************
** Getter for table
**
*******************************************************************************/
public QFrontendTableMetaData getTable()
{
return table;
}
/*******************************************************************************
** Setter for table
**
*******************************************************************************/
public void setTable(QFrontendTableMetaData table)
{
this.table = table;
}
}

View File

@ -23,8 +23,8 @@ public class QModuleDispatcher
public QModuleDispatcher()
{
backendTypeToModuleClassNameMap = new HashMap<>();
backendTypeToModuleClassNameMap.put("mock", "com.kingsrook.qqq.backend.core.modules.mock.MockModule");
backendTypeToModuleClassNameMap.put("rdbms", "com.kingsrook.qqq.backend.module.rdbms.RDBSMModule");
backendTypeToModuleClassNameMap.put("nosql", "com.kingsrook.qqq.backend.module.nosql.NoSQLModule");
// todo - let user define custom type -> classes
}

View File

@ -0,0 +1,39 @@
package com.kingsrook.qqq.backend.core.modules.mock;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.InsertRequest;
import com.kingsrook.qqq.backend.core.model.actions.InsertResult;
import com.kingsrook.qqq.backend.core.model.data.QRecordWithStatus;
import com.kingsrook.qqq.backend.core.modules.interfaces.InsertInterface;
/*******************************************************************************
**
*******************************************************************************/
public class MockInsertAction implements InsertInterface
{
/*******************************************************************************
**
*******************************************************************************/
public InsertResult execute(InsertRequest insertRequest) throws QException
{
try
{
InsertResult rs = new InsertResult();
rs.setRecords(insertRequest.getRecords().stream().map(qRecord ->
{
return new QRecordWithStatus(qRecord);
}).toList());
return rs;
}
catch(Exception e)
{
throw new QException("Error executing insert: " + e.getMessage(), e);
}
}
}

View File

@ -0,0 +1,33 @@
package com.kingsrook.qqq.backend.core.modules.mock;
import com.kingsrook.qqq.backend.core.modules.interfaces.InsertInterface;
import com.kingsrook.qqq.backend.core.modules.interfaces.QModuleInterface;
import com.kingsrook.qqq.backend.core.modules.interfaces.QueryInterface;
/*******************************************************************************
**
*******************************************************************************/
public class MockModule implements QModuleInterface
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public QueryInterface getQueryInterface()
{
return new MockQueryAction();
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public InsertInterface getInsertInterface()
{
return (new MockInsertAction());
}
}

View File

@ -0,0 +1,51 @@
package com.kingsrook.qqq.backend.core.modules.mock;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.QueryRequest;
import com.kingsrook.qqq.backend.core.model.actions.QueryResult;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.QTableMetaData;
import com.kingsrook.qqq.backend.core.modules.interfaces.QueryInterface;
/*******************************************************************************
**
*******************************************************************************/
public class MockQueryAction implements QueryInterface
{
/*******************************************************************************
**
*******************************************************************************/
public QueryResult execute(QueryRequest queryRequest) throws QException
{
try
{
QTableMetaData table = queryRequest.getTable();
QueryResult rs = new QueryResult();
List<QRecord> records = new ArrayList<>();
rs.setRecords(records);
QRecord record = new QRecord();
records.add(record);
record.setTableName(table.getName());
for(String field : table.getFields().keySet())
{
record.setValue(field, "1");
}
return rs;
}
catch(Exception e)
{
e.printStackTrace();
throw new QException("Error executing query", e);
}
}
}

View File

@ -251,7 +251,7 @@ public class CollectionUtils
{
List<List<T>> rs = new LinkedList<>();
if(values.isEmpty())
if(values == null || values.isEmpty())
{
//////////////////////////////////////////////////////////////////
// if there are no input values, return an empty list of lists. //

View File

@ -0,0 +1,34 @@
package com.kingsrook.qqq.backend.core.utils;
/*******************************************************************************
**
*******************************************************************************/
public class ExceptionUtils
{
/*******************************************************************************
**
*******************************************************************************/
public static <T extends Throwable> T findClassInRootChain(Throwable e, Class<T> targetClass)
{
if (e == null)
{
return (null);
}
if(e.getClass().equals(targetClass))
{
//noinspection unchecked
return ((T) e);
}
if(e.getCause() == null)
{
return (null);
}
return findClassInRootChain(e.getCause(), targetClass);
}
}