[New] Added tx.isUpdated() and tx.isRemoved()
This commit is contained in:
parent
9189cdcda6
commit
47da3334b9
|
@ -590,6 +590,22 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return this.objectFilter != null && this.objectFilter.hasElement(key, locator);
|
||||
}
|
||||
|
||||
private Operation getElementOperation(String key, Locator locator) {
|
||||
if (this.objectFilter == null)
|
||||
return Operation.GET;
|
||||
li.strolch.utils.objectfilter.Operation op = this.objectFilter.getOperation(key, locator);
|
||||
switch (op) {
|
||||
case ADD:
|
||||
return Operation.ADD;
|
||||
case MODIFY:
|
||||
return Operation.UPDATE;
|
||||
case REMOVE:
|
||||
return Operation.REMOVE;
|
||||
default:
|
||||
return Operation.GET;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Resource> streamResources(String... types) {
|
||||
return getResourceMap().stream(this, types).map(e -> {
|
||||
|
@ -1067,6 +1083,36 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
return inFilter || getActivityMap().hasElement(this, type, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdated(Resource resource) {
|
||||
return getElementOperation(Tags.RESOURCE, resource.getLocator()) == Operation.UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdated(Order order) {
|
||||
return getElementOperation(Tags.ORDER, order.getLocator()) == Operation.UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdated(Activity activity) {
|
||||
return getElementOperation(Tags.ACTIVITY, activity.getLocator()) == Operation.UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved(Resource resource) {
|
||||
return getElementOperation(Tags.RESOURCE, resource.getLocator()) == Operation.REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved(Order order) {
|
||||
return getElementOperation(Tags.ORDER, order.getLocator()) == Operation.REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRemoved(Activity activity) {
|
||||
return getElementOperation(Tags.ACTIVITY, activity.getLocator()) == Operation.REMOVE;
|
||||
}
|
||||
|
||||
private ObjectFilter getObjectFilter() {
|
||||
if (this.objectFilter == null)
|
||||
this.objectFilter = new ObjectFilter();
|
||||
|
|
|
@ -19,8 +19,7 @@ public enum Operation {
|
|||
return this.privilegePrefix + element.getObjectType();
|
||||
}
|
||||
|
||||
private Operation(String privilegePrefix) {
|
||||
Operation(String privilegePrefix) {
|
||||
this.privilegePrefix = privilegePrefix;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1433,6 +1433,66 @@ public interface StrolchTransaction extends AutoCloseable {
|
|||
*/
|
||||
boolean hasActivity(String type, String id);
|
||||
|
||||
/**
|
||||
* Returns true if the @{@link Resource} was modified in this TX
|
||||
*
|
||||
* @param resource
|
||||
* the resource to check if modified
|
||||
*
|
||||
* @return true if the @{@link Resource} was modified in this TX
|
||||
*/
|
||||
boolean isUpdated(Resource resource);
|
||||
|
||||
/**
|
||||
* Returns true if the @{@link Order} was modified in this TX
|
||||
*
|
||||
* @param order
|
||||
* the order to check if modified
|
||||
*
|
||||
* @return true if the @{@link Order} was modified in this TX
|
||||
*/
|
||||
boolean isUpdated(Order order);
|
||||
|
||||
/**
|
||||
* Returns true if the @{@link Activity} was modified in this TX
|
||||
*
|
||||
* @param activity
|
||||
* the activity to check if modified
|
||||
*
|
||||
* @return true if the @{@link Activity} was modified in this TX
|
||||
*/
|
||||
boolean isUpdated(Activity activity);
|
||||
|
||||
/**
|
||||
* Returns true if the @{@link Resource} was removed in this TX
|
||||
*
|
||||
* @param resource
|
||||
* the resource to check if removed
|
||||
*
|
||||
* @return true if the @{@link Resource} was removed in this TX
|
||||
*/
|
||||
boolean isRemoved(Resource resource);
|
||||
|
||||
/**
|
||||
* Returns true if the @{@link Order} was removed in this TX
|
||||
*
|
||||
* @param order
|
||||
* the order to check if removed
|
||||
*
|
||||
* @return true if the @{@link Order} was removed in this TX
|
||||
*/
|
||||
boolean isRemoved(Order order);
|
||||
|
||||
/**
|
||||
* Returns true if the @{@link Activity} was removed in this TX
|
||||
*
|
||||
* @param activity
|
||||
* the activity to check if removed
|
||||
*
|
||||
* @return true if the @{@link Activity} was removed in this TX
|
||||
*/
|
||||
boolean isRemoved(Activity activity);
|
||||
|
||||
/**
|
||||
* Add or update and thus persist the given {@link Resource} by calling the relevant {@link Command}
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue