[Major] refactored how transactions are opened
Now the ElementMapHandler is the central object and clients do not use access DAOs or the PersistenceHandler anymore. This is now transparent.
This commit is contained in:
parent
e855378780
commit
a012c7fff8
|
@ -10,7 +10,7 @@ public abstract class AbstractModelTest {
|
|||
|
||||
@Test
|
||||
public void shouldStartContainer() {
|
||||
try (StrolchTransaction tx = getRuntimeMock().getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = getRuntimeMock().getDefaultRealm().openTx()) {
|
||||
tx.getOrderDao().queryKeySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class OrderModelTestRunner {
|
|||
|
||||
// create
|
||||
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getOrderDao().save(newOrder);
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ public class OrderModelTestRunner {
|
|||
|
||||
// create
|
||||
Order newOrder = createOrder(ID, NAME, TYPE);
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getOrderDao().save(newOrder);
|
||||
}
|
||||
|
||||
// read
|
||||
Order readOrder = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
readOrder = tx.getOrderDao().queryBy(TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Order with id " + ID, readOrder);
|
||||
|
@ -62,13 +62,13 @@ public class OrderModelTestRunner {
|
|||
Parameter<String> sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID);
|
||||
String newStringValue = "Giddiya!";
|
||||
sParam.setValue(newStringValue);
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getOrderDao().update(readOrder);
|
||||
}
|
||||
|
||||
// read updated
|
||||
Order updatedOrder = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
updatedOrder = tx.getOrderDao().queryBy(TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Order with id " + ID, updatedOrder);
|
||||
|
@ -77,12 +77,12 @@ public class OrderModelTestRunner {
|
|||
assertEquals(newStringValue, updatedParam.getValue());
|
||||
|
||||
// delete
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getOrderDao().remove(readOrder);
|
||||
}
|
||||
|
||||
// fail to re-read
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
Order order = tx.getOrderDao().queryBy(TYPE, ID);
|
||||
assertNull("Should no read Order with id " + ID, order);
|
||||
}
|
||||
|
@ -103,11 +103,11 @@ public class OrderModelTestRunner {
|
|||
};
|
||||
Collections.sort(orders, comparator);
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
tx.getOrderDao().removeAll(tx.getOrderDao().queryAll());
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
tx.getOrderDao().saveAll(orders);
|
||||
}
|
||||
|
||||
|
@ -116,13 +116,13 @@ public class OrderModelTestRunner {
|
|||
expectedTypes.add("MyType2");
|
||||
expectedTypes.add("MyType3");
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
List<Order> allOrders = tx.getOrderDao().queryAll();
|
||||
Collections.sort(allOrders, comparator);
|
||||
assertEquals(orders, allOrders);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
OrderDao orderDao = tx.getOrderDao();
|
||||
|
||||
Set<String> types = orderDao.queryTypes();
|
||||
|
@ -140,7 +140,7 @@ public class OrderModelTestRunner {
|
|||
}
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001");
|
||||
assertNotNull(order);
|
||||
order = tx.getOrderDao().queryBy("MyType2", "@_00000006");
|
||||
|
|
|
@ -38,7 +38,7 @@ public class ResourceModelTestRunner {
|
|||
|
||||
// create
|
||||
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getResourceDao().save(newResource);
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ public class ResourceModelTestRunner {
|
|||
|
||||
// create
|
||||
Resource newResource = createResource(ID, NAME, TYPE);
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getResourceDao().save(newResource);
|
||||
}
|
||||
|
||||
// read
|
||||
Resource readResource = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
readResource = tx.getResourceDao().queryBy(TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$
|
||||
|
@ -62,13 +62,13 @@ public class ResourceModelTestRunner {
|
|||
Parameter<String> sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID);
|
||||
String newStringValue = "Giddiya!"; //$NON-NLS-1$
|
||||
sParam.setValue(newStringValue);
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getResourceDao().update(readResource);
|
||||
}
|
||||
|
||||
// read updated
|
||||
Resource updatedResource = null;
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
updatedResource = tx.getResourceDao().queryBy(TYPE, ID);
|
||||
}
|
||||
assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$
|
||||
|
@ -77,12 +77,12 @@ public class ResourceModelTestRunner {
|
|||
assertEquals(newStringValue, updatedParam.getValue());
|
||||
|
||||
// delete
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
tx.getResourceDao().remove(readResource);
|
||||
}
|
||||
|
||||
// fail to re-read
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) {
|
||||
Resource resource = tx.getResourceDao().queryBy(TYPE, ID);
|
||||
assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -103,11 +103,11 @@ public class ResourceModelTestRunner {
|
|||
};
|
||||
Collections.sort(resources, comparator);
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
tx.getResourceDao().removeAll(tx.getResourceDao().queryAll());
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
tx.getResourceDao().saveAll(resources);
|
||||
}
|
||||
|
||||
|
@ -116,13 +116,13 @@ public class ResourceModelTestRunner {
|
|||
expectedTypes.add("MyType2");
|
||||
expectedTypes.add("MyType3");
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
List<Resource> allResources = tx.getResourceDao().queryAll();
|
||||
Collections.sort(allResources, comparator);
|
||||
assertEquals(resources, allResources);
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
ResourceDao resourceDao = tx.getResourceDao();
|
||||
|
||||
Set<String> types = resourceDao.queryTypes();
|
||||
|
@ -140,7 +140,7 @@ public class ResourceModelTestRunner {
|
|||
}
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) {
|
||||
try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) {
|
||||
Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001");
|
||||
assertNotNull(resource);
|
||||
resource = tx.getResourceDao().queryBy("MyType2", "@_00000006");
|
||||
|
|
|
@ -19,9 +19,8 @@ import java.io.File;
|
|||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.runtime.agent.api.ComponentContainer;
|
||||
import li.strolch.runtime.agent.api.OrderMap;
|
||||
import li.strolch.runtime.agent.api.ResourceMap;
|
||||
import li.strolch.runtime.agent.api.StrolchAgent;
|
||||
import li.strolch.runtime.agent.impl.StrolchRealm;
|
||||
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
||||
import li.strolch.runtime.privilege.StrolchPrivilegeHandler;
|
||||
|
||||
|
@ -50,12 +49,12 @@ public final class RuntimeMock {
|
|||
return this.container.getComponent(StrolchPrivilegeHandler.class);
|
||||
}
|
||||
|
||||
public OrderMap getOrderMap() {
|
||||
return this.container.getOrderMap();
|
||||
public StrolchRealm getDefaultRealm() {
|
||||
return this.container.getDefaultRealm();
|
||||
}
|
||||
|
||||
public ResourceMap getResourceMap() {
|
||||
return this.container.getResourceMap();
|
||||
|
||||
public StrolchRealm getRealm(String realm) {
|
||||
return this.container.getRealm(realm);
|
||||
}
|
||||
|
||||
public void mockRuntime(File rootPathF, File rootSrc) {
|
||||
|
|
Loading…
Reference in New Issue