From c0cc6f57cb8bd0c155ddc153e65e7e20112ec4b4 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Jul 2017 13:51:17 +0200 Subject: [PATCH] [Major] Added add, update and remove methods to TX for elements Moved add, update and remove commands to agent package --- .../li/strolch/agent/impl/EmptyRealm.java | 6 +- .../li/strolch/agent/impl/TransientRealm.java | 6 +- .../persistence/api/AbstractTransaction.java | 196 +++++++++- .../persistence/api}/AddActivityCommand.java | 3 +- .../persistence/api}/AddOrderCommand.java | 3 +- .../persistence/api}/AddResourceCommand.java | 3 +- .../api}/RemoveActivityCommand.java | 3 +- .../persistence/api}/RemoveOrderCommand.java | 3 +- .../api}/RemoveResourceCommand.java | 3 +- .../persistence/api/StrolchTransaction.java | 108 ++++++ .../api}/UpdateActivityCommand.java | 3 +- .../persistence/api}/UpdateOrderCommand.java | 3 +- .../api}/UpdateResourceCommand.java | 3 +- .../inmemory/InMemoryPersistence.java | 14 +- .../inmemory/InMemoryTransaction.java | 9 +- .../inmemory/InMemoryPersistenceHandler.java | 2 +- .../performance/PerformanceTestService.java | 4 +- .../PostgreSqlPersistenceHandler.java | 6 +- .../PostgreSqlStrolchTransaction.java | 7 +- .../execution/command/ExecutionCommand.java | 4 +- .../execution/policy/ExecutionPolicy.java | 2 +- .../policy/RemoveActivityArchival.java | 2 +- .../execution/policy/ReservationExection.java | 2 +- .../java/li/strolch/migrations/Migration.java | 2 +- .../strolch/service/AddActivityService.java | 2 +- .../service/AddOrUpdateResourceService.java | 4 +- .../li/strolch/service/AddOrderService.java | 2 +- .../strolch/service/AddResourceService.java | 2 +- .../service/RemoveActivityService.java | 2 +- .../strolch/service/RemoveOrderService.java | 2 +- .../service/RemoveResourceService.java | 2 +- .../service/UpdateActivityService.java | 2 +- .../strolch/service/UpdateOrderService.java | 2 +- .../service/UpdateResourceService.java | 2 +- .../strolch/command/AddOrderCommandTest.java | 1 + .../command/AddResourceCommandTest.java | 1 + .../command/InMemoryTransactionTest.java | 351 ++++++++++++++++++ .../command/RemoveOrderCommandTest.java | 1 + .../command/RemoveResourceCommandTest.java | 1 + .../command/UpdateOrderCommandTest.java | 1 + .../command/UpdateResourceCommandTest.java | 1 + .../li/strolch/migrations/MigrationsTest.java | 4 +- .../java/li/strolch/service/FlushTxTest.java | 6 +- .../test/java/li/strolch/service/TxTest.java | 2 +- 44 files changed, 704 insertions(+), 84 deletions(-) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/AddActivityCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/AddOrderCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/AddResourceCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/RemoveActivityCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/RemoveOrderCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/RemoveResourceCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/UpdateActivityCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/UpdateOrderCommand.java (96%) rename {li.strolch.service/src/main/java/li/strolch/command => li.strolch.agent/src/main/java/li/strolch/persistence/api}/UpdateResourceCommand.java (96%) create mode 100644 li.strolch.service/src/test/java/li/strolch/command/InMemoryTransactionTest.java diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/EmptyRealm.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/EmptyRealm.java index 25d02f002..1a073f2e5 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/EmptyRealm.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/EmptyRealm.java @@ -22,7 +22,6 @@ import li.strolch.agent.api.AuditTrail; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.OrderMap; import li.strolch.agent.api.ResourceMap; -import li.strolch.handler.operationslog.OperationsLog; import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.inmemory.InMemoryPersistence; @@ -86,10 +85,7 @@ public class EmptyRealm extends InternalStrolchRealm { @Override public void initialize(ComponentContainer container, ComponentConfiguration configuration) { super.initialize(container, configuration); - OperationsLog operationsLog = container.hasComponent(OperationsLog.class) - ? container.getComponent(OperationsLog.class) : null; - this.persistenceHandler = new InMemoryPersistence(operationsLog, container.getPrivilegeHandler(), - isVersioningEnabled()); + this.persistenceHandler = new InMemoryPersistence(container, isVersioningEnabled()); this.resourceMap = new TransactionalResourceMap(this); this.orderMap = new TransactionalOrderMap(this); this.activityMap = new TransactionalActivityMap(this); diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientRealm.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientRealm.java index 61d9b154b..a0d2276ef 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientRealm.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransientRealm.java @@ -23,7 +23,6 @@ import li.strolch.agent.api.AuditTrail; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.OrderMap; import li.strolch.agent.api.ResourceMap; -import li.strolch.handler.operationslog.OperationsLog; import li.strolch.model.ModelStatistics; import li.strolch.model.xml.XmlModelSaxFileReader; import li.strolch.persistence.api.PersistenceHandler; @@ -104,10 +103,7 @@ public class TransientRealm extends InternalStrolchRealm { this.modelFile = configuration.getDataFile(key, null, configuration.getRuntimeConfiguration(), true); - OperationsLog operationsLog = container.hasComponent(OperationsLog.class) - ? container.getComponent(OperationsLog.class) : null; - this.persistenceHandler = new InMemoryPersistence(operationsLog, container.getPrivilegeHandler(), - isVersioningEnabled()); + this.persistenceHandler = new InMemoryPersistence(container, isVersioningEnabled()); this.resourceMap = new TransactionalResourceMap(this); this.orderMap = new TransactionalOrderMap(this); this.activityMap = new TransactionalActivityMap(this); 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 f87f25dd6..4ebf45c48 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 @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import li.strolch.agent.api.ActivityMap; import li.strolch.agent.api.AuditTrail; +import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.ObserverEvent; import li.strolch.agent.api.ObserverHandler; import li.strolch.agent.api.OrderMap; @@ -46,6 +47,7 @@ import li.strolch.agent.impl.AuditingResourceMap; import li.strolch.agent.impl.InternalStrolchRealm; import li.strolch.exception.StrolchAccessDeniedException; import li.strolch.exception.StrolchException; +import li.strolch.exception.StrolchModelException; import li.strolch.handler.operationslog.LogMessage; import li.strolch.handler.operationslog.LogSeverity; import li.strolch.handler.operationslog.OperationsLog; @@ -80,6 +82,7 @@ import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; import li.strolch.utils.helper.ExceptionHelper; import li.strolch.utils.helper.StringHelper; +import li.strolch.utils.objectfilter.ObjectFilter; /** * @author Robert von Burg @@ -87,8 +90,15 @@ import li.strolch.utils.helper.StringHelper; public abstract class AbstractTransaction implements StrolchTransaction { protected static final Logger logger = LoggerFactory.getLogger(AbstractTransaction.class); + + private ComponentContainer container; + private PrivilegeHandler privilegeHandler; + private OperationsLog operationsLog; + private InternalStrolchRealm realm; + private ObjectFilter objectFilter; + private TransactionCloseStrategy closeStrategy; private boolean suppressUpdates; private boolean suppressAudits; @@ -107,18 +117,18 @@ public abstract class AbstractTransaction implements StrolchTransaction { private String action; private Certificate certificate; - private PrivilegeHandler privilegeHandler; - private OperationsLog operationsLog; - public AbstractTransaction(OperationsLog operationsLog, PrivilegeHandler privilegeHandler, StrolchRealm realm, - Certificate certificate, String action) { - DBC.PRE.assertNotNull("privilegeHandler must be set!", privilegeHandler); //$NON-NLS-1$ + public AbstractTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate, + String action) { + DBC.PRE.assertNotNull("container must be set!", container); //$NON-NLS-1$ DBC.PRE.assertNotNull("realm must be set!", realm); //$NON-NLS-1$ DBC.PRE.assertNotNull("certificate must be set!", certificate); //$NON-NLS-1$ DBC.PRE.assertNotNull("action must be set!", action); //$NON-NLS-1$ - this.privilegeHandler = privilegeHandler; - this.operationsLog = operationsLog; + this.container = container; + this.privilegeHandler = container.getPrivilegeHandler(); + if (container.hasComponent(OperationsLog.class)) + this.operationsLog = container.getComponent(OperationsLog.class); this.realm = (InternalStrolchRealm) realm; this.action = action; this.certificate = certificate; @@ -336,6 +346,11 @@ public abstract class AbstractTransaction implements StrolchTransaction { return this.auditTrail; } + @Override + public ComponentContainer getContainer() { + return this.container; + } + private void assertQueryAllowed(StrolchQuery query) { try { PrivilegeContext privilegeContext = this.privilegeHandler.getPrivilegeContext(this.certificate); @@ -634,9 +649,175 @@ public abstract class AbstractTransaction implements StrolchTransaction { return getActivityMap().getBy(this, refP, assertExists); } + private ObjectFilter getObjectFilter() { + if (this.objectFilter == null) + this.objectFilter = new ObjectFilter(); + return this.objectFilter; + } + + @Override + public void addResource(Resource resource) throws StrolchModelException { + DBC.PRE.assertNotNull("resource must not be null", resource); + DBC.PRE.assertFalse("resource already exists with id " + resource.getId(), + getResourceMap().hasElement(this, resource.getType(), resource.getId())); + getObjectFilter().add(Tags.RESOURCE, resource); + } + + @Override + public void addOrder(Order order) throws StrolchException { + DBC.PRE.assertNotNull("order must not be null", order); + DBC.PRE.assertFalse("order already exists with id " + order.getId(), + getOrderMap().hasElement(this, order.getType(), order.getId())); + getObjectFilter().add(Tags.ORDER, order); + } + + @Override + public void addActivity(Activity activity) throws StrolchException { + DBC.PRE.assertNotNull("activity must not be null", activity); + DBC.PRE.assertFalse("activity already exists with id " + activity.getId(), + getActivityMap().hasElement(this, activity.getType(), activity.getId())); + getObjectFilter().add(Tags.ACTIVITY, activity); + } + + @Override + public void updateResource(Resource resource) throws StrolchException { + DBC.PRE.assertNotNull("resource must not be null", resource); + getObjectFilter().update(Tags.RESOURCE, resource); + } + + @Override + public void updateOrder(Order order) { + DBC.PRE.assertNotNull("order must not be null", order); + getObjectFilter().update(Tags.ORDER, order); + } + + @Override + public void updateActivity(Activity activity) throws StrolchException { + DBC.PRE.assertNotNull("activity must not be null", activity); + getObjectFilter().update(Tags.ACTIVITY, activity); + } + + @Override + public void removeResource(Resource resource) throws StrolchException { + DBC.PRE.assertNotNull("resource must not be null", resource); + getObjectFilter().remove(Tags.RESOURCE, resource); + } + + @Override + public void removeOrder(Order order) throws StrolchException { + DBC.PRE.assertNotNull("order must not be null", order); + getObjectFilter().remove(Tags.ORDER, order); + } + + @Override + public void removeActivity(Activity activity) throws StrolchException { + DBC.PRE.assertNotNull("activity must not be null", activity); + getObjectFilter().remove(Tags.ACTIVITY, activity); + } + + private void addModelChangeCommands() { + if (this.objectFilter == null) + return; + + List removed; + List updated; + List added; + + /* + * Resources + */ + removed = this.objectFilter.getRemoved(Tags.RESOURCE); + if (!removed.isEmpty()) { + for (Object obj : removed) { + RemoveResourceCommand cmd = new RemoveResourceCommand(getContainer(), this); + cmd.setResource((Resource) obj); + addCommand(cmd); + } + } + + updated = this.objectFilter.getUpdated(Tags.RESOURCE); + if (!updated.isEmpty()) { + for (Object obj : updated) { + UpdateResourceCommand cmd = new UpdateResourceCommand(getContainer(), this); + cmd.setResource((Resource) obj); + addCommand(cmd); + } + } + + added = this.objectFilter.getAdded(Tags.RESOURCE); + if (!added.isEmpty()) { + for (Object obj : added) { + AddResourceCommand cmd = new AddResourceCommand(getContainer(), this); + cmd.setResource((Resource) obj); + addCommand(cmd); + } + } + + /* + * Orders + */ + removed = this.objectFilter.getRemoved(Tags.ORDER); + if (!removed.isEmpty()) { + for (Object obj : removed) { + RemoveOrderCommand cmd = new RemoveOrderCommand(getContainer(), this); + cmd.setOrder((Order) obj); + addCommand(cmd); + } + } + + updated = this.objectFilter.getUpdated(Tags.ORDER); + if (!updated.isEmpty()) { + for (Object obj : updated) { + UpdateOrderCommand cmd = new UpdateOrderCommand(getContainer(), this); + cmd.setOrder((Order) obj); + addCommand(cmd); + } + } + + added = this.objectFilter.getAdded(Tags.ORDER); + if (!added.isEmpty()) { + for (Object obj : added) { + AddOrderCommand cmd = new AddOrderCommand(getContainer(), this); + cmd.setOrder((Order) obj); + addCommand(cmd); + } + } + + /* + * Activities + */ + removed = this.objectFilter.getRemoved(Tags.ACTIVITY); + if (!removed.isEmpty()) { + for (Object obj : removed) { + RemoveActivityCommand cmd = new RemoveActivityCommand(getContainer(), this); + cmd.setActivity((Activity) obj); + addCommand(cmd); + } + } + + updated = this.objectFilter.getUpdated(Tags.ACTIVITY); + if (!updated.isEmpty()) { + for (Object obj : updated) { + UpdateActivityCommand cmd = new UpdateActivityCommand(getContainer(), this); + cmd.setActivity((Activity) obj); + addCommand(cmd); + } + } + + added = this.objectFilter.getAdded(Tags.ACTIVITY); + if (!added.isEmpty()) { + for (Object obj : added) { + AddActivityCommand cmd = new AddActivityCommand(getContainer(), this); + cmd.setActivity((Activity) obj); + addCommand(cmd); + } + } + } + @Override public void flush() { try { + addModelChangeCommands(); validateCommands(); doCommands(); writeChanges(); @@ -656,6 +837,7 @@ public abstract class AbstractTransaction implements StrolchTransaction { try { this.txResult.setState(TransactionState.COMMITTING); + addModelChangeCommands(); validateCommands(); doCommands(); writeChanges(); diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddActivityCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AddActivityCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/AddActivityCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/AddActivityCommand.java index f5744434d..51dcc86f8 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/AddActivityCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AddActivityCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ActivityMap; import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.activity.Activity; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AddOrderCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/AddOrderCommand.java index a35afea79..35e0ab75d 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/AddOrderCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AddOrderCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.OrderMap; import li.strolch.exception.StrolchException; import li.strolch.model.Order; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AddResourceCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/AddResourceCommand.java index 822d0bac8..48f5a1921 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/AddResourceCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AddResourceCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.ResourceMap; import li.strolch.exception.StrolchException; import li.strolch.model.Resource; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveActivityCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveActivityCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/RemoveActivityCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveActivityCommand.java index ff6ccf79c..6d6de25fb 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/RemoveActivityCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveActivityCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ActivityMap; import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.activity.Activity; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveOrderCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveOrderCommand.java index 304f7267b..32eaf5bad 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/RemoveOrderCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveOrderCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.OrderMap; import li.strolch.exception.StrolchException; import li.strolch.model.Order; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveResourceCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveResourceCommand.java index abcbefa43..16eea7528 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/RemoveResourceCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/RemoveResourceCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.ResourceMap; import li.strolch.exception.StrolchException; import li.strolch.model.Resource; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; 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 d1253fd51..d72a5da76 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 @@ -19,6 +19,7 @@ import java.util.List; import li.strolch.agent.api.ActivityMap; import li.strolch.agent.api.AuditTrail; +import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.OrderMap; import li.strolch.agent.api.ResourceMap; import li.strolch.agent.api.StrolchComponent; @@ -26,6 +27,7 @@ import li.strolch.agent.api.StrolchLockException; import li.strolch.agent.api.StrolchRealm; import li.strolch.agent.impl.DataStoreMode; import li.strolch.exception.StrolchException; +import li.strolch.exception.StrolchModelException; import li.strolch.model.Locator; import li.strolch.model.Order; import li.strolch.model.ParameterBag; @@ -143,6 +145,13 @@ public interface StrolchTransaction extends AutoCloseable { */ public PersistenceHandler getPersistenceHandler(); + /** + * Return the {@link ComponentContainer} + * + * @return the reference to the container + */ + public ComponentContainer getContainer(); + /** * Returns the currently set {@link TransactionCloseStrategy} * @@ -948,4 +957,103 @@ public interface StrolchTransaction extends AutoCloseable { * if the {@link StringListParameter} is not a properly configured as a reference parameter */ public List getOrdersBy(StringListParameter refP, boolean assertExists) throws StrolchException; + + /** + * Adds and thus persists the given {@link Resource} by calling the relevant {@link Command} + * + * @param resource + * the resource to add + * + * @throws StrolchModelException + * if the resource is null, or a resource with the given ID already exists + */ + public void addResource(Resource resource) throws StrolchModelException; + + /** + * Adds and thus persists the given {@link Order} by calling the relevant {@link Command} + * + * @param order + * the order to add + * + * @throws StrolchModelException + * if the order is null, or an order with the given ID already exists + */ + public void addOrder(Order order) throws StrolchException; + + /** + * Adds and thus persists the given {@link Activity} by calling the relevant {@link Command} + * + * @param activity + * the activity to add + * + * @throws StrolchModelException + * if the activity is null, or an activity with the given ID already exists + */ + public void addActivity(Activity activity) throws StrolchException; + + /** + * Updates the given {@link Resource} by calling the relevant {@link Command} + * + * @param resource + * the resource to update + * + * @throws StrolchModelException + * if the resource is null + */ + public void updateResource(Resource resource) throws StrolchException; + + /** + * Updates the given {@link Order} by calling the relevant {@link Command} + * + * @param order + * the order to update + * + * @throws StrolchModelException + * if the order is null + */ + public void updateOrder(Order order); + + /** + * Updates the given {@link Activity} by calling the relevant {@link Command} + * + * @param activity + * the activity to update + * + * @throws StrolchModelException + * if the activity is null + */ + public void updateActivity(Activity activity) throws StrolchException; + + /** + * Removes the given {@link Resource} by calling the relevant {@link Command} + * + * @param resource + * the resource to remove + * + * @throws StrolchModelException + * if the resource is null + */ + public void removeResource(Resource resource) throws StrolchException; + + /** + * Removes the given {@link Order} by calling the relevant {@link Command} + * + * @param order + * the order to remove + * + * @throws StrolchModelException + * if the order is null + */ + public void removeOrder(Order order) throws StrolchException; + + /** + * Removes the given {@link Activity} by calling the relevant {@link Command} + * + * @param activity + * the activity to remove + * + * @throws StrolchModelException + * if the activity is null + */ + public void removeActivity(Activity activity) throws StrolchException; } diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateActivityCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateActivityCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/UpdateActivityCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateActivityCommand.java index 7600dce5f..e433d68a6 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/UpdateActivityCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateActivityCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ActivityMap; import li.strolch.agent.api.ComponentContainer; import li.strolch.exception.StrolchException; import li.strolch.model.activity.Activity; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateOrderCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateOrderCommand.java index 21ea838f1..fa05d5329 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/UpdateOrderCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateOrderCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.OrderMap; import li.strolch.exception.StrolchException; import li.strolch.model.Order; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateResourceCommand.java similarity index 96% rename from li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java rename to li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateResourceCommand.java index 49f6338aa..98106d9f1 100644 --- a/li.strolch.service/src/main/java/li/strolch/command/UpdateResourceCommand.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/UpdateResourceCommand.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.command; +package li.strolch.persistence.api; import java.text.MessageFormat; @@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.ResourceMap; import li.strolch.exception.StrolchException; import li.strolch.model.Resource; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; import li.strolch.utils.dbc.DBC; diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryPersistence.java b/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryPersistence.java index 7b34b4f0c..9dae75430 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryPersistence.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryPersistence.java @@ -18,8 +18,8 @@ package li.strolch.persistence.inmemory; import java.util.HashMap; import java.util.Map; +import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchRealm; -import li.strolch.handler.operationslog.OperationsLog; import li.strolch.persistence.api.ActivityDao; import li.strolch.persistence.api.AuditDao; import li.strolch.persistence.api.OrderDao; @@ -27,26 +27,22 @@ import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.privilege.model.Certificate; -import li.strolch.runtime.privilege.PrivilegeHandler; public class InMemoryPersistence implements PersistenceHandler { private boolean versioningEnabled; private Map daoCache; - private PrivilegeHandler privilegeHandler; - private OperationsLog operationsLog; + private ComponentContainer container; - public InMemoryPersistence(OperationsLog operationsLog, PrivilegeHandler privilegeHandler, - boolean versioningEnabled) { - this.operationsLog = operationsLog; - this.privilegeHandler = privilegeHandler; + public InMemoryPersistence(ComponentContainer container, boolean versioningEnabled) { + this.container = container; this.versioningEnabled = versioningEnabled; this.daoCache = new HashMap<>(); } @Override public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) { - return new InMemoryTransaction(this.operationsLog, this.privilegeHandler, realm, certificate, action, this); + return new InMemoryTransaction(this.container, realm, certificate, action, this); } @Override diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryTransaction.java index 53bceb45e..70bea203d 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/inmemory/InMemoryTransaction.java @@ -15,21 +15,20 @@ */ package li.strolch.persistence.inmemory; +import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchRealm; -import li.strolch.handler.operationslog.OperationsLog; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.TransactionState; import li.strolch.privilege.model.Certificate; -import li.strolch.runtime.privilege.PrivilegeHandler; public class InMemoryTransaction extends AbstractTransaction { private InMemoryPersistence persistenceHandler; - public InMemoryTransaction(OperationsLog operationsLog, PrivilegeHandler privilegeHandler, StrolchRealm realm, - Certificate certificate, String action, InMemoryPersistence persistenceHandler) { - super(operationsLog, privilegeHandler, realm, certificate, action); + public InMemoryTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate, String action, + InMemoryPersistence persistenceHandler) { + super(container, realm, certificate, action); this.persistenceHandler = persistenceHandler; } diff --git a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryPersistenceHandler.java b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryPersistenceHandler.java index 774f1d9bd..6fbecf5db 100644 --- a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryPersistenceHandler.java +++ b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/InMemoryPersistenceHandler.java @@ -45,7 +45,7 @@ public class InMemoryPersistenceHandler extends StrolchComponent implements Pers @Override public void initialize(ComponentConfiguration configuration) throws Exception { - this.persistence = new InMemoryPersistence(null, getContainer().getPrivilegeHandler(), false); + this.persistence = new InMemoryPersistence(getContainer(), false); super.initialize(configuration); } diff --git a/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformanceTestService.java b/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformanceTestService.java index aa8c5738c..fae384a9a 100644 --- a/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformanceTestService.java +++ b/li.strolch.performancetest/src/test/java/li/strolch/performance/PerformanceTestService.java @@ -18,10 +18,10 @@ package li.strolch.performance; import java.util.concurrent.TimeUnit; import li.strolch.agent.api.StrolchAgent; -import li.strolch.command.AddResourceCommand; -import li.strolch.command.RemoveResourceCommand; import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; +import li.strolch.persistence.api.AddResourceCommand; +import li.strolch.persistence.api.RemoveResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceResult; diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlPersistenceHandler.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlPersistenceHandler.java index 860b78971..bffe96bbb 100644 --- a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlPersistenceHandler.java +++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlPersistenceHandler.java @@ -35,7 +35,6 @@ import li.strolch.agent.api.StrolchComponent; import li.strolch.agent.api.StrolchRealm; import li.strolch.db.DbMigrationState; import li.strolch.db.DbSchemaVersionCheck; -import li.strolch.handler.operationslog.OperationsLog; import li.strolch.persistence.api.ActivityDao; import li.strolch.persistence.api.AuditDao; import li.strolch.persistence.api.OrderDao; @@ -131,10 +130,7 @@ public class PostgreSqlPersistenceHandler extends StrolchComponent implements Pe @Override public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) { - OperationsLog operationsLog = getContainer().hasComponent(OperationsLog.class) - ? getContainer().getComponent(OperationsLog.class) : null; - return new PostgreSqlStrolchTransaction(operationsLog, getContainer().getPrivilegeHandler(), realm, certificate, - action, this); + return new PostgreSqlStrolchTransaction(getContainer(), realm, certificate, action, this); } Connection getConnection(String realm) { diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlStrolchTransaction.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlStrolchTransaction.java index 3c86519cf..bbd5ed4f8 100644 --- a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlStrolchTransaction.java +++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlStrolchTransaction.java @@ -20,8 +20,8 @@ import java.sql.Connection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchRealm; -import li.strolch.handler.operationslog.OperationsLog; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.ActivityDao; import li.strolch.persistence.api.AuditDao; @@ -29,7 +29,6 @@ import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.ResourceDao; import li.strolch.privilege.model.Certificate; -import li.strolch.runtime.privilege.PrivilegeHandler; public class PostgreSqlStrolchTransaction extends AbstractTransaction { @@ -42,10 +41,10 @@ public class PostgreSqlStrolchTransaction extends AbstractTransaction { private AuditDao auditDao; private Connection connection; - public PostgreSqlStrolchTransaction(OperationsLog operationsLog, PrivilegeHandler privilegeHandler, + public PostgreSqlStrolchTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate, String action, PostgreSqlPersistenceHandler persistenceHandler) { - super(operationsLog, privilegeHandler, realm, certificate, action); + super(container, realm, certificate, action); this.persistenceHandler = persistenceHandler; } diff --git a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java index 348953172..d48925ec3 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/command/ExecutionCommand.java @@ -6,8 +6,6 @@ import java.util.Iterator; import java.util.Map.Entry; import li.strolch.agent.api.ComponentContainer; -import li.strolch.command.UpdateActivityCommand; -import li.strolch.command.UpdateOrderCommand; import li.strolch.exception.StrolchException; import li.strolch.execution.policy.ConfirmationPolicy; import li.strolch.execution.policy.ExecutionPolicy; @@ -21,6 +19,8 @@ import li.strolch.model.activity.TimeOrderingVisitor; import li.strolch.model.policy.PolicyDef; import li.strolch.model.visitor.IActivityElementVisitor; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateActivityCommand; +import li.strolch.persistence.api.UpdateOrderCommand; import li.strolch.policy.PolicyHandler; import li.strolch.service.api.Command; import li.strolch.utils.helper.StringHelper; diff --git a/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java b/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java index e53cc9e05..bdbfed95f 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/policy/ExecutionPolicy.java @@ -2,7 +2,6 @@ package li.strolch.execution.policy; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchRealm; -import li.strolch.command.UpdateActivityCommand; import li.strolch.exception.StrolchException; import li.strolch.execution.DelayedExecutionTimer; import li.strolch.execution.ExecutionHandler; @@ -10,6 +9,7 @@ import li.strolch.model.State; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateActivityCommand; import li.strolch.policy.StrolchPolicy; import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.model.Certificate; diff --git a/li.strolch.service/src/main/java/li/strolch/execution/policy/RemoveActivityArchival.java b/li.strolch.service/src/main/java/li/strolch/execution/policy/RemoveActivityArchival.java index 67972a281..678c1f2f2 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/policy/RemoveActivityArchival.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/policy/RemoveActivityArchival.java @@ -1,8 +1,8 @@ package li.strolch.execution.policy; import li.strolch.agent.api.ComponentContainer; -import li.strolch.command.RemoveActivityCommand; import li.strolch.model.activity.Activity; +import li.strolch.persistence.api.RemoveActivityCommand; import li.strolch.persistence.api.StrolchTransaction; public class RemoveActivityArchival extends ActivityArchivalPolicy { diff --git a/li.strolch.service/src/main/java/li/strolch/execution/policy/ReservationExection.java b/li.strolch.service/src/main/java/li/strolch/execution/policy/ReservationExection.java index 641b4108f..253d6e3b1 100644 --- a/li.strolch.service/src/main/java/li/strolch/execution/policy/ReservationExection.java +++ b/li.strolch.service/src/main/java/li/strolch/execution/policy/ReservationExection.java @@ -1,7 +1,6 @@ package li.strolch.execution.policy; import li.strolch.agent.api.ComponentContainer; -import li.strolch.command.UpdateResourceCommand; import li.strolch.exception.StrolchModelException; import li.strolch.model.Locator; import li.strolch.model.Resource; @@ -9,6 +8,7 @@ import li.strolch.model.State; import li.strolch.model.activity.Action; import li.strolch.model.parameter.BooleanParameter; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateResourceCommand; /** *

diff --git a/li.strolch.service/src/main/java/li/strolch/migrations/Migration.java b/li.strolch.service/src/main/java/li/strolch/migrations/Migration.java index ec3342383..b20feb640 100644 --- a/li.strolch.service/src/main/java/li/strolch/migrations/Migration.java +++ b/li.strolch.service/src/main/java/li/strolch/migrations/Migration.java @@ -18,11 +18,11 @@ package li.strolch.migrations; import java.io.File; import li.strolch.agent.api.ComponentContainer; -import li.strolch.command.AddResourceCommand; import li.strolch.command.parameter.SetParameterCommand; import li.strolch.model.ParameterBag; import li.strolch.model.Resource; import li.strolch.model.parameter.StringParameter; +import li.strolch.persistence.api.AddResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.privilege.model.Certificate; import li.strolch.utils.Version; diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddActivityService.java b/li.strolch.service/src/main/java/li/strolch/service/AddActivityService.java index 010eb837a..b1b0678f3 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/AddActivityService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/AddActivityService.java @@ -15,8 +15,8 @@ */ package li.strolch.service; -import li.strolch.command.AddActivityCommand; import li.strolch.model.activity.Activity; +import li.strolch.persistence.api.AddActivityCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.AddActivityService.AddActivityArg; import li.strolch.service.api.AbstractService; diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddOrUpdateResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrUpdateResourceService.java index f28dd3351..84228db23 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/AddOrUpdateResourceService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/AddOrUpdateResourceService.java @@ -15,10 +15,10 @@ */ package li.strolch.service; -import li.strolch.command.AddResourceCommand; -import li.strolch.command.UpdateResourceCommand; import li.strolch.model.Resource; +import li.strolch.persistence.api.AddResourceCommand; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateResourceCommand; import li.strolch.service.AddOrUpdateResourceService.AddOrUpdateResourceArg; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java index 945778337..909b65d10 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/AddOrderService.java @@ -15,8 +15,8 @@ */ package li.strolch.service; -import li.strolch.command.AddOrderCommand; import li.strolch.model.Order; +import li.strolch.persistence.api.AddOrderCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.AddOrderService.AddOrderArg; import li.strolch.service.api.AbstractService; diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java index bab7154c0..bbd9da563 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/AddResourceService.java @@ -15,8 +15,8 @@ */ package li.strolch.service; -import li.strolch.command.AddResourceCommand; import li.strolch.model.Resource; +import li.strolch.persistence.api.AddResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.AddResourceService.AddResourceArg; import li.strolch.service.api.AbstractService; diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveActivityService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveActivityService.java index fd70f15c5..bcb72523f 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/RemoveActivityService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveActivityService.java @@ -15,8 +15,8 @@ */ package li.strolch.service; -import li.strolch.command.RemoveActivityCommand; import li.strolch.model.activity.Activity; +import li.strolch.persistence.api.RemoveActivityCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceResult; diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java index e182fd573..c1d03a281 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveOrderService.java @@ -15,8 +15,8 @@ */ package li.strolch.service; -import li.strolch.command.RemoveOrderCommand; import li.strolch.model.Order; +import li.strolch.persistence.api.RemoveOrderCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceResult; diff --git a/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java index 2564ec410..d86232940 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/RemoveResourceService.java @@ -15,8 +15,8 @@ */ package li.strolch.service; -import li.strolch.command.RemoveResourceCommand; import li.strolch.model.Resource; +import li.strolch.persistence.api.RemoveResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceResult; diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateActivityService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateActivityService.java index 71d04f436..0574ecb73 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/UpdateActivityService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateActivityService.java @@ -15,9 +15,9 @@ */ package li.strolch.service; -import li.strolch.command.UpdateActivityCommand; import li.strolch.model.activity.Activity; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateActivityCommand; import li.strolch.service.UpdateActivityService.UpdateActivityArg; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java index 005406168..f31e2f470 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateOrderService.java @@ -15,9 +15,9 @@ */ package li.strolch.service; -import li.strolch.command.UpdateOrderCommand; import li.strolch.model.Order; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateOrderCommand; import li.strolch.service.UpdateOrderService.UpdateOrderArg; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; diff --git a/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java index a03d6f2a6..8ad2c622a 100644 --- a/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java +++ b/li.strolch.service/src/main/java/li/strolch/service/UpdateResourceService.java @@ -15,9 +15,9 @@ */ package li.strolch.service; -import li.strolch.command.UpdateResourceCommand; import li.strolch.model.Resource; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateResourceCommand; import li.strolch.service.UpdateResourceService.UpdateResourceArg; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; diff --git a/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java index a17e15813..141c276c9 100644 --- a/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java +++ b/li.strolch.service/src/test/java/li/strolch/command/AddOrderCommandTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import li.strolch.agent.api.ComponentContainer; import li.strolch.model.ModelGenerator; import li.strolch.model.Order; +import li.strolch.persistence.api.AddOrderCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; diff --git a/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java index 5c799289b..60cc6cfe3 100644 --- a/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java +++ b/li.strolch.service/src/test/java/li/strolch/command/AddResourceCommandTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import li.strolch.agent.api.ComponentContainer; import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; +import li.strolch.persistence.api.AddResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; diff --git a/li.strolch.service/src/test/java/li/strolch/command/InMemoryTransactionTest.java b/li.strolch.service/src/test/java/li/strolch/command/InMemoryTransactionTest.java new file mode 100644 index 000000000..e1f28dc05 --- /dev/null +++ b/li.strolch.service/src/test/java/li/strolch/command/InMemoryTransactionTest.java @@ -0,0 +1,351 @@ +package li.strolch.command; + +import static li.strolch.service.test.AbstractRealmServiceTest.CONFIG_SRC; +import static li.strolch.service.test.AbstractRealmServiceTest.REALM_CACHED; +import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSIENT; +import static li.strolch.service.test.AbstractRealmServiceTest.dropSchema; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.BeforeClass; +import org.junit.Test; + +import li.strolch.model.ModelGenerator; +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.activity.Activity; +import li.strolch.model.activity.TimeOrdering; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.privilege.model.Certificate; +import li.strolch.testbase.runtime.RuntimeMock; + +public class InMemoryTransactionTest { + + private static final String TARGET_RUNTIME = "target/InMemoryTransactionTest/"; + + private static RuntimeMock runtimeMock; + private static Certificate certificate; + + @BeforeClass + public static void beforeClass() throws Exception { + + dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test"); + dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test"); + + runtimeMock = new RuntimeMock().mockRuntime(TARGET_RUNTIME, CONFIG_SRC); + runtimeMock.startContainer(); + certificate = runtimeMock.getPrivilegeHandler().authenticate("test", "test".toCharArray()); + } + + protected StrolchTransaction openTx(String realmName) { + return runtimeMock.getAgent().getContainer().getRealm(realmName).openTx(certificate, "test"); + } + + @Test + public void runTransient() { + shouldRunAll(REALM_TRANSIENT); + } + + @Test + public void runCached() { + shouldRunAll(REALM_CACHED); + } + + private void shouldRunAll(String realmName) { + + shouldCrudResource(realmName); + shouldCrudResource1(realmName); + shouldCrudResource2(realmName); + + shouldCrudOrder(realmName); + shouldCrudOrder1(realmName); + shouldCrudOrder2(realmName); + + shouldCrudActivity(realmName); + shouldCrudActivity1(realmName); + shouldCrudActivity2(realmName); + } + + public void shouldCrudResource(String realmName) { + String id = "@200"; + String type = "Bike"; + + // create + Resource newRes = ModelGenerator.createResource(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addResource(newRes); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Resource should exist!", tx.getResourceMap().hasElement(tx, type, id)); + } + + // update + try (StrolchTransaction tx = openTx(realmName)) { + Resource res = tx.getResourceBy(type, id); + res.setName("Foo foo"); + tx.updateResource(res); + tx.commitOnClose(); + } + + // verify + try (StrolchTransaction tx = openTx(realmName)) { + Resource res = tx.getResourceBy(type, id); + assertEquals("Foo foo", res.getName()); + } + + // remove + try (StrolchTransaction tx = openTx(realmName)) { + Resource res = tx.getResourceBy(type, id); + tx.removeResource(res); + tx.commitOnClose(); + } + + // should not exist + try (StrolchTransaction tx = openTx(realmName)) { + assertFalse("Resource should not exist!", tx.getResourceMap().hasElement(tx, type, id)); + } + + // create again + newRes = ModelGenerator.createResource(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addResource(newRes); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Resource should exist!", tx.getResourceMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudOrder(String realmName) { + String id = "@200"; + String type = "Bike"; + + // create + Order newOrder = ModelGenerator.createOrder(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addOrder(newOrder); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Order should exist!", tx.getOrderMap().hasElement(tx, type, id)); + } + + // update + try (StrolchTransaction tx = openTx(realmName)) { + Order order = tx.getOrderBy(type, id); + order.setName("Foo foo"); + tx.updateOrder(order); + tx.commitOnClose(); + } + + // verify + try (StrolchTransaction tx = openTx(realmName)) { + Order order = tx.getOrderBy(type, id); + assertEquals("Foo foo", order.getName()); + } + + // remove + try (StrolchTransaction tx = openTx(realmName)) { + Order order = tx.getOrderBy(type, id); + tx.removeOrder(order); + tx.commitOnClose(); + } + + // should not exist + try (StrolchTransaction tx = openTx(realmName)) { + assertFalse("Order should not exist!", tx.getOrderMap().hasElement(tx, type, id)); + } + + // create again + newOrder = ModelGenerator.createOrder(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addOrder(newOrder); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Order should exist!", tx.getOrderMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudActivity(String realmName) { + String id = "@200"; + String type = "Bike"; + + // create + Activity newActivity = ModelGenerator.createActivity(id, "200", type, TimeOrdering.SERIES); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addActivity(newActivity); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Activity should exist!", tx.getActivityMap().hasElement(tx, type, id)); + } + + // update + try (StrolchTransaction tx = openTx(realmName)) { + Activity activity = tx.getActivityBy(type, id); + activity.setName("Foo foo"); + tx.updateActivity(activity); + tx.commitOnClose(); + } + + // verify + try (StrolchTransaction tx = openTx(realmName)) { + Activity activity = tx.getActivityBy(type, id); + assertEquals("Foo foo", activity.getName()); + } + + // remove + try (StrolchTransaction tx = openTx(realmName)) { + Activity activity = tx.getActivityBy(type, id); + tx.removeActivity(activity); + tx.commitOnClose(); + } + + // should not exist + try (StrolchTransaction tx = openTx(realmName)) { + assertFalse("Activity should not exist!", tx.getActivityMap().hasElement(tx, type, id)); + } + + // create again + newActivity = ModelGenerator.createActivity(id, "200", type, TimeOrdering.SERIES); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addActivity(newActivity); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Activity should exist!", tx.getActivityMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudResource1(String realmName) { + String id = "@201"; + String type = "Bike"; + + // create and update + Resource newRes = ModelGenerator.createResource(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addResource(newRes); + newRes.setName("Foo foo!"); + tx.updateResource(newRes); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Resource should exist!", tx.getResourceMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudResource2(String realmName) { + String id = "@202"; + String type = "Bike"; + + // create and update + Resource newRes = ModelGenerator.createResource(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addResource(newRes); + newRes.setName("Foo foo!"); + tx.updateResource(newRes); + tx.removeResource(newRes); + tx.commitOnClose(); + } + + // should not exist + try (StrolchTransaction tx = openTx(realmName)) { + assertFalse("Resource should not exist!", tx.getResourceMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudOrder1(String realmName) { + String id = "@201"; + String type = "Bike"; + + // create and update + Order newOrder = ModelGenerator.createOrder(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addOrder(newOrder); + newOrder.setName("Foo foo!"); + tx.updateOrder(newOrder); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Order should exist!", tx.getOrderMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudOrder2(String realmName) { + String id = "@202"; + String type = "Bike"; + + // create and update + Order newOrder = ModelGenerator.createOrder(id, "200", type); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addOrder(newOrder); + newOrder.setName("Foo foo!"); + tx.updateOrder(newOrder); + tx.removeOrder(newOrder); + tx.commitOnClose(); + } + + // should not exist + try (StrolchTransaction tx = openTx(realmName)) { + assertFalse("Order should not exist!", tx.getOrderMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudActivity1(String realmName) { + String id = "@201"; + String type = "Bike"; + + // create and update + Activity newActivity = ModelGenerator.createActivity(id, "200", type, TimeOrdering.SERIES); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addActivity(newActivity); + newActivity.setName("Foo foo!"); + tx.updateActivity(newActivity); + tx.commitOnClose(); + } + + // should exist + try (StrolchTransaction tx = openTx(realmName)) { + assertTrue("Activity should exist!", tx.getActivityMap().hasElement(tx, type, id)); + } + } + + public void shouldCrudActivity2(String realmName) { + String id = "@202"; + String type = "Bike"; + + // create and update + Activity newActivity = ModelGenerator.createActivity(id, "200", type, TimeOrdering.SERIES); + try (StrolchTransaction tx = openTx(realmName)) { + tx.addActivity(newActivity); + newActivity.setName("Foo foo!"); + tx.updateActivity(newActivity); + tx.removeActivity(newActivity); + tx.commitOnClose(); + } + + // should not exist + try (StrolchTransaction tx = openTx(realmName)) { + assertFalse("Activity should not exist!", tx.getActivityMap().hasElement(tx, type, id)); + } + } +} diff --git a/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java index 75bf9c23d..84707ea3a 100644 --- a/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java +++ b/li.strolch.service/src/test/java/li/strolch/command/RemoveOrderCommandTest.java @@ -24,6 +24,7 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.model.Locator; import li.strolch.model.Order; import li.strolch.model.Tags; +import li.strolch.persistence.api.RemoveOrderCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; diff --git a/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java index fa3ce11b5..52cb09312 100644 --- a/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java +++ b/li.strolch.service/src/test/java/li/strolch/command/RemoveResourceCommandTest.java @@ -24,6 +24,7 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.model.Locator; import li.strolch.model.Resource; import li.strolch.model.Tags; +import li.strolch.persistence.api.RemoveResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.Command; diff --git a/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java index c5c1855bf..b2062264d 100644 --- a/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java +++ b/li.strolch.service/src/test/java/li/strolch/command/UpdateOrderCommandTest.java @@ -19,6 +19,7 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.model.ModelGenerator; import li.strolch.model.Order; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateOrderCommand; import li.strolch.service.api.Command; import static org.junit.Assert.assertEquals; diff --git a/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java index d0796718c..928f2e112 100644 --- a/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java +++ b/li.strolch.service/src/test/java/li/strolch/command/UpdateResourceCommandTest.java @@ -23,6 +23,7 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateResourceCommand; import li.strolch.service.api.Command; /** diff --git a/li.strolch.service/src/test/java/li/strolch/migrations/MigrationsTest.java b/li.strolch.service/src/test/java/li/strolch/migrations/MigrationsTest.java index 00f0843de..60e754e06 100644 --- a/li.strolch.service/src/test/java/li/strolch/migrations/MigrationsTest.java +++ b/li.strolch.service/src/test/java/li/strolch/migrations/MigrationsTest.java @@ -24,10 +24,10 @@ import java.util.List; import java.util.Map; import li.strolch.agent.api.ComponentContainer; -import li.strolch.command.AddOrderCommand; -import li.strolch.command.RemoveOrderCommand; import li.strolch.model.ModelGenerator; import li.strolch.model.Order; +import li.strolch.persistence.api.AddOrderCommand; +import li.strolch.persistence.api.RemoveOrderCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.privilege.model.Certificate; import li.strolch.runtime.StrolchConstants; diff --git a/li.strolch.service/src/test/java/li/strolch/service/FlushTxTest.java b/li.strolch.service/src/test/java/li/strolch/service/FlushTxTest.java index 40c7ed772..f3126adcf 100644 --- a/li.strolch.service/src/test/java/li/strolch/service/FlushTxTest.java +++ b/li.strolch.service/src/test/java/li/strolch/service/FlushTxTest.java @@ -17,12 +17,12 @@ package li.strolch.service; import org.junit.Test; -import li.strolch.command.AddResourceCommand; -import li.strolch.command.RemoveResourceCommand; -import li.strolch.command.UpdateResourceCommand; import li.strolch.model.ModelGenerator; import li.strolch.model.Resource; +import li.strolch.persistence.api.AddResourceCommand; +import li.strolch.persistence.api.RemoveResourceCommand; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.api.UpdateResourceCommand; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument; import li.strolch.service.api.ServiceResult; diff --git a/li.strolch.service/src/test/java/li/strolch/service/TxTest.java b/li.strolch.service/src/test/java/li/strolch/service/TxTest.java index d6f00dfac..d1e762467 100644 --- a/li.strolch.service/src/test/java/li/strolch/service/TxTest.java +++ b/li.strolch.service/src/test/java/li/strolch/service/TxTest.java @@ -21,10 +21,10 @@ import static org.junit.Assert.assertTrue; import org.junit.Ignore; import org.junit.Test; -import li.strolch.command.AddResourceCommand; import li.strolch.model.ModelGenerator; import li.strolch.model.Order; import li.strolch.model.Resource; +import li.strolch.persistence.api.AddResourceCommand; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.service.api.AbstractService; import li.strolch.service.api.ServiceArgument;