diff --git a/ch.eitchnet.utils b/ch.eitchnet.utils
index 401052a5e..97936b03f 160000
--- a/ch.eitchnet.utils
+++ b/ch.eitchnet.utils
@@ -1 +1 @@
-Subproject commit 401052a5ea5844673615ba4c255b6faa96000adc
+Subproject commit 97936b03fe86ce421bbfe61efbd51a49da1f0868
diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedRealm.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedRealm.java
index 56651a3a3..af9230dcb 100644
--- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedRealm.java
+++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/CachedRealm.java
@@ -115,6 +115,8 @@ public class CachedRealm extends InternalStrolchRealm {
nrOfResources++;
}
}
+
+ tx.commitOnClose();
}
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
@@ -127,6 +129,8 @@ public class CachedRealm extends InternalStrolchRealm {
nrOfOrders++;
}
}
+
+ tx.commitOnClose();
}
long duration = System.nanoTime() - start;
diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalRealm.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalRealm.java
index 56a1b8a4e..d6c245829 100644
--- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalRealm.java
+++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/TransactionalRealm.java
@@ -101,10 +101,12 @@ public class TransactionalRealm extends InternalStrolchRealm {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
nrOfOrders = this.orderMap.getAllKeys(tx).size();
+ tx.commitOnClose();
}
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
nrOfResources = this.resourceMap.getAllKeys(tx).size();
+ tx.commitOnClose();
}
long duration = System.nanoTime() - start;
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 ed8ad0159..2abbda884 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
@@ -118,6 +118,7 @@ public class TransientRealm extends InternalStrolchRealm {
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile);
handler.parseFile();
statistics = handler.getStatistics();
+ tx.commitOnClose();
}
String durationS = StringHelper.formatNanoDuration(statistics.durationNanos);
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 85df9fedd..3dc4246e3 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
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
+import java.util.ListIterator;
import java.util.Set;
import li.strolch.agent.api.AuditTrail;
@@ -112,7 +113,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
this.commands = new ArrayList<>();
this.lockedElements = new HashSet<>();
- this.closeStrategy = TransactionCloseStrategy.COMMIT;
+ this.closeStrategy = TransactionCloseStrategy.ROLLBACK;
this.txResult = new TransactionResult(getRealmName(), System.nanoTime(), new Date());
this.txResult.setState(TransactionState.OPEN);
}
@@ -156,16 +157,31 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return certificate;
}
- @Override
- public void setCloseStrategy(TransactionCloseStrategy closeStrategy) {
+ private void setCloseStrategy(TransactionCloseStrategy closeStrategy) {
this.closeStrategy = closeStrategy;
}
@Override
- public void close() throws StrolchPersistenceException {
+ public void close() throws StrolchTransactionException {
this.closeStrategy.close(this);
}
+ @Override
+ public void commitOnClose() {
+ setCloseStrategy(TransactionCloseStrategy.COMMIT);
+ }
+
+ @Override
+ public void rollbackOnClose() {
+ setCloseStrategy(TransactionCloseStrategy.ROLLBACK);
+ }
+
+ @Override
+ public StrolchTransactionException fail(String string) {
+ rollbackOnClose();
+ return new StrolchTransactionException(string);
+ }
+
@Override
public void setSuppressUpdates(boolean suppressUpdates) {
this.suppressUpdates = suppressUpdates;
@@ -460,7 +476,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
String msg = "Strolch Transaction for realm {0} failed due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getRealmName(), e.getMessage());
- throw new StrolchPersistenceException(msg, e);
+ throw new StrolchTransactionException(msg, e);
}
}
@@ -505,7 +521,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
String msg = "Strolch Transaction for realm {0} failed due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getRealmName(), e.getMessage());
- throw new StrolchPersistenceException(msg, e);
+ throw new StrolchTransactionException(msg, e);
} finally {
releaseElementLocks();
@@ -633,7 +649,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
String msg = "Strolch Transaction for realm {0} failed due to {1}\n{2}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getRealmName(), e.getMessage(), sb.toString());
- throw new StrolchPersistenceException(msg, e);
+ throw new StrolchTransactionException(msg, e);
}
private boolean isAuditTrailEnabled() {
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 ff37e569f..b0088363a 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
@@ -61,6 +61,7 @@ import ch.eitchnet.privilege.model.Certificate;
* StrolchRealm realm = strolchAgent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM);
* try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
* // do work e.g. add commands
+ * tx.commitOnClose();
* }
*
*
@@ -132,28 +133,18 @@ public interface StrolchTransaction extends AutoCloseable {
public PersistenceHandler getPersistenceHandler();
/**
- * Sets the strategy to be used when closing the transaction when {@link #close()} is called. The default is
- * {@link TransactionCloseStrategy#COMMIT}, but if the user of the transaction decides it wants to use a different
- * strategy, then it may set it using this method
- *
- * @param closeStrategy
- * the new {@link TransactionCloseStrategy} to use
+ * DO NOT CALL THIS METHOD. If the currently set close strategy is {@link TransactionCloseStrategy#COMMIT}, then
+ * when the transaction is closed, this method is called and all registered {@link Command} are performed, locks on
+ * objects are released and any other resources are released
*/
- public void setCloseStrategy(TransactionCloseStrategy closeStrategy);
+ public void autoCloseableCommit() throws StrolchTransactionException;
/**
- * If the currently set close strategy is {@link TransactionCloseStrategy#COMMIT}, then when the transaction is
- * closed, this method is called and all registered {@link Command} are performed, locks on objects are released and
- * any other resources are released
+ * DO NOT CALL THIS METHOD. If the currently set close strategy is {@link TransactionCloseStrategy#ROLLBACK}, then
+ * when the transaction is closed, no further actions are performed and any {@link Command} which were performed
+ * have their {@link Command#undo()} method called and any DB connections are also rolled back
*/
- public void autoCloseableCommit();
-
- /**
- * If the currently set close strategy is {@link TransactionCloseStrategy#ROLLBACK}, then when the transaction is
- * closed, no further actions are performed and any {@link Command} which were performed have their
- * {@link Command#undo()} method called and any DB connections are also rolled back
- */
- public void autoCloseableRollback();
+ public void autoCloseableRollback() throws StrolchTransactionException;
/**
*
@@ -166,13 +157,34 @@ public interface StrolchTransaction extends AutoCloseable {
* StrolchRealm realm = strolchAgent.getContainer().getRealm("defaultRealm");
* try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
* // do work
+ * tx.commitOnClose();
* }
*
*
* After the block is closed, the transaction is automatically closed and all allocated resources are released
*/
@Override
- public void close() throws StrolchPersistenceException;
+ public void close() throws StrolchTransactionException;
+
+ /**
+ * Sets the {@link TransactionCloseStrategy} to {@link TransactionCloseStrategy#COMMIT}
+ */
+ public void commitOnClose();
+
+ /**
+ * Sets the {@link TransactionCloseStrategy} to {@link TransactionCloseStrategy#ROLLBACK}
+ */
+ public void rollbackOnClose();
+
+ /**
+ * Sets the {@link TransactionCloseStrategy} to {@link TransactionCloseStrategy#ROLLBACK} and returns a
+ * {@link StrolchTransactionException} which can be thrown by the caller to stop the exception
+ *
+ * @param exceptionMessage
+ *
+ * @return a {@link StrolchTransactionException} to be thrown by the caller
+ */
+ public StrolchTransactionException fail(String exceptionMessage);
/**
*
diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransactionException.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransactionException.java
new file mode 100644
index 000000000..d39faff37
--- /dev/null
+++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransactionException.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2013 Robert von Burg
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package li.strolch.persistence.api;
+
+/**
+ * @author Robert von Burg
+ */
+public class StrolchTransactionException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param message
+ */
+ public StrolchTransactionException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public StrolchTransactionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/TransactionCloseStrategy.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/TransactionCloseStrategy.java
index 18f25e5d8..a1c08ac7f 100644
--- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/TransactionCloseStrategy.java
+++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/TransactionCloseStrategy.java
@@ -15,23 +15,23 @@
*/
package li.strolch.persistence.api;
+import li.strolch.exception.StrolchException;
+
public enum TransactionCloseStrategy {
+
COMMIT() {
@Override
- public void close(StrolchTransaction tx) {
+ public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableCommit();
}
},
ROLLBACK() {
@Override
- public void close(StrolchTransaction tx) {
+ public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableRollback();
}
};
- /**
- * @param tx
- */
- public abstract void close(StrolchTransaction tx);
+ public abstract void close(StrolchTransaction tx) throws StrolchException;
}
\ No newline at end of file
diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/query/enums/DefaultEnumHandler.java b/li.strolch.agent/src/main/java/li/strolch/runtime/query/enums/DefaultEnumHandler.java
index b68b985dc..110ba3961 100644
--- a/li.strolch.agent/src/main/java/li/strolch/runtime/query/enums/DefaultEnumHandler.java
+++ b/li.strolch.agent/src/main/java/li/strolch/runtime/query/enums/DefaultEnumHandler.java
@@ -97,6 +97,7 @@ public class DefaultEnumHandler extends StrolchComponent implements EnumHandler
}
StrolchEnum strolchEnum = new StrolchEnum(name, locale, values);
+ tx.commitOnClose();
return strolchEnum;
}
}
diff --git a/li.strolch.agent/src/test/java/li/strolch/agent/ComponentContainerTest.java b/li.strolch.agent/src/test/java/li/strolch/agent/ComponentContainerTest.java
index c27395428..44e507d33 100644
--- a/li.strolch.agent/src/test/java/li/strolch/agent/ComponentContainerTest.java
+++ b/li.strolch.agent/src/test/java/li/strolch/agent/ComponentContainerTest.java
@@ -201,6 +201,7 @@ public class ComponentContainerTest {
Resource queriedRes = resourceDao.queryBy("Test", "@testRes0");
assertNotNull(queriedRes);
assertEquals("@testRes0", queriedRes.getId());
+ tx.commitOnClose();
}
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
@@ -209,6 +210,7 @@ public class ComponentContainerTest {
Order queriedOrder = orderDao.queryBy("Test", "@testOrder0");
assertNotNull(queriedOrder);
assertEquals("@testOrder0", queriedOrder.getId());
+ tx.commitOnClose();
}
}
@@ -223,6 +225,7 @@ public class ComponentContainerTest {
Resource queriedRes = resourceMap.getBy(tx, "Test", "@testRes1");
assertNotNull(queriedRes);
assertEquals("@testRes1", queriedRes.getId());
+ tx.commitOnClose();
}
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
@@ -231,6 +234,7 @@ public class ComponentContainerTest {
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
assertNotNull(queriedOrder);
assertEquals("@testOrder1", queriedOrder.getId());
+ tx.commitOnClose();
}
}
@@ -251,6 +255,7 @@ public class ComponentContainerTest {
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
assertNotNull(queriedOrder);
assertEquals("@testOrder1", queriedOrder.getId());
+ tx.commitOnClose();
}
try (StrolchTransaction tx = container.getRealm("myRealm").openTx(certificate, "test")) {
@@ -267,6 +272,7 @@ public class ComponentContainerTest {
assertEquals("MyRealmOrder", myRealmOrder.getId());
Order otherRealmOrder = orderMap.getBy(tx, "TestType", "OtherRealmOrder");
assertNull(otherRealmOrder);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = container.getRealm("otherRealm").openTx(certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap();
@@ -282,6 +288,7 @@ public class ComponentContainerTest {
assertEquals("OtherRealmOrder", otherRealmOrder.getId());
Order myRealmOrder = orderMap.getBy(tx, "TestType", "MyRealmOrder");
assertNull(myRealmOrder);
+ tx.commitOnClose();
}
}
diff --git a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/FindByLocatorTest.java b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/FindByLocatorTest.java
index da637ad3b..8beb7d7dd 100644
--- a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/FindByLocatorTest.java
+++ b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/FindByLocatorTest.java
@@ -86,6 +86,8 @@ public class FindByLocatorTest {
Locator locResIntegerState = Locator.valueOf("Resource/TestType/MyTestResource/State/@integerState");
IntegerTimedState integerS = tx.findElement(locResIntegerState);
assertNotNull("Should have found a IntegerTimedState with the locator " + locResIntegerState, integerS);
+
+ tx.commitOnClose();
}
}
}
diff --git a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/QueryTest.java b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/QueryTest.java
index 5fb4da42c..5155a5eec 100644
--- a/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/QueryTest.java
+++ b/li.strolch.agent/src/test/java/li/strolch/runtime/query/inmemory/QueryTest.java
@@ -72,6 +72,7 @@ public class QueryTest {
res1.addParameter(BAG_ID, iP);
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1);
+ tx.commitOnClose();
}
ResourceQuery query = ResourceQuery.query("MyType");
@@ -85,6 +86,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getResourceDao(tx));
+ tx.commitOnClose();
}
assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId());
@@ -104,6 +106,7 @@ public class QueryTest {
o1.addParameter(BAG_ID, iP);
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getOrderMap().add(tx, o1);
+ tx.commitOnClose();
}
OrderQuery query = OrderQuery.query("MyType");
@@ -117,6 +120,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getOrderDao(tx));
+ tx.commitOnClose();
}
assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId());
@@ -134,6 +138,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1);
+ tx.commitOnClose();
}
ResourceQuery query = ResourceQuery.query("MyType");
@@ -143,6 +148,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId());
@@ -160,6 +166,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1);
+ tx.commitOnClose();
}
ResourceQuery query = ResourceQuery.query("MyType");
@@ -169,6 +176,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(0, result.size());
}
@@ -185,6 +193,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1);
+ tx.commitOnClose();
}
ResourceQuery query = ResourceQuery.query("MyType");
@@ -194,6 +203,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId());
@@ -211,6 +221,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1);
+ tx.commitOnClose();
}
ResourceQuery query = ResourceQuery.query("MyType");
@@ -220,6 +231,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(0, result.size());
}
@@ -238,6 +250,7 @@ public class QueryTest {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1);
tx.getResourceMap().add(tx, res2);
+ tx.commitOnClose();
}
{
@@ -246,6 +259,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(1, result.size());
assertEquals("@2", result.get(0).getId());
@@ -257,6 +271,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId());
@@ -268,6 +283,7 @@ public class QueryTest {
List result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query);
+ tx.commitOnClose();
}
assertEquals(0, result.size());
}
diff --git a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlInitializer.java b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlInitializer.java
index 35fef9ef6..6a562ef22 100644
--- a/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlInitializer.java
+++ b/li.strolch.persistence.postgresql/src/main/java/li/strolch/persistence/postgresql/PostgreSqlInitializer.java
@@ -83,6 +83,7 @@ public abstract class PostgreSqlInitializer implements SystemUserAction {
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(listener, dataStoreF);
handler.parseFile();
statistics = handler.getStatistics();
+ tx.commitOnClose();
}
logger.info(MessageFormat.format("Realm {0} initialization statistics: {1}", realmName, statistics));
}
diff --git a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/AuditQueryTest.java b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/AuditQueryTest.java
index 4ccab6ede..0718a2f48 100644
--- a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/AuditQueryTest.java
+++ b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/AuditQueryTest.java
@@ -151,6 +151,8 @@ public class AuditQueryTest {
randomAudit.setAction("create");
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
auditTrail.add(tx, randomAudit);
+
+ tx.commitOnClose();
}
}
diff --git a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/ObserverUpdateTest.java b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/ObserverUpdateTest.java
index a3016b68f..aba20da21 100644
--- a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/ObserverUpdateTest.java
+++ b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/ObserverUpdateTest.java
@@ -126,12 +126,14 @@ public class ObserverUpdateTest {
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = realm.openTx(certificate, "test")) { //$NON-NLS-1$
tx.getOrderMap().add(tx, newOrder);
+ tx.commitOnClose();
}
// create resource
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = realm.openTx(certificate, "test");) { //$NON-NLS-1$
tx.getResourceMap().add(tx, newResource);
+ tx.commitOnClose();
}
assertEquals(2, observer.results.size());
diff --git a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/QueryTest.java b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/QueryTest.java
index 2c78409b7..c4a01b0e9 100644
--- a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/QueryTest.java
+++ b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/QueryTest.java
@@ -127,6 +127,8 @@ public class QueryTest {
resourceMap.add(tx, ModelGenerator.createResource("@4", "Resource 4", "MyType2"));
resourceMap.add(tx, ModelGenerator.createResource("@5", "Resource 5", "MyType2"));
resourceMap.add(tx, ModelGenerator.createResource("@6", "Resource 6", "MyType2"));
+
+ tx.commitOnClose();
}
}
diff --git a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/RealmTest.java b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/RealmTest.java
index 462865748..b8f128cd5 100644
--- a/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/RealmTest.java
+++ b/li.strolch.persistence.postgresql/src/test/java/li/strolch/persistence/postgresql/dao/test/RealmTest.java
@@ -91,11 +91,13 @@ public class RealmTest extends AbstractModelTest {
Resource expectedRes1 = ModelGenerator.createResource(expectedId1, "Bla bla", type); //$NON-NLS-1$
try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) {
tx.getResourceMap().add(tx, expectedRes1);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) {
Resource res = tx.getResourceMap().getBy(tx, type, expectedId1);
assertEquals("Should find object previously added in same realm!", expectedRes1, res); //$NON-NLS-1$
+ tx.commitOnClose();
}
}
@@ -105,11 +107,13 @@ public class RealmTest extends AbstractModelTest {
Resource expectedRes2 = ModelGenerator.createResource(expectedId2, "Bla bla", type); //$NON-NLS-1$
try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
tx.getResourceMap().add(tx, expectedRes2);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
Resource res = tx.getResourceMap().getBy(tx, type, expectedId2);
assertEquals("Should find object previously added in same realm!", expectedRes2, res); //$NON-NLS-1$
+ tx.commitOnClose();
}
}
@@ -118,6 +122,7 @@ public class RealmTest extends AbstractModelTest {
try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
Resource res = tx.getResourceMap().getBy(tx, type, expectedId1);
assertNull("Should not find object added in differenct realm!", res); //$NON-NLS-1$
+ tx.commitOnClose();
}
}
}
diff --git a/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java
index a749056fc..d6231493c 100644
--- a/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java
+++ b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java
@@ -68,6 +68,7 @@ public class ExistingDbTest {
Order order = tx.getOrderMap().getBy(tx, "MyType", "@1"); //$NON-NLS-1$//$NON-NLS-2$
assertNotNull("Should be able to read existing element from db", order); //$NON-NLS-1$
+ tx.commitOnClose();
}
}
}
diff --git a/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java
index 22ff19569..b4b4affd4 100644
--- a/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java
+++ b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java
@@ -121,12 +121,14 @@ public class ObserverUpdateTest {
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = realm.openTx(certificate, TEST)) {
tx.getOrderMap().add(tx, newOrder);
+ tx.commitOnClose();
}
// create resource
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = realm.openTx(certificate, TEST)) {
tx.getResourceMap().add(tx, newResource);
+ tx.commitOnClose();
}
assertEquals(2, observer.results.size());
diff --git a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java
index 99a56c64b..dc3668b51 100644
--- a/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java
+++ b/li.strolch.rest/src/main/java/li/strolch/rest/endpoint/Inspector.java
@@ -96,6 +96,7 @@ public class Inspector {
size += tx.getOrderMap().querySize(tx);
RealmOverview realmOverview = new RealmOverview(realmName, size);
realmOverviews.add(realmOverview);
+ tx.commitOnClose();
}
}
@@ -146,6 +147,8 @@ public class Inspector {
orderOverview.setNrOfElements(orderMap.querySize(tx));
orderOverview.setTypes(orderMap.getTypes(tx));
elementMapOverviews.add(orderOverview);
+
+ tx.commitOnClose();
}
RealmDetail modelOverview = new RealmDetail(elementMapOverviews);
@@ -189,6 +192,7 @@ public class Inspector {
}
resourcesOverview = new ElementMapOverview(ElementMapType.RESOURCE.getName(), typeOverviews);
+ tx.commitOnClose();
}
GenericEntity entity = new GenericEntity(resourcesOverview,
@@ -232,6 +236,7 @@ public class Inspector {
}
ordersOverview = new ElementMapOverview(ElementMapType.ORDER.getName(), typeOverviews);
+ tx.commitOnClose();
}
GenericEntity entity = new GenericEntity(ordersOverview,
@@ -278,6 +283,7 @@ public class Inspector {
elementOverviews.add(resourceOverview);
}
typeDetail = new TypeDetail(type, elementOverviews);
+ tx.commitOnClose();
}
GenericEntity entity = new GenericEntity(typeDetail, TypeDetail.class) {
@@ -319,6 +325,7 @@ public class Inspector {
elementOverviews.add(orderOverview);
}
typeDetail = new TypeDetail(type, elementOverviews);
+ tx.commitOnClose();
}
GenericEntity entity = new GenericEntity(typeDetail, TypeDetail.class) {
@@ -357,6 +364,7 @@ public class Inspector {
Resource resource;
try (StrolchTransaction tx = openTx(cert, realm)) {
resource = tx.getResourceMap().getBy(tx, type, id);
+ tx.commitOnClose();
}
if (resource == null) {
throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$
@@ -379,6 +387,7 @@ public class Inspector {
Order order;
try (StrolchTransaction tx = openTx(cert, realm)) {
order = tx.getOrderMap().getBy(tx, type, id);
+ tx.commitOnClose();
}
if (order == null) {
throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$
diff --git a/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java b/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java
index 77affbd3e..6135d451e 100644
--- a/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java
+++ b/li.strolch.service/src/main/java/li/strolch/service/AddOrderCollectionService.java
@@ -44,6 +44,7 @@ public class AddOrderCollectionService extends
AddOrderCollectionCommand command = new AddOrderCollectionCommand(getContainer(), tx);
command.setOrders(arg.orders);
tx.addCommand(command);
+ tx.commitOnClose();
}
return ServiceResult.success();
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 01d82e678..27460afcb 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
@@ -41,6 +41,7 @@ public class AddOrderService extends AbstractService types = auditTrail.getTypes(tx);
assertEquals(1, types.size());
assertTrue(types.contains(audit.getElementType()));
+ tx.commitOnClose();
}
// has
@@ -112,34 +114,40 @@ public class AuditModelTestRunner {
dbAudit = auditTrail.getBy(tx, "Foo", audit.getId());
assertNull(dbAudit);
+ tx.commitOnClose();
}
// remove
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.remove(tx, audit);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
assertNull(dbAudit);
+ tx.commitOnClose();
}
// update
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.add(tx, audit);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
dbAudit.setAction("Foo");
auditTrail.update(tx, dbAudit);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
assertEquals("Foo", dbAudit.getAction());
+ tx.commitOnClose();
}
}
@@ -155,6 +163,7 @@ public class AuditModelTestRunner {
assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), containsRange));
assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), earlierRange));
assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), laterRange));
+ tx.commitOnClose();
}
}
@@ -172,6 +181,7 @@ public class AuditModelTestRunner {
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.addAll(tx, audits);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@@ -186,17 +196,20 @@ public class AuditModelTestRunner {
assertEquals(0, allElements.size());
allElements = auditTrail.getAllElements(tx, "FooBar", laterRange);
assertEquals(0, allElements.size());
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.removeAll(tx, audits);
assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange));
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange));
+ tx.commitOnClose();
}
}
@@ -215,6 +228,7 @@ public class AuditModelTestRunner {
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.addAll(tx, audits);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@@ -232,6 +246,7 @@ public class AuditModelTestRunner {
}
auditTrail.updateAll(tx, allElements);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@@ -240,6 +255,7 @@ public class AuditModelTestRunner {
for (Audit dbAudit : allElements) {
assertEquals("Foo", dbAudit.getAction());
}
+ tx.commitOnClose();
}
}
@@ -271,6 +287,7 @@ public class AuditModelTestRunner {
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.addAll(tx, audits);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@@ -279,6 +296,7 @@ public class AuditModelTestRunner {
assertEquals(5, auditTrail.querySize(tx, "BarBarBar", containsRange));
assertEquals(5, auditTrail.querySize(tx, "FooFooFoo", containsRange));
assertEquals(5, auditTrail.querySize(tx, "BarFooBar", containsRange));
+ tx.commitOnClose();
}
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@@ -291,6 +309,7 @@ public class AuditModelTestRunner {
assertEquals(5, auditTrail.removeAll(tx, "BarFooBar", containsRange));
assertEquals(0, auditTrail.querySize(tx, containsRange));
+ tx.commitOnClose();
}
}
}
@@ -307,6 +326,7 @@ public class AuditModelTestRunner {
}
assertEquals(0, auditTrail.querySize(tx, dateRange));
+ tx.commitOnClose();
}
}
diff --git a/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java
index 59fc3f4f2..604ae929c 100644
--- a/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java
+++ b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java
@@ -49,6 +49,7 @@ public class OrderModelTestRunner {
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().add(tx, newOrder);
+ tx.commitOnClose();
}
}
@@ -57,6 +58,7 @@ public class OrderModelTestRunner {
// remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx));
+ tx.commitOnClose();
}
// create three orders
@@ -67,6 +69,7 @@ public class OrderModelTestRunner {
tx.getOrderMap().add(tx, order1);
tx.getOrderMap().add(tx, order2);
tx.getOrderMap().add(tx, order3);
+ tx.commitOnClose();
}
// query size
@@ -85,6 +88,7 @@ public class OrderModelTestRunner {
size = tx.getOrderMap().querySize(tx, "NonExistingType");
assertEquals("Should have zero objects of type 'NonExistingType'", 0, size);
+ tx.commitOnClose();
}
}
@@ -94,12 +98,14 @@ public class OrderModelTestRunner {
Order newOrder = createOrder(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().add(tx, newOrder);
+ tx.commitOnClose();
}
// read
Order readOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
readOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
+ tx.commitOnClose();
}
assertNotNull("Should read Order with id " + ID, readOrder);
@@ -109,12 +115,14 @@ public class OrderModelTestRunner {
sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().update(tx, readOrder);
+ tx.commitOnClose();
}
// read updated
Order updatedOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
+ tx.commitOnClose();
}
assertNotNull("Should read Order with id " + ID, updatedOrder);
if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED)
@@ -125,12 +133,14 @@ public class OrderModelTestRunner {
// delete
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().remove(tx, readOrder);
+ tx.commitOnClose();
}
// fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
Order order = tx.getOrderMap().getBy(tx, TYPE, ID);
assertNull("Should no read Order with id " + ID, order);
+ tx.commitOnClose();
}
}
@@ -155,6 +165,7 @@ public class OrderModelTestRunner {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
OrderMap orderMap = tx.getOrderMap();
orderMap.removeAll(tx, orderMap.getAllElements(tx));
+ tx.commitOnClose();
}
{
@@ -162,11 +173,13 @@ public class OrderModelTestRunner {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
OrderMap orderMap = tx.getOrderMap();
assertEquals(0, orderMap.querySize(tx));
+ tx.commitOnClose();
}
// now add some orders
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getOrderMap().addAll(tx, orders);
+ tx.commitOnClose();
}
// make sure we have our expected size
@@ -174,11 +187,13 @@ public class OrderModelTestRunner {
OrderMap orderMap = tx.getOrderMap();
assertEquals(orders.size(), orderMap.querySize(tx));
assertEquals(5, orderMap.querySize(tx, "MyType3"));
+ tx.commitOnClose();
}
// now use the remove all by type
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getOrderMap().removeAllBy(tx, "MyType3");
+ tx.commitOnClose();
}
// again make sure we have our expected size
@@ -186,24 +201,28 @@ public class OrderModelTestRunner {
OrderMap orderMap = tx.getOrderMap();
assertEquals(orders.size() - 5, orderMap.querySize(tx));
assertEquals(0, orderMap.querySize(tx, "MyType3"));
+ tx.commitOnClose();
}
// now use the remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
long removed = tx.getOrderMap().removeAll(tx);
assertEquals(orders.size() - 5, removed);
+ tx.commitOnClose();
}
// again make sure we have our expected size
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
OrderMap orderMap = tx.getOrderMap();
assertEquals(0, orderMap.querySize(tx));
+ tx.commitOnClose();
}
}
// now add all again
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getOrderMap().addAll(tx, orders);
+ tx.commitOnClose();
}
Set expectedTypes = new HashSet<>();
@@ -215,6 +234,7 @@ public class OrderModelTestRunner {
List allOrders = tx.getOrderMap().getAllElements(tx);
Collections.sort(allOrders, comparator);
assertEquals(orders, allOrders);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@@ -233,6 +253,7 @@ public class OrderModelTestRunner {
List ordersByType = orderMap.getElementsBy(tx, type);
assertEquals(5, ordersByType.size());
}
+ tx.commitOnClose();
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@@ -242,6 +263,7 @@ public class OrderModelTestRunner {
assertNotNull(order);
order = tx.getOrderMap().getBy(tx, "MyType3", "@00000011");
assertNotNull(order);
+ tx.commitOnClose();
}
}
}
diff --git a/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java
index 4725a53e7..b0d254452 100644
--- a/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java
+++ b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java
@@ -49,6 +49,7 @@ public class ResourceModelTestRunner {
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().add(tx, newResource);
+ tx.commitOnClose();
}
}
@@ -57,6 +58,7 @@ public class ResourceModelTestRunner {
// remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx));
+ tx.commitOnClose();
}
// create three resources
@@ -67,6 +69,7 @@ public class ResourceModelTestRunner {
tx.getResourceMap().add(tx, resource1);
tx.getResourceMap().add(tx, resource2);
tx.getResourceMap().add(tx, resource3);
+ tx.commitOnClose();
}
// query size
@@ -85,6 +88,7 @@ public class ResourceModelTestRunner {
size = tx.getResourceMap().querySize(tx, "NonExistingType");
assertEquals("Should have zero objects of type 'NonExistingType'", 0, size);
+ tx.commitOnClose();
}
}
@@ -94,12 +98,14 @@ public class ResourceModelTestRunner {
Resource newResource = createResource(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().add(tx, newResource);
+ tx.commitOnClose();
}
// read
Resource readResource = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
readResource = tx.getResourceMap().getBy(tx, TYPE, ID);
+ tx.commitOnClose();
}
assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$
@@ -109,12 +115,14 @@ public class ResourceModelTestRunner {
sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().update(tx, readResource);
+ tx.commitOnClose();
}
// read updated
Resource updatedResource = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID);
+ tx.commitOnClose();
}
assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$
if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED)
@@ -125,12 +133,14 @@ public class ResourceModelTestRunner {
// delete
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().remove(tx, readResource);
+ tx.commitOnClose();
}
// fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID);
assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$
+ tx.commitOnClose();
}
}
@@ -155,6 +165,7 @@ public class ResourceModelTestRunner {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap();
resourceMap.removeAll(tx, resourceMap.getAllElements(tx));
+ tx.commitOnClose();
}
{
@@ -162,11 +173,13 @@ public class ResourceModelTestRunner {
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap();
assertEquals(0, resourceMap.querySize(tx));
+ tx.commitOnClose();
}
// now add some resources
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getResourceMap().addAll(tx, resources);
+ tx.commitOnClose();
}
// make sure we have our expected size
@@ -174,11 +187,13 @@ public class ResourceModelTestRunner {
ResourceMap resourceMap = tx.getResourceMap();
assertEquals(resources.size(), resourceMap.querySize(tx));
assertEquals(5, resourceMap.querySize(tx, "MyType3"));
+ tx.commitOnClose();
}
// now use the remove all by type
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getResourceMap().removeAllBy(tx, "MyType3");
+ tx.commitOnClose();
}
// again make sure we have our expected size
@@ -186,24 +201,28 @@ public class ResourceModelTestRunner {
ResourceMap resourceMap = tx.getResourceMap();
assertEquals(resources.size() - 5, resourceMap.querySize(tx));
assertEquals(0, resourceMap.querySize(tx, "MyType3"));
+ tx.commitOnClose();
}
// now use the remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
long removed = tx.getResourceMap().removeAll(tx);
assertEquals(resources.size() - 5, removed);
+ tx.commitOnClose();
}
// again make sure we have our expected size
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap();
assertEquals(0, resourceMap.querySize(tx));
+ tx.commitOnClose();
}
}
// now add all again
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getResourceMap().addAll(tx, resources);
+ tx.commitOnClose();
}
Set expectedTypes = new HashSet<>();
@@ -215,6 +234,7 @@ public class ResourceModelTestRunner {
List allResources = tx.getResourceMap().getAllElements(tx);
Collections.sort(allResources, comparator);
assertEquals(resources, allResources);
+ tx.commitOnClose();
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@@ -233,6 +253,7 @@ public class ResourceModelTestRunner {
List resourcesByType = resourceMap.getElementsBy(tx, type);
assertEquals(5, resourcesByType.size());
}
+ tx.commitOnClose();
}
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@@ -242,6 +263,7 @@ public class ResourceModelTestRunner {
assertNotNull(resource);
resource = tx.getResourceMap().getBy(tx, "MyType3", "@00000011");
assertNotNull(resource);
+ tx.commitOnClose();
}
}
}