From a85fa26b5e19e07693d354626effa74a1fb4a45b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Jan 2019 18:48:11 +0100 Subject: [PATCH] [New] Added StrolchTransaction.addOrUpdate() methods --- .../persistence/api/AbstractTransaction.java | 27 +++++++++++++++ .../persistence/api/StrolchTransaction.java | 33 +++++++++++++++++++ 2 files changed, 60 insertions(+) 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 77eb8cc3d..bc159e4e8 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 @@ -947,6 +947,33 @@ public abstract class AbstractTransaction implements StrolchTransaction { getPrivilegeContext().assertHasAnyRole(roleNames); } + @Override + public void addOrUpdate(Resource resource) throws StrolchModelException { + DBC.PRE.assertNotNull("resource must not be null", resource); + if (hasResource(resource.getType(), resource.getId())) + getObjectFilter().update(Tags.RESOURCE, resource.getLocator(), resource); + else + getObjectFilter().add(Tags.RESOURCE, resource.getLocator(), resource); + } + + @Override + public void addOrUpdate(Order order) throws StrolchModelException { + DBC.PRE.assertNotNull("order must not be null", order); + if (hasOrder(order.getType(), order.getId())) + getObjectFilter().update(Tags.ORDER, order.getLocator(), order); + else + getObjectFilter().add(Tags.ORDER, order.getLocator(), order); + } + + @Override + public void addOrUpdate(Activity activity) throws StrolchModelException { + DBC.PRE.assertNotNull("activity must not be null", activity); + if (hasActivity(activity.getType(), activity.getId())) + getObjectFilter().update(Tags.ACTIVITY, activity.getLocator(), activity); + else + getObjectFilter().add(Tags.ACTIVITY, activity.getLocator(), activity); + } + @Override public void add(Resource resource) throws StrolchModelException { DBC.PRE.assertNotNull("resource must not be null", resource); 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 75f8f47b1..ab0bc0714 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 @@ -1125,6 +1125,39 @@ public interface StrolchTransaction extends AutoCloseable { */ boolean hasActivity(String type, String id); + /** + * Add or update and thus persist the given {@link Resource} by calling the relevant {@link Command} + * + * @param resource + * the resource to add or update + * + * @throws StrolchModelException + * if the resource is null + */ + void addOrUpdate(Resource resource) throws StrolchModelException; + + /** + * Add or update and thus persist the given {@link Order} by calling the relevant {@link Command} + * + * @param order + * the order to add or update + * + * @throws StrolchModelException + * if the order is null + */ + void addOrUpdate(Order order) throws StrolchModelException; + + /** + * Add or update and thus persist the given {@link Activity} by calling the relevant {@link Command} + * + * @param activity + * the activity to add or update + * + * @throws StrolchModelException + * if the resource is null + */ + void addOrUpdate(Activity activity) throws StrolchModelException; + /** * Adds and thus persists the given {@link Resource} by calling the relevant {@link Command} *