[Major] Added add, update and remove methods to TX for elements
Moved add, update and remove commands to agent package
This commit is contained in:
parent
0b62acc4f3
commit
c0cc6f57cb
|
@ -22,7 +22,6 @@ import li.strolch.agent.api.AuditTrail;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.persistence.api.PersistenceHandler;
|
import li.strolch.persistence.api.PersistenceHandler;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.persistence.inmemory.InMemoryPersistence;
|
import li.strolch.persistence.inmemory.InMemoryPersistence;
|
||||||
|
@ -86,10 +85,7 @@ public class EmptyRealm extends InternalStrolchRealm {
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ComponentContainer container, ComponentConfiguration configuration) {
|
public void initialize(ComponentContainer container, ComponentConfiguration configuration) {
|
||||||
super.initialize(container, configuration);
|
super.initialize(container, configuration);
|
||||||
OperationsLog operationsLog = container.hasComponent(OperationsLog.class)
|
this.persistenceHandler = new InMemoryPersistence(container, isVersioningEnabled());
|
||||||
? container.getComponent(OperationsLog.class) : null;
|
|
||||||
this.persistenceHandler = new InMemoryPersistence(operationsLog, container.getPrivilegeHandler(),
|
|
||||||
isVersioningEnabled());
|
|
||||||
this.resourceMap = new TransactionalResourceMap(this);
|
this.resourceMap = new TransactionalResourceMap(this);
|
||||||
this.orderMap = new TransactionalOrderMap(this);
|
this.orderMap = new TransactionalOrderMap(this);
|
||||||
this.activityMap = new TransactionalActivityMap(this);
|
this.activityMap = new TransactionalActivityMap(this);
|
||||||
|
|
|
@ -23,7 +23,6 @@ import li.strolch.agent.api.AuditTrail;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.model.ModelStatistics;
|
import li.strolch.model.ModelStatistics;
|
||||||
import li.strolch.model.xml.XmlModelSaxFileReader;
|
import li.strolch.model.xml.XmlModelSaxFileReader;
|
||||||
import li.strolch.persistence.api.PersistenceHandler;
|
import li.strolch.persistence.api.PersistenceHandler;
|
||||||
|
@ -104,10 +103,7 @@ public class TransientRealm extends InternalStrolchRealm {
|
||||||
|
|
||||||
this.modelFile = configuration.getDataFile(key, null, configuration.getRuntimeConfiguration(), true);
|
this.modelFile = configuration.getDataFile(key, null, configuration.getRuntimeConfiguration(), true);
|
||||||
|
|
||||||
OperationsLog operationsLog = container.hasComponent(OperationsLog.class)
|
this.persistenceHandler = new InMemoryPersistence(container, isVersioningEnabled());
|
||||||
? container.getComponent(OperationsLog.class) : null;
|
|
||||||
this.persistenceHandler = new InMemoryPersistence(operationsLog, container.getPrivilegeHandler(),
|
|
||||||
isVersioningEnabled());
|
|
||||||
this.resourceMap = new TransactionalResourceMap(this);
|
this.resourceMap = new TransactionalResourceMap(this);
|
||||||
this.orderMap = new TransactionalOrderMap(this);
|
this.orderMap = new TransactionalOrderMap(this);
|
||||||
this.activityMap = new TransactionalActivityMap(this);
|
this.activityMap = new TransactionalActivityMap(this);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import li.strolch.agent.api.ActivityMap;
|
import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.AuditTrail;
|
import li.strolch.agent.api.AuditTrail;
|
||||||
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.ObserverEvent;
|
import li.strolch.agent.api.ObserverEvent;
|
||||||
import li.strolch.agent.api.ObserverHandler;
|
import li.strolch.agent.api.ObserverHandler;
|
||||||
import li.strolch.agent.api.OrderMap;
|
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.agent.impl.InternalStrolchRealm;
|
||||||
import li.strolch.exception.StrolchAccessDeniedException;
|
import li.strolch.exception.StrolchAccessDeniedException;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.exception.StrolchModelException;
|
||||||
import li.strolch.handler.operationslog.LogMessage;
|
import li.strolch.handler.operationslog.LogMessage;
|
||||||
import li.strolch.handler.operationslog.LogSeverity;
|
import li.strolch.handler.operationslog.LogSeverity;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
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.dbc.DBC;
|
||||||
import li.strolch.utils.helper.ExceptionHelper;
|
import li.strolch.utils.helper.ExceptionHelper;
|
||||||
import li.strolch.utils.helper.StringHelper;
|
import li.strolch.utils.helper.StringHelper;
|
||||||
|
import li.strolch.utils.objectfilter.ObjectFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -87,8 +90,15 @@ import li.strolch.utils.helper.StringHelper;
|
||||||
public abstract class AbstractTransaction implements StrolchTransaction {
|
public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
|
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractTransaction.class);
|
protected static final Logger logger = LoggerFactory.getLogger(AbstractTransaction.class);
|
||||||
|
|
||||||
|
private ComponentContainer container;
|
||||||
|
private PrivilegeHandler privilegeHandler;
|
||||||
|
private OperationsLog operationsLog;
|
||||||
|
|
||||||
private InternalStrolchRealm realm;
|
private InternalStrolchRealm realm;
|
||||||
|
|
||||||
|
private ObjectFilter objectFilter;
|
||||||
|
|
||||||
private TransactionCloseStrategy closeStrategy;
|
private TransactionCloseStrategy closeStrategy;
|
||||||
private boolean suppressUpdates;
|
private boolean suppressUpdates;
|
||||||
private boolean suppressAudits;
|
private boolean suppressAudits;
|
||||||
|
@ -107,18 +117,18 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
|
|
||||||
private String action;
|
private String action;
|
||||||
private Certificate certificate;
|
private Certificate certificate;
|
||||||
private PrivilegeHandler privilegeHandler;
|
|
||||||
private OperationsLog operationsLog;
|
|
||||||
|
|
||||||
public AbstractTransaction(OperationsLog operationsLog, PrivilegeHandler privilegeHandler, StrolchRealm realm,
|
public AbstractTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate,
|
||||||
Certificate certificate, String action) {
|
String action) {
|
||||||
DBC.PRE.assertNotNull("privilegeHandler must be set!", privilegeHandler); //$NON-NLS-1$
|
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("realm must be set!", realm); //$NON-NLS-1$
|
||||||
DBC.PRE.assertNotNull("certificate must be set!", certificate); //$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$
|
DBC.PRE.assertNotNull("action must be set!", action); //$NON-NLS-1$
|
||||||
|
|
||||||
this.privilegeHandler = privilegeHandler;
|
this.container = container;
|
||||||
this.operationsLog = operationsLog;
|
this.privilegeHandler = container.getPrivilegeHandler();
|
||||||
|
if (container.hasComponent(OperationsLog.class))
|
||||||
|
this.operationsLog = container.getComponent(OperationsLog.class);
|
||||||
this.realm = (InternalStrolchRealm) realm;
|
this.realm = (InternalStrolchRealm) realm;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.certificate = certificate;
|
this.certificate = certificate;
|
||||||
|
@ -336,6 +346,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
return this.auditTrail;
|
return this.auditTrail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ComponentContainer getContainer() {
|
||||||
|
return this.container;
|
||||||
|
}
|
||||||
|
|
||||||
private void assertQueryAllowed(StrolchQuery query) {
|
private void assertQueryAllowed(StrolchQuery query) {
|
||||||
try {
|
try {
|
||||||
PrivilegeContext privilegeContext = this.privilegeHandler.getPrivilegeContext(this.certificate);
|
PrivilegeContext privilegeContext = this.privilegeHandler.getPrivilegeContext(this.certificate);
|
||||||
|
@ -634,9 +649,175 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
return getActivityMap().getBy(this, refP, assertExists);
|
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<Object> removed;
|
||||||
|
List<Object> updated;
|
||||||
|
List<Object> 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
|
@Override
|
||||||
public void flush() {
|
public void flush() {
|
||||||
try {
|
try {
|
||||||
|
addModelChangeCommands();
|
||||||
validateCommands();
|
validateCommands();
|
||||||
doCommands();
|
doCommands();
|
||||||
writeChanges();
|
writeChanges();
|
||||||
|
@ -656,6 +837,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
try {
|
try {
|
||||||
this.txResult.setState(TransactionState.COMMITTING);
|
this.txResult.setState(TransactionState.COMMITTING);
|
||||||
|
|
||||||
|
addModelChangeCommands();
|
||||||
validateCommands();
|
validateCommands();
|
||||||
doCommands();
|
doCommands();
|
||||||
writeChanges();
|
writeChanges();
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
|
|
||||||
import li.strolch.agent.api.ActivityMap;
|
import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.AuditTrail;
|
import li.strolch.agent.api.AuditTrail;
|
||||||
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
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.api.StrolchRealm;
|
||||||
import li.strolch.agent.impl.DataStoreMode;
|
import li.strolch.agent.impl.DataStoreMode;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.exception.StrolchModelException;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.ParameterBag;
|
import li.strolch.model.ParameterBag;
|
||||||
|
@ -143,6 +145,13 @@ public interface StrolchTransaction extends AutoCloseable {
|
||||||
*/
|
*/
|
||||||
public PersistenceHandler getPersistenceHandler();
|
public PersistenceHandler getPersistenceHandler();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the {@link ComponentContainer}
|
||||||
|
*
|
||||||
|
* @return the reference to the container
|
||||||
|
*/
|
||||||
|
public ComponentContainer getContainer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the currently set {@link TransactionCloseStrategy}
|
* 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
|
* if the {@link StringListParameter} is not a properly configured as a reference parameter
|
||||||
*/
|
*/
|
||||||
public List<Order> getOrdersBy(StringListParameter refP, boolean assertExists) throws StrolchException;
|
public List<Order> 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ActivityMap;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.OrderMap;
|
import li.strolch.agent.api.OrderMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package li.strolch.command;
|
package li.strolch.persistence.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.ResourceMap;
|
import li.strolch.agent.api.ResourceMap;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
|
|
|
@ -18,8 +18,8 @@ package li.strolch.persistence.inmemory;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.persistence.api.ActivityDao;
|
import li.strolch.persistence.api.ActivityDao;
|
||||||
import li.strolch.persistence.api.AuditDao;
|
import li.strolch.persistence.api.AuditDao;
|
||||||
import li.strolch.persistence.api.OrderDao;
|
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.ResourceDao;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
|
||||||
|
|
||||||
public class InMemoryPersistence implements PersistenceHandler {
|
public class InMemoryPersistence implements PersistenceHandler {
|
||||||
|
|
||||||
private boolean versioningEnabled;
|
private boolean versioningEnabled;
|
||||||
private Map<String, DaoCache> daoCache;
|
private Map<String, DaoCache> daoCache;
|
||||||
private PrivilegeHandler privilegeHandler;
|
private ComponentContainer container;
|
||||||
private OperationsLog operationsLog;
|
|
||||||
|
|
||||||
public InMemoryPersistence(OperationsLog operationsLog, PrivilegeHandler privilegeHandler,
|
public InMemoryPersistence(ComponentContainer container, boolean versioningEnabled) {
|
||||||
boolean versioningEnabled) {
|
this.container = container;
|
||||||
this.operationsLog = operationsLog;
|
|
||||||
this.privilegeHandler = privilegeHandler;
|
|
||||||
this.versioningEnabled = versioningEnabled;
|
this.versioningEnabled = versioningEnabled;
|
||||||
this.daoCache = new HashMap<>();
|
this.daoCache = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) {
|
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
|
@Override
|
||||||
|
|
|
@ -15,21 +15,20 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.persistence.inmemory;
|
package li.strolch.persistence.inmemory;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.persistence.api.AbstractTransaction;
|
import li.strolch.persistence.api.AbstractTransaction;
|
||||||
import li.strolch.persistence.api.PersistenceHandler;
|
import li.strolch.persistence.api.PersistenceHandler;
|
||||||
import li.strolch.persistence.api.TransactionState;
|
import li.strolch.persistence.api.TransactionState;
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
|
||||||
|
|
||||||
public class InMemoryTransaction extends AbstractTransaction {
|
public class InMemoryTransaction extends AbstractTransaction {
|
||||||
|
|
||||||
private InMemoryPersistence persistenceHandler;
|
private InMemoryPersistence persistenceHandler;
|
||||||
|
|
||||||
public InMemoryTransaction(OperationsLog operationsLog, PrivilegeHandler privilegeHandler, StrolchRealm realm,
|
public InMemoryTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate, String action,
|
||||||
Certificate certificate, String action, InMemoryPersistence persistenceHandler) {
|
InMemoryPersistence persistenceHandler) {
|
||||||
super(operationsLog, privilegeHandler, realm, certificate, action);
|
super(container, realm, certificate, action);
|
||||||
this.persistenceHandler = persistenceHandler;
|
this.persistenceHandler = persistenceHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class InMemoryPersistenceHandler extends StrolchComponent implements Pers
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ComponentConfiguration configuration) throws Exception {
|
public void initialize(ComponentConfiguration configuration) throws Exception {
|
||||||
this.persistence = new InMemoryPersistence(null, getContainer().getPrivilegeHandler(), false);
|
this.persistence = new InMemoryPersistence(getContainer(), false);
|
||||||
super.initialize(configuration);
|
super.initialize(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,10 @@ package li.strolch.performance;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import li.strolch.agent.api.StrolchAgent;
|
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.ModelGenerator;
|
||||||
import li.strolch.model.Resource;
|
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.StrolchTransaction;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
|
@ -35,7 +35,6 @@ import li.strolch.agent.api.StrolchComponent;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.db.DbMigrationState;
|
import li.strolch.db.DbMigrationState;
|
||||||
import li.strolch.db.DbSchemaVersionCheck;
|
import li.strolch.db.DbSchemaVersionCheck;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.persistence.api.ActivityDao;
|
import li.strolch.persistence.api.ActivityDao;
|
||||||
import li.strolch.persistence.api.AuditDao;
|
import li.strolch.persistence.api.AuditDao;
|
||||||
import li.strolch.persistence.api.OrderDao;
|
import li.strolch.persistence.api.OrderDao;
|
||||||
|
@ -131,10 +130,7 @@ public class PostgreSqlPersistenceHandler extends StrolchComponent implements Pe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) {
|
public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) {
|
||||||
OperationsLog operationsLog = getContainer().hasComponent(OperationsLog.class)
|
return new PostgreSqlStrolchTransaction(getContainer(), realm, certificate, action, this);
|
||||||
? getContainer().getComponent(OperationsLog.class) : null;
|
|
||||||
return new PostgreSqlStrolchTransaction(operationsLog, getContainer().getPrivilegeHandler(), realm, certificate,
|
|
||||||
action, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection getConnection(String realm) {
|
Connection getConnection(String realm) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ import java.sql.Connection;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.persistence.api.AbstractTransaction;
|
import li.strolch.persistence.api.AbstractTransaction;
|
||||||
import li.strolch.persistence.api.ActivityDao;
|
import li.strolch.persistence.api.ActivityDao;
|
||||||
import li.strolch.persistence.api.AuditDao;
|
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.PersistenceHandler;
|
||||||
import li.strolch.persistence.api.ResourceDao;
|
import li.strolch.persistence.api.ResourceDao;
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
|
||||||
|
|
||||||
public class PostgreSqlStrolchTransaction extends AbstractTransaction {
|
public class PostgreSqlStrolchTransaction extends AbstractTransaction {
|
||||||
|
|
||||||
|
@ -42,10 +41,10 @@ public class PostgreSqlStrolchTransaction extends AbstractTransaction {
|
||||||
private AuditDao auditDao;
|
private AuditDao auditDao;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
public PostgreSqlStrolchTransaction(OperationsLog operationsLog, PrivilegeHandler privilegeHandler,
|
public PostgreSqlStrolchTransaction(ComponentContainer container,
|
||||||
StrolchRealm realm, Certificate certificate, String action,
|
StrolchRealm realm, Certificate certificate, String action,
|
||||||
PostgreSqlPersistenceHandler persistenceHandler) {
|
PostgreSqlPersistenceHandler persistenceHandler) {
|
||||||
super(operationsLog, privilegeHandler, realm, certificate, action);
|
super(container, realm, certificate, action);
|
||||||
this.persistenceHandler = persistenceHandler;
|
this.persistenceHandler = persistenceHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@ import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.command.UpdateActivityCommand;
|
|
||||||
import li.strolch.command.UpdateOrderCommand;
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.execution.policy.ConfirmationPolicy;
|
import li.strolch.execution.policy.ConfirmationPolicy;
|
||||||
import li.strolch.execution.policy.ExecutionPolicy;
|
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.policy.PolicyDef;
|
||||||
import li.strolch.model.visitor.IActivityElementVisitor;
|
import li.strolch.model.visitor.IActivityElementVisitor;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
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.policy.PolicyHandler;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
import li.strolch.utils.helper.StringHelper;
|
import li.strolch.utils.helper.StringHelper;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package li.strolch.execution.policy;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.command.UpdateActivityCommand;
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.execution.DelayedExecutionTimer;
|
import li.strolch.execution.DelayedExecutionTimer;
|
||||||
import li.strolch.execution.ExecutionHandler;
|
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.Action;
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateActivityCommand;
|
||||||
import li.strolch.policy.StrolchPolicy;
|
import li.strolch.policy.StrolchPolicy;
|
||||||
import li.strolch.privilege.base.PrivilegeException;
|
import li.strolch.privilege.base.PrivilegeException;
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package li.strolch.execution.policy;
|
package li.strolch.execution.policy;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.command.RemoveActivityCommand;
|
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.persistence.api.RemoveActivityCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
|
||||||
public class RemoveActivityArchival extends ActivityArchivalPolicy {
|
public class RemoveActivityArchival extends ActivityArchivalPolicy {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package li.strolch.execution.policy;
|
package li.strolch.execution.policy;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.command.UpdateResourceCommand;
|
|
||||||
import li.strolch.exception.StrolchModelException;
|
import li.strolch.exception.StrolchModelException;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
@ -9,6 +8,7 @@ import li.strolch.model.State;
|
||||||
import li.strolch.model.activity.Action;
|
import li.strolch.model.activity.Action;
|
||||||
import li.strolch.model.parameter.BooleanParameter;
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateResourceCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -18,11 +18,11 @@ package li.strolch.migrations;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.command.AddResourceCommand;
|
|
||||||
import li.strolch.command.parameter.SetParameterCommand;
|
import li.strolch.command.parameter.SetParameterCommand;
|
||||||
import li.strolch.model.ParameterBag;
|
import li.strolch.model.ParameterBag;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.parameter.StringParameter;
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
import li.strolch.persistence.api.AddResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
import li.strolch.utils.Version;
|
import li.strolch.utils.Version;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.AddActivityCommand;
|
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.persistence.api.AddActivityCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.AddActivityService.AddActivityArg;
|
import li.strolch.service.AddActivityService.AddActivityArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.AddResourceCommand;
|
|
||||||
import li.strolch.command.UpdateResourceCommand;
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.persistence.api.AddResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateResourceCommand;
|
||||||
import li.strolch.service.AddOrUpdateResourceService.AddOrUpdateResourceArg;
|
import li.strolch.service.AddOrUpdateResourceService.AddOrUpdateResourceArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.AddOrderCommand;
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.persistence.api.AddOrderCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.AddOrderService.AddOrderArg;
|
import li.strolch.service.AddOrderService.AddOrderArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.AddResourceCommand;
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.persistence.api.AddResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.AddResourceService.AddResourceArg;
|
import li.strolch.service.AddResourceService.AddResourceArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.RemoveActivityCommand;
|
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
|
import li.strolch.persistence.api.RemoveActivityCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.RemoveOrderCommand;
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.persistence.api.RemoveOrderCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.RemoveResourceCommand;
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.persistence.api.RemoveResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.UpdateActivityCommand;
|
|
||||||
import li.strolch.model.activity.Activity;
|
import li.strolch.model.activity.Activity;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateActivityCommand;
|
||||||
import li.strolch.service.UpdateActivityService.UpdateActivityArg;
|
import li.strolch.service.UpdateActivityService.UpdateActivityArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.UpdateOrderCommand;
|
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateOrderCommand;
|
||||||
import li.strolch.service.UpdateOrderService.UpdateOrderArg;
|
import li.strolch.service.UpdateOrderService.UpdateOrderArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.service;
|
package li.strolch.service;
|
||||||
|
|
||||||
import li.strolch.command.UpdateResourceCommand;
|
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateResourceCommand;
|
||||||
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
|
import li.strolch.service.UpdateResourceService.UpdateResourceArg;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.junit.Before;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.model.ModelGenerator;
|
import li.strolch.model.ModelGenerator;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.persistence.api.AddOrderCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.junit.Before;
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.model.ModelGenerator;
|
import li.strolch.model.ModelGenerator;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.persistence.api.AddResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
|
|
||||||
|
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.persistence.api.RemoveOrderCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.persistence.api.RemoveResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.model.ModelGenerator;
|
import li.strolch.model.ModelGenerator;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateOrderCommand;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.model.ModelGenerator;
|
import li.strolch.model.ModelGenerator;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateResourceCommand;
|
||||||
import li.strolch.service.api.Command;
|
import li.strolch.service.api.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,10 +24,10 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
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.ModelGenerator;
|
||||||
import li.strolch.model.Order;
|
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.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
import li.strolch.runtime.StrolchConstants;
|
import li.strolch.runtime.StrolchConstants;
|
||||||
|
|
|
@ -17,12 +17,12 @@ package li.strolch.service;
|
||||||
|
|
||||||
import org.junit.Test;
|
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.ModelGenerator;
|
||||||
import li.strolch.model.Resource;
|
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.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.UpdateResourceCommand;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
import li.strolch.service.api.ServiceResult;
|
import li.strolch.service.api.ServiceResult;
|
||||||
|
|
|
@ -21,10 +21,10 @@ import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import li.strolch.command.AddResourceCommand;
|
|
||||||
import li.strolch.model.ModelGenerator;
|
import li.strolch.model.ModelGenerator;
|
||||||
import li.strolch.model.Order;
|
import li.strolch.model.Order;
|
||||||
import li.strolch.model.Resource;
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.persistence.api.AddResourceCommand;
|
||||||
import li.strolch.persistence.api.StrolchTransaction;
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
import li.strolch.service.api.AbstractService;
|
import li.strolch.service.api.AbstractService;
|
||||||
import li.strolch.service.api.ServiceArgument;
|
import li.strolch.service.api.ServiceArgument;
|
||||||
|
|
Loading…
Reference in New Issue