Checkpoint - query stats (plus recordEntities with associations)

This commit is contained in:
2023-06-02 08:58:24 -05:00
parent 4ccc726f2e
commit d9a98c5987
12 changed files with 1472 additions and 9 deletions

View File

@ -23,10 +23,14 @@ package com.kingsrook.qqq.backend.core.model.data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.BaseTest;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.testentities.Item;
import com.kingsrook.qqq.backend.core.model.data.testentities.ItemWithPrimitives;
import com.kingsrook.qqq.backend.core.model.data.testentities.LineItem;
import com.kingsrook.qqq.backend.core.model.data.testentities.Order;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
@ -34,6 +38,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -281,7 +286,103 @@ class QRecordEntityTest extends BaseTest
assertEquals(QFieldType.STRING, qTableMetaData.getField("sku").getType());
assertEquals(QFieldType.INTEGER, qTableMetaData.getField("quantity").getType());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testOrderWithAssociationsToQRecord() throws QException
{
Order order = new Order();
order.setOrderNo("ORD001");
order.setLineItems(List.of(
new LineItem().withSku("ABC").withQuantity(1),
new LineItem().withSku("DEF").withQuantity(2)
));
QRecord qRecord = order.toQRecord();
assertEquals("ORD001", qRecord.getValueString("orderNo"));
List<QRecord> lineItems = qRecord.getAssociatedRecords().get("lineItems");
assertNotNull(lineItems);
assertEquals(2, lineItems.size());
assertEquals("ABC", lineItems.get(0).getValueString("sku"));
assertEquals(1, lineItems.get(0).getValueInteger("quantity"));
assertEquals("DEF", lineItems.get(1).getValueString("sku"));
assertEquals(2, lineItems.get(1).getValueInteger("quantity"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testOrderWithoutAssociationsToQRecord() throws QException
{
Order order = new Order();
order.setOrderNo("ORD001");
order.setLineItems(null);
QRecord qRecord = order.toQRecord();
assertEquals("ORD001", qRecord.getValueString("orderNo"));
List<QRecord> lineItems = qRecord.getAssociatedRecords().get("lineItems");
assertNull(lineItems);
order.setLineItems(new ArrayList<>());
qRecord = order.toQRecord();
lineItems = qRecord.getAssociatedRecords().get("lineItems");
assertNotNull(lineItems);
assertEquals(0, lineItems.size());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testQRecordWithAssociationsToOrder() throws QException
{
QRecord qRecord = new QRecord()
.withValue("orderNo", "ORD002")
.withAssociatedRecords("lineItems", List.of(
new QRecord().withValue("sku", "AB12").withValue("quantity", 42),
new QRecord().withValue("sku", "XY89").withValue("quantity", 47)
));
Order order = qRecord.toEntity(Order.class);
assertEquals("ORD002", order.getOrderNo());
assertEquals(2, order.getLineItems().size());
assertEquals("AB12", order.getLineItems().get(0).getSku());
assertEquals(42, order.getLineItems().get(0).getQuantity());
assertEquals("XY89", order.getLineItems().get(1).getSku());
assertEquals(47, order.getLineItems().get(1).getQuantity());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testQRecordWithoutAssociationsToOrder() throws QException
{
QRecord qRecord = new QRecord().withValue("orderNo", "ORD002");
Order order = qRecord.toEntity(Order.class);
assertEquals("ORD002", order.getOrderNo());
assertNull(order.getLineItems());
qRecord.withAssociatedRecords("lineItems", null);
order = qRecord.toEntity(Order.class);
assertNull(order.getLineItems());
qRecord.withAssociatedRecords("lineItems", new ArrayList<>());
order = qRecord.toEntity(Order.class);
assertNotNull(order.getLineItems());
assertEquals(0, order.getLineItems().size());
}
}

View File

@ -0,0 +1,102 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.model.data.testentities;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Sample of an entity that can be converted to & from a QRecord
*******************************************************************************/
public class LineItem extends QRecordEntity
{
@QField()
private String sku;
@QField()
private Integer quantity;
/*******************************************************************************
** Getter for sku
*******************************************************************************/
public String getSku()
{
return (this.sku);
}
/*******************************************************************************
** Setter for sku
*******************************************************************************/
public void setSku(String sku)
{
this.sku = sku;
}
/*******************************************************************************
** Fluent setter for sku
*******************************************************************************/
public LineItem withSku(String sku)
{
this.sku = sku;
return (this);
}
/*******************************************************************************
** Getter for quantity
*******************************************************************************/
public Integer getQuantity()
{
return (this.quantity);
}
/*******************************************************************************
** Setter for quantity
*******************************************************************************/
public void setQuantity(Integer quantity)
{
this.quantity = quantity;
}
/*******************************************************************************
** Fluent setter for quantity
*******************************************************************************/
public LineItem withQuantity(Integer quantity)
{
this.quantity = quantity;
return (this);
}
}

View File

@ -0,0 +1,104 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.model.data.testentities;
import java.util.List;
import com.kingsrook.qqq.backend.core.model.data.QAssociation;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Sample of an entity that can be converted to & from a QRecord
*******************************************************************************/
public class Order extends QRecordEntity
{
@QField()
private String orderNo;
@QAssociation(name = "lineItems")
private List<LineItem> lineItems;
/*******************************************************************************
** Getter for orderNo
*******************************************************************************/
public String getOrderNo()
{
return (this.orderNo);
}
/*******************************************************************************
** Setter for orderNo
*******************************************************************************/
public void setOrderNo(String orderNo)
{
this.orderNo = orderNo;
}
/*******************************************************************************
** Fluent setter for orderNo
*******************************************************************************/
public Order withOrderNo(String orderNo)
{
this.orderNo = orderNo;
return (this);
}
/*******************************************************************************
** Getter for lineItems
*******************************************************************************/
public List<LineItem> getLineItems()
{
return (this.lineItems);
}
/*******************************************************************************
** Setter for lineItems
*******************************************************************************/
public void setLineItems(List<LineItem> lineItems)
{
this.lineItems = lineItems;
}
/*******************************************************************************
** Fluent setter for lineItems
*******************************************************************************/
public Order withLineItems(List<LineItem> lineItems)
{
this.lineItems = lineItems;
return (this);
}
}