diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/ElementMap.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/ElementMap.java index 28f88461a..398ae3e9f 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/ElementMap.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/ElementMap.java @@ -65,7 +65,7 @@ public interface ElementMap { public T getBy(StrolchTransaction tx, String type, String id); /** - * Returns the Element which is referenced by the given {@link StringParameter}. A reference {@link Parameter} must + * Returns the element which is referenced by the given {@link StringParameter}. 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 @@ -74,12 +74,15 @@ public interface ElementMap { * the {@link StrolchTransaction} instance * @param refP * the {@link StringParameter} which references an element + * @param assertExists + * if true, and element does not exist, then a {@link StrolchException} is thrown + * * @return the element found, or null if it does not exist * * @throws StrolchException * if the {@link StringParameter} is not a properly configured as a reference parameter */ - public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException; + public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException; /** * Returns all elements which are referenced by the given {@link StringListParameter}. A reference {@link Parameter} @@ -91,6 +94,8 @@ public interface ElementMap { * the {@link StrolchTransaction} instance * @param refP * the {@link StringListParameter} which references an element + * @param assertExists + * if true, and element does not exist, then a {@link StrolchException} is thrown * * @return the list of elements found, or the empty list if they do not exist. Note: Any missing elements are * not returned! @@ -98,7 +103,7 @@ public interface ElementMap { * @throws StrolchException * if the {@link StringParameter} is not a properly configured as a reference parameter */ - public List getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException; + public List getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists) throws StrolchException; public List getAllElements(StrolchTransaction tx); diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/AuditingElementMapFacade.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/AuditingElementMapFacade.java index 479b4c783..7a5ef552d 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/AuditingElementMapFacade.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/AuditingElementMapFacade.java @@ -105,57 +105,26 @@ public class AuditingElementMapFacade implements E return this.deletedAllByType; } - /** - * @param tx - * @param type - * @return - * @see li.strolch.agent.api.ElementMap#hasType(li.strolch.persistence.api.StrolchTransaction, java.lang.String) - */ @Override public boolean hasType(StrolchTransaction tx, String type) { return this.elementMap.hasType(tx, type); } - /** - * @param tx - * @param type - * @param id - * @return - * @see li.strolch.agent.api.ElementMap#hasElement(li.strolch.persistence.api.StrolchTransaction, java.lang.String, - * java.lang.String) - */ @Override public boolean hasElement(StrolchTransaction tx, String type, String id) { return this.elementMap.hasElement(tx, type, id); } - /** - * @param tx - * @return - * @see li.strolch.agent.api.ElementMap#querySize(li.strolch.persistence.api.StrolchTransaction) - */ @Override public long querySize(StrolchTransaction tx) { return this.elementMap.querySize(tx); } - /** - * @param tx - * @param type - * @return - * @see li.strolch.agent.api.ElementMap#querySize(li.strolch.persistence.api.StrolchTransaction, java.lang.String) - */ @Override public long querySize(StrolchTransaction tx, String type) { return this.elementMap.querySize(tx, type); } - /** - * @param tx - * @param type - * @return - * @see li.strolch.agent.api.ElementMap#getTemplate(li.strolch.persistence.api.StrolchTransaction, java.lang.String) - */ @Override public T getTemplate(StrolchTransaction tx, String type) { T template = this.elementMap.getTemplate(tx, type); @@ -164,14 +133,6 @@ public class AuditingElementMapFacade implements E return template; } - /** - * @param tx - * @param type - * @param id - * @return - * @see li.strolch.agent.api.ElementMap#getBy(li.strolch.persistence.api.StrolchTransaction, java.lang.String, - * java.lang.String) - */ @Override public T getBy(StrolchTransaction tx, String type, String id) { T element = this.elementMap.getBy(tx, type, id); @@ -180,35 +141,22 @@ public class AuditingElementMapFacade implements E return element; } - /** - * @param tx - * @param refP - * @return - * @throws StrolchException - * @see li.strolch.agent.api.ElementMap#getBy(li.strolch.persistence.api.StrolchTransaction, - * li.strolch.model.parameter.StringParameter) - */ @Override - public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException { - T element = this.elementMap.getBy(tx, refP); + public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException { + T element = this.elementMap.getBy(tx, refP, assertExists); if (this.observeAccessReads) this.read.add(element); return element; } @Override - public List getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException { - List elements = this.elementMap.getBy(tx, refP); + public List getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists) throws StrolchException { + List elements = this.elementMap.getBy(tx, refP, assertExists); if (this.observeAccessReads) this.read.addAll(elements); return elements; } - /** - * @param tx - * @return - * @see li.strolch.agent.api.ElementMap#getAllElements(li.strolch.persistence.api.StrolchTransaction) - */ @Override public List getAllElements(StrolchTransaction tx) { List elements = this.elementMap.getAllElements(tx); @@ -217,13 +165,6 @@ public class AuditingElementMapFacade implements E return elements; } - /** - * @param tx - * @param type - * @return - * @see li.strolch.agent.api.ElementMap#getElementsBy(li.strolch.persistence.api.StrolchTransaction, - * java.lang.String) - */ @Override public List getElementsBy(StrolchTransaction tx, String type) { List elements = this.elementMap.getElementsBy(tx, type); @@ -232,67 +173,33 @@ public class AuditingElementMapFacade implements E return elements; } - /** - * @param tx - * @return - * @see li.strolch.agent.api.ElementMap#getTypes(li.strolch.persistence.api.StrolchTransaction) - */ @Override public Set getTypes(StrolchTransaction tx) { return this.elementMap.getTypes(tx); } - /** - * @param tx - * @return - * @see li.strolch.agent.api.ElementMap#getAllKeys(li.strolch.persistence.api.StrolchTransaction) - */ @Override public Set getAllKeys(StrolchTransaction tx) { return this.elementMap.getAllKeys(tx); } - /** - * @param tx - * @param type - * @return - * @see li.strolch.agent.api.ElementMap#getKeysBy(li.strolch.persistence.api.StrolchTransaction, java.lang.String) - */ @Override public Set getKeysBy(StrolchTransaction tx, String type) { return this.elementMap.getKeysBy(tx, type); } - /** - * @param tx - * @param element - * @see li.strolch.agent.api.ElementMap#add(li.strolch.persistence.api.StrolchTransaction, - * li.strolch.model.StrolchRootElement) - */ @Override public void add(StrolchTransaction tx, T element) { this.elementMap.add(tx, element); this.created.add(element); } - /** - * @param tx - * @param elements - * @see li.strolch.agent.api.ElementMap#addAll(li.strolch.persistence.api.StrolchTransaction, java.util.List) - */ @Override public void addAll(StrolchTransaction tx, List elements) { this.elementMap.addAll(tx, elements); this.created.addAll(elements); } - /** - * @param tx - * @param element - * @return - * @see li.strolch.agent.api.ElementMap#update(li.strolch.persistence.api.StrolchTransaction, - * li.strolch.model.StrolchRootElement) - */ @Override public T update(StrolchTransaction tx, T element) { T replaced = this.elementMap.update(tx, element); @@ -301,12 +208,6 @@ public class AuditingElementMapFacade implements E } - /** - * @param tx - * @param elements - * @return - * @see li.strolch.agent.api.ElementMap#updateAll(li.strolch.persistence.api.StrolchTransaction, java.util.List) - */ @Override public List updateAll(StrolchTransaction tx, List elements) { List replaced = this.elementMap.updateAll(tx, elements); @@ -314,34 +215,18 @@ public class AuditingElementMapFacade implements E return replaced; } - /** - * @param tx - * @param element - * @see li.strolch.agent.api.ElementMap#remove(li.strolch.persistence.api.StrolchTransaction, - * li.strolch.model.StrolchRootElement) - */ @Override public void remove(StrolchTransaction tx, T element) { this.elementMap.remove(tx, element); this.deleted.add(element); } - /** - * @param tx - * @param elements - * @see li.strolch.agent.api.ElementMap#removeAll(li.strolch.persistence.api.StrolchTransaction, java.util.List) - */ @Override public void removeAll(StrolchTransaction tx, List elements) { this.elementMap.removeAll(tx, elements); this.deleted.addAll(elements); } - /** - * @param tx - * @return - * @see li.strolch.agent.api.ElementMap#removeAll(li.strolch.persistence.api.StrolchTransaction) - */ @Override public long removeAll(StrolchTransaction tx) { long removed = this.elementMap.removeAll(tx); @@ -349,12 +234,6 @@ public class AuditingElementMapFacade implements E return removed; } - /** - * @param tx - * @param type - * @return - * @see li.strolch.agent.api.ElementMap#removeAllBy(li.strolch.persistence.api.StrolchTransaction, java.lang.String) - */ @Override public long removeAllBy(StrolchTransaction tx, String type) { long removed = this.elementMap.removeAllBy(tx, type); diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedElementMap.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedElementMap.java index d6fd1dfc3..2f28bc4b3 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedElementMap.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedElementMap.java @@ -107,15 +107,21 @@ public abstract class CachedElementMap implements protected abstract void assertIsRefParam(Parameter refP); @Override - public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException { + public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException { assertIsRefParam(refP); String type = refP.getUom(); String id = refP.getValue(); - return getBy(tx, type, id); + T element = getBy(tx, type, id); + if (assertExists && element == null) { + String msg = "The element for refP {0} with id {1} does not exist!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, refP.getLocator(), id); + throw new StrolchException(msg); + } + return element; } @Override - public List getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException { + public List getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists) throws StrolchException { assertIsRefParam(refP); List elements = new ArrayList<>(); @@ -124,8 +130,15 @@ public abstract class CachedElementMap implements for (String id : ids) { T element = getBy(tx, type, id); - if (element != null) + if (element != null) { elements.add(element); + } else if (assertExists) { + if (assertExists && element == null) { + String msg = "The element for refP {0} with id {1} does not exist!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, refP.getLocator(), id); + throw new StrolchException(msg); + } + } } return elements; diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalElementMap.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalElementMap.java index 59f52b50a..ef00f1cf2 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalElementMap.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalElementMap.java @@ -1,5 +1,6 @@ package li.strolch.agent.impl; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -56,15 +57,21 @@ public abstract class TransactionalElementMap impl protected abstract void assertIsRefParam(Parameter refP); @Override - public T getBy(StrolchTransaction tx, StringParameter refP) throws StrolchException { + public T getBy(StrolchTransaction tx, StringParameter refP, boolean assertExists) throws StrolchException { assertIsRefParam(refP); String type = refP.getUom(); String id = refP.getValue(); - return getBy(tx, type, id); + T element = getBy(tx, type, id); + if (assertExists && element == null) { + String msg = "The element for refP {0} with id {1} does not exist!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, refP.getLocator(), id); + throw new StrolchException(msg); + } + return element; } @Override - public List getBy(StrolchTransaction tx, StringListParameter refP) throws StrolchException { + public List getBy(StrolchTransaction tx, StringListParameter refP, boolean assertExists) throws StrolchException { assertIsRefParam(refP); List elements = new ArrayList<>(); @@ -73,8 +80,15 @@ public abstract class TransactionalElementMap impl for (String id : ids) { T element = getBy(tx, type, id); - if (element != null) + if (element != null) { elements.add(element); + } else if (assertExists) { + if (assertExists && element == null) { + String msg = "The element for refP {0} with id {1} does not exist!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, refP.getLocator(), id); + throw new StrolchException(msg); + } + } } return elements; diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index 9ec9ae206..ce99a91a4 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -395,17 +395,17 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public Order getOrderBy(StringParameter refP, boolean assertExists) throws StrolchException { - Order order = getOrderMap().getBy(this, refP); - if (assertExists && order == null) { - String msg = "No Order exists with the id {0} with type {1} for refP {2}"; - throw new StrolchException(MessageFormat.format(msg, refP.getValue(), refP.getUom(), refP.getLocator())); - } - return order; + return getOrderMap().getBy(this, refP, assertExists); } @Override public List getOrdersBy(StringListParameter refP) throws StrolchException { - return getOrderMap().getBy(this, refP); + return getOrderMap().getBy(this, refP, false); + } + + @Override + public List getOrdersBy(StringListParameter refP, boolean assertExists) throws StrolchException { + return getOrderMap().getBy(this, refP, assertExists); } @Override @@ -430,17 +430,17 @@ public abstract class AbstractTransaction implements StrolchTransaction { @Override public Resource getResourceBy(StringParameter refP, boolean assertExists) throws StrolchException { - Resource resource = getResourceMap().getBy(this, refP); - if (assertExists && resource == null) { - String msg = "No Resource exists with the id {0} with type {1} for refP {2}"; - throw new StrolchException(MessageFormat.format(msg, refP.getValue(), refP.getUom(), refP.getLocator())); - } - return resource; + return getResourceMap().getBy(this, refP, assertExists); } @Override public List getResourcesBy(StringListParameter refP) throws StrolchException { - return getResourceMap().getBy(this, refP); + return getResourceMap().getBy(this, refP, false); + } + + @Override + public List getResourcesBy(StringListParameter refP, boolean assertExists) throws StrolchException { + return getResourceMap().getBy(this, refP, assertExists); } @Override diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java index 1edd1aa80..0f4743806 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java @@ -580,6 +580,24 @@ public interface StrolchTransaction extends AutoCloseable { */ public List getResourcesBy(StringListParameter 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} + * @param assertExists + * if true, and resource does not exist, then a {@link StrolchException} is thrown + * + * @return the resources referenced by the parameter, or the empty list if they do not exist. Note: Any + * missing resources are not returned! + * + * @throws StrolchException + * if the {@link StringListParameter} is not a properly configured as a reference parameter + */ + public List getResourcesBy(StringListParameter refP, boolean assertExists) throws StrolchException; + /** * Returns the {@link Order} with the given type and id, or null if it does not exist * @@ -657,4 +675,22 @@ public interface StrolchTransaction extends AutoCloseable { * if the {@link StringListParameter} is not a properly configured as a reference parameter */ public List getOrdersBy(StringListParameter 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} + * @param assertExists + * if true, and order does not exist, then a {@link StrolchException} is thrown + * + * @return the orders referenced by the parameter, or the empty list if they do not exist. Note: Any missing + * orders are not returned! + * + * @throws StrolchException + * if the {@link StringListParameter} is not a properly configured as a reference parameter + */ + public List getOrdersBy(StringListParameter refP, boolean assertExists) throws StrolchException; }