[Minor] small log fix when throwing exception on missing elements

This commit is contained in:
Robert von Burg 2018-09-27 15:11:26 +02:00
parent 6fb3099232
commit 62c206bfd0
3 changed files with 24 additions and 9 deletions

View File

@ -185,7 +185,7 @@ public abstract class CachedElementMap<T extends StrolchRootElement> extends Tra
throws StrolchException {
T t = getDbDao(tx).queryBy(type, id, version);
if (assertExists && t == null) {
String msg = "The element with type {0} and id {1} and version {2} does not exist!"; //$NON-NLS-1$
String msg = "The element with type '{0}' and id '{1}' and version '{2}' does not exist!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, type, id, version);
throw new StrolchException(msg);
}

View File

@ -87,7 +87,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
T t = getBy(tx, StrolchConstants.TEMPLATE, type);
if (assertExists && t == null) {
String msg = "The template with type {0} does not exist!"; //$NON-NLS-1$
String msg = "The template with type '{0}' does not exist!"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, type));
}
@ -116,7 +116,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
}
if (assertExists && t == null) {
String msg = "The element with type {0} and id {1} does not exist!"; //$NON-NLS-1$
String msg = "The element with type '{0}' and id '{1}' does not exist!"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, type, id));
}
@ -135,7 +135,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
String id = refP.getValue();
T t = getBy(tx, type, id, false);
if (assertExists && t == null) {
String msg = "The element with type {0} and id {1} does not exist for param {2}"; //$NON-NLS-1$
String msg = "The element with type '{0}' and id '{1}' does not exist for param '{2}'"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator()));
}
return t;
@ -153,7 +153,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
.map(id -> {
T t = getBy(tx, type, id, false);
if (assertExists && t == null) {
String msg = "The element with type {0} and id {1} does not exist for param {2}"; //$NON-NLS-1$
String msg = "The element with type '{0}' and id '{1}' does not exist for param '{2}'"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, type, id, refP.getLocator()));
}
return t;
@ -256,7 +256,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
// assert no object already exists with this id
if (byType.containsKey(element.getId())) {
String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
String msg = "An element already exists with the id '{0}'. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, element.getId());
throw new StrolchPersistenceException(msg);
}
@ -280,7 +280,7 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
// assert no object already exists with this id
if (byType.containsKey(element.getId())) {
String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
String msg = "An element already exists with the id '{0}'. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, element.getId());
throw new StrolchPersistenceException(msg);
}
@ -306,14 +306,14 @@ public abstract class TransientElementMap<T extends StrolchRootElement> implemen
private void internalUpdate(StrolchTransaction tx, T element) {
Map<String, T> byType = this.elementMap.get(element.getType());
if (byType == null) {
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
String msg = "The element does not yet exist with the type '{0}' and id '{1}'. Use add() for new objects!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, element.getType(), element.getId());
throw new StrolchPersistenceException(msg);
}
// assert no object already exists with this id
if (!byType.containsKey(element.getId())) {
String msg = "The element does not yet exist with the type {0} and id {1}. Use add() for new objects!"; //$NON-NLS-1$
String msg = "The element does not yet exist with the type '{0}' and id '{1}'. Use add() for new objects!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, element.getType(), element.getId());
throw new StrolchPersistenceException(msg);
}

View File

@ -613,6 +613,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
DBC.PRE.assertNotNull("refP", refP);
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ORDER_REF, refP);
if (assertExists && refP.isEmpty()) {
String msg = "The Order with type '{0}' and id '{1}' does not exist for param '{2}'"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getUom(), refP.getValue(), refP.getLocator()));
}
Order element = getElementFromFilter(Tags.ORDER, Order.locatorFor(refP.getUom(), refP.getValue()));
if (element != null)
return element;
@ -684,6 +689,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
DBC.PRE.assertNotNull("refP", refP);
ElementMapHelpers.assertIsRefParam(INTERPRETATION_RESOURCE_REF, refP);
if (assertExists && refP.isEmpty()) {
String msg = "The Resource with type '{0}' and id '{1}' does not exist for param '{2}'"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getUom(), refP.getValue(), refP.getLocator()));
}
Resource element = getElementFromFilter(Tags.RESOURCE, Resource.locatorFor(refP.getUom(), refP.getValue()));
if (element != null)
return element;
@ -767,6 +777,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
DBC.PRE.assertNotNull("refP", refP);
ElementMapHelpers.assertIsRefParam(INTERPRETATION_ACTIVITY_REF, refP);
if (assertExists && refP.isEmpty()) {
String msg = "The Activity with type '{0}' and id '{1}' does not exist for param '{2}'"; //$NON-NLS-1$
throw new StrolchException(MessageFormat.format(msg, refP.getUom(), refP.getValue(), refP.getLocator()));
}
Activity element = getElementFromFilter(Tags.ACTIVITY, Activity.locatorFor(refP.getUom(), refP.getValue()));
if (element != null)
return element;