[New] added ElementMap.getBy(StringListParameter)
This commit is contained in:
parent
e1e285b6b1
commit
bf1db41f52
|
@ -21,6 +21,7 @@ import java.util.Set;
|
|||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
|
@ -80,6 +81,25 @@ public interface ElementMap<T extends StrolchRootElement> {
|
|||
*/
|
||||
public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException;
|
||||
|
||||
/**
|
||||
* Returns all elements which are referenced by the given {@link StringListParameter}. A reference {@link Parameter}
|
||||
* must have its interpretation set to the element type being referenced e.g. s
|
||||
* {@link StrolchConstants#INTERPRETATION_ORDER_REF} and the UOM must be set to the element's type and the value is
|
||||
* the id of the element
|
||||
*
|
||||
* @param tx
|
||||
* the {@link StrolchTransaction} instance
|
||||
* @param refP
|
||||
* the {@link StringListParameter} which references an element
|
||||
*
|
||||
* @return the list of elements found, or the empty list if they do not exist. <b>Note:</b> Any missing elements are
|
||||
* not returned!
|
||||
*
|
||||
* @throws StrolchException
|
||||
* if the {@link StringParameter} is not a properly configured as a reference parameter
|
||||
*/
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException;
|
||||
|
||||
public List<T> getAllElements(StrolchTransaction tx);
|
||||
|
||||
public List<T> getElementsBy(StrolchTransaction tx, String type);
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Set;
|
|||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import ch.eitchnet.utils.dbc.DBC;
|
||||
|
@ -195,6 +196,14 @@ public class AuditingElementMapFacade<T extends StrolchRootElement> implements E
|
|||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException {
|
||||
List<T> elements = this.elementMap.getBy(tx, refP);
|
||||
if (this.observeAccessReads)
|
||||
this.read.addAll(elements);
|
||||
return elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tx
|
||||
* @return
|
||||
|
|
|
@ -25,7 +25,11 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
@ -46,8 +50,8 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
private Map<String, Map<String, T>> elementMap;
|
||||
|
||||
public CachedElementMap() {
|
||||
this.allKeys = new HashSet<String>();
|
||||
this.elementMap = new HashMap<String, Map<String, T>>();
|
||||
this.allKeys = new HashSet<>();
|
||||
this.elementMap = new HashMap<>();
|
||||
}
|
||||
|
||||
protected abstract StrolchDao<T> getDao(StrolchTransaction tx);
|
||||
|
@ -100,6 +104,33 @@ public abstract class CachedElementMap<T extends StrolchRootElement> implements
|
|||
return byType.get(id);
|
||||
}
|
||||
|
||||
protected abstract void assertIsRefParam(Parameter<?> refP);
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
return getBy(tx, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
|
||||
List<T> elements = new ArrayList<>();
|
||||
String type = refP.getUom();
|
||||
List<String> ids = refP.getValue();
|
||||
|
||||
for (String id : ids) {
|
||||
T element = getBy(tx, type, id);
|
||||
if (element != null)
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<T> getAllElements(StrolchTransaction tx) {
|
||||
List<T> allElements = new ArrayList<>();
|
||||
|
|
|
@ -8,14 +8,14 @@ import java.text.MessageFormat;
|
|||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap {
|
||||
|
||||
@Override
|
||||
public Order getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
|
||||
if (!refP.getInterpretation().equals(INTERPRETATION_ORDER_REF)) {
|
||||
String msg = "{0} is not an Order reference as its interpretation is not {1}"; //$NON-NLS-1$
|
||||
|
@ -26,11 +26,6 @@ public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap
|
|||
String msg = "{0} is not an Order reference as its UOM is not set to a type!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
|
||||
}
|
||||
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
|
||||
return getBy(tx, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,15 +8,14 @@ import java.text.MessageFormat;
|
|||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class CachedResourceMap extends CachedElementMap<Resource> implements ResourceMap {
|
||||
|
||||
@Override
|
||||
public Resource getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
|
||||
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
if (!refP.getInterpretation().equals(INTERPRETATION_RESOURCE_REF)) {
|
||||
String msg = MessageFormat.format("{0} is not an Resource reference as its interpretation is not {1}", //$NON-NLS-1$
|
||||
refP.getLocator(), INTERPRETATION_RESOURCE_REF);
|
||||
|
@ -28,11 +27,6 @@ public class CachedResourceMap extends CachedElementMap<Resource> implements Res
|
|||
refP.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
|
||||
return getBy(tx, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import li.strolch.agent.api.ElementMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.StrolchDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
|
@ -48,6 +53,33 @@ public abstract class TransactionalElementMap<T extends StrolchRootElement> impl
|
|||
return getDao(tx).queryBy(type, id);
|
||||
}
|
||||
|
||||
protected abstract void assertIsRefParam(Parameter<?> refP);
|
||||
|
||||
@Override
|
||||
public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
return getBy(tx, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException {
|
||||
assertIsRefParam(refP);
|
||||
|
||||
List<T> elements = new ArrayList<>();
|
||||
String type = refP.getUom();
|
||||
List<String> ids = refP.getValue();
|
||||
|
||||
for (String id : ids) {
|
||||
T element = getBy(tx, type, id);
|
||||
if (element != null)
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getAllElements(StrolchTransaction tx) {
|
||||
return getDao(tx).queryAll();
|
||||
|
|
|
@ -8,14 +8,14 @@ import java.text.MessageFormat;
|
|||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class TransactionalOrderMap extends TransactionalElementMap<Order> implements OrderMap {
|
||||
|
||||
@Override
|
||||
public Order getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
|
||||
if (!refP.getInterpretation().equals(INTERPRETATION_ORDER_REF)) {
|
||||
String msg = "{0} is not an Order reference as its interpretation is not {1}"; //$NON-NLS-1$
|
||||
|
@ -26,11 +26,6 @@ public class TransactionalOrderMap extends TransactionalElementMap<Order> implem
|
|||
String msg = "{0} is not an Order reference as its UOM is not set to a type!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
|
||||
}
|
||||
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
|
||||
return getBy(tx, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,14 +8,14 @@ import java.text.MessageFormat;
|
|||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
||||
public class TransactionalResourceMap extends TransactionalElementMap<Resource> implements ResourceMap {
|
||||
|
||||
@Override
|
||||
public Resource getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException {
|
||||
protected void assertIsRefParam(Parameter<?> refP) {
|
||||
|
||||
if (!refP.getInterpretation().equals(INTERPRETATION_RESOURCE_REF)) {
|
||||
String msg = "{0} is not an Resource reference as its interpretation is not {1}"; //$NON-NLS-1$
|
||||
|
@ -26,11 +26,6 @@ public class TransactionalResourceMap extends TransactionalElementMap<Resource>
|
|||
String msg = "{0} is not an Resource reference as its UOM is not set to a type!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
|
||||
}
|
||||
|
||||
String type = refP.getUom();
|
||||
String id = refP.getValue();
|
||||
|
||||
return getBy(tx, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,6 +49,7 @@ import li.strolch.model.audit.AuditQuery;
|
|||
import li.strolch.model.audit.AuditVisitor;
|
||||
import li.strolch.model.audit.NoStrategyAuditVisitor;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
|
@ -359,6 +360,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return getOrderMap().getBy(this, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> getOrdersBy(StringListParameter refP) throws StrolchException {
|
||||
return getOrderMap().getBy(this, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getOrderBy(String type, String id) {
|
||||
return getOrderMap().getBy(this, type, id);
|
||||
|
@ -369,6 +375,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return getResourceMap().getBy(this, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> getResourcesBy(StringListParameter refP) throws StrolchException {
|
||||
return getResourceMap().getBy(this, refP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getResourceBy(String type, String id) {
|
||||
return getResourceMap().getBy(this, type, id);
|
||||
|
|
|
@ -33,6 +33,7 @@ import li.strolch.model.audit.Audit;
|
|||
import li.strolch.model.audit.AuditQuery;
|
||||
import li.strolch.model.audit.AuditVisitor;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
|
@ -136,6 +137,7 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*
|
||||
* @param refP
|
||||
* the {@link StringParameter} which references a {@link Resource}
|
||||
*
|
||||
* @return the resource referenced by the parameter, or null if it does not exist
|
||||
*
|
||||
* @throws StrolchException
|
||||
|
@ -143,6 +145,22 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*/
|
||||
public Resource getResourceBy(StringParameter refP) throws StrolchException;
|
||||
|
||||
/**
|
||||
* Returns all {@link Resource Resources} which are referenced by the given {@link StringListParameter}. A reference
|
||||
* {@link Parameter} must have its interpretation set to {@link StrolchConstants#INTERPRETATION_RESOURCE_REF} and
|
||||
* the UOM must be set to the resource's type and the value is the id of the resource
|
||||
*
|
||||
* @param refP
|
||||
* the {@link StringListParameter} which references a list of {@link Resource Resources}
|
||||
*
|
||||
* @return the resources referenced by the parameter, or the empty list if they do not exist. <b>Note:</b> Any
|
||||
* missing resources are not returned!
|
||||
*
|
||||
* @throws StrolchException
|
||||
* if the {@link StringListParameter} is not a properly configured as a reference parameter
|
||||
*/
|
||||
public List<Resource> getResourcesBy(StringListParameter refP) throws StrolchException;
|
||||
|
||||
/**
|
||||
* Returns the {@link Order} with the given type and id, or null if it does not exist
|
||||
*
|
||||
|
@ -162,10 +180,27 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*
|
||||
* @param refP
|
||||
* the {@link StringParameter} which references an {@link Order}
|
||||
*
|
||||
* @return the order referenced by the parameter, or null if it does not exist
|
||||
*
|
||||
* @throws StrolchException
|
||||
* if the {@link StringParameter} is not a properly configured as a reference parameter
|
||||
*/
|
||||
public Order getOrderBy(StringParameter refP) throws StrolchException;
|
||||
|
||||
/**
|
||||
* Returns all {@link Order Orders} which are referenced by the given {@link StringListParameter}. A reference
|
||||
* {@link Parameter} must have its interpretation set to {@link StrolchConstants#INTERPRETATION_ORDER_REF} and the
|
||||
* UOM must be set to the order's type and the value is the id of the order
|
||||
*
|
||||
* @param refP
|
||||
* the {@link StringListParameter} which references a list of {@link Order Orders}
|
||||
*
|
||||
* @return the orders referenced by the parameter, or the empty list if they do not exist. <b>Note:</b> Any missing
|
||||
* orders are not returned!
|
||||
*
|
||||
* @throws StrolchException
|
||||
* if the {@link StringListParameter} is not a properly configured as a reference parameter
|
||||
*/
|
||||
public List<Order> getOrdersBy(StringListParameter refP) throws StrolchException;
|
||||
}
|
||||
|
|
|
@ -39,9 +39,9 @@ public class InMemoryAuditQuery<U> {
|
|||
* @param auditVisitor
|
||||
*/
|
||||
public InMemoryAuditQuery(AuditTypeNavigator navigator, List<AuditSelector> selectors, AuditVisitor<U> auditVisitor) {
|
||||
DBC.PRE.assertNotNull("Navigator must be set!", navigator);
|
||||
DBC.PRE.assertNotNull("selectors must be set!", selectors);
|
||||
DBC.PRE.assertNotNull("auditVisitor must be set!", auditVisitor);
|
||||
DBC.PRE.assertNotNull("Navigator must be set!", navigator); //$NON-NLS-1$
|
||||
DBC.PRE.assertNotNull("selectors must be set!", selectors); //$NON-NLS-1$
|
||||
DBC.PRE.assertNotNull("auditVisitor must be set!", auditVisitor); //$NON-NLS-1$
|
||||
this.navigator = navigator;
|
||||
this.selectors = selectors;
|
||||
this.auditVisitor = auditVisitor;
|
||||
|
@ -49,7 +49,7 @@ public class InMemoryAuditQuery<U> {
|
|||
|
||||
public List<U> doQuery(InMemoryAuditDao dao) {
|
||||
|
||||
List<U> result = new ArrayList<U>();
|
||||
List<U> result = new ArrayList<>();
|
||||
List<Audit> elements = this.navigator.navigate(dao);
|
||||
for (Audit audit : elements) {
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ import ch.eitchnet.utils.collections.DateRange;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public class AuditQueryTest {
|
||||
|
||||
private static Date past;
|
||||
|
|
Loading…
Reference in New Issue