[New] Added StrolchTransaction.addOrUpdate() methods

This commit is contained in:
Robert von Burg 2019-01-23 18:48:11 +01:00
parent 8e0c2e6412
commit a85fa26b5e
2 changed files with 60 additions and 0 deletions

View File

@ -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);

View File

@ -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}
*