[Major] Refactored how a TX is closed

- So sadly just auto closing a TX using try-resource from Java7 is a bad idea.
- Doing that leads to problems when an exception is thrown, then the close is called (duh) but this leads to commit being called.
- Since the Java language does not offer a decent way to detect if the close is being called in the context of an exception i was forced to add a tx.commitOnClose() and tx.rollbackOnClose().
- The default is that when a TX is opened, then the close strategy is rollback; the API user must call tx.commitOnClose() before the TX is closed by the braces, or as late as possible, to make sure that if an exception is thrown the transaction is rolled back, and not committed.
- The API was also extended with a tx.fail(msg):StrolchTransactionException so that if the implementor detects an unrecoverable error, one can write: throw tx.fail(“my reason”);

This was sadly an unavoidable late 1.0.0 change
Conflicts:
	li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java
This commit is contained in:
Robert von Burg 2015-02-03 23:18:31 +01:00
parent 9532c97ef1
commit 46ccb921df
44 changed files with 257 additions and 35 deletions

View File

@ -115,6 +115,8 @@ public class CachedRealm extends InternalStrolchRealm {
nrOfResources++; nrOfResources++;
} }
} }
tx.commitOnClose();
} }
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) { try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
@ -127,6 +129,8 @@ public class CachedRealm extends InternalStrolchRealm {
nrOfOrders++; nrOfOrders++;
} }
} }
tx.commitOnClose();
} }
long duration = System.nanoTime() - start; long duration = System.nanoTime() - start;

View File

@ -101,10 +101,12 @@ public class TransactionalRealm extends InternalStrolchRealm {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) { try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
nrOfOrders = this.orderMap.getAllKeys(tx).size(); nrOfOrders = this.orderMap.getAllKeys(tx).size();
tx.commitOnClose();
} }
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) { try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
nrOfResources = this.resourceMap.getAllKeys(tx).size(); nrOfResources = this.resourceMap.getAllKeys(tx).size();
tx.commitOnClose();
} }
long duration = System.nanoTime() - start; long duration = System.nanoTime() - start;

View File

@ -118,6 +118,7 @@ public class TransientRealm extends InternalStrolchRealm {
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile); XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile);
handler.parseFile(); handler.parseFile();
statistics = handler.getStatistics(); statistics = handler.getStatistics();
tx.commitOnClose();
} }
String durationS = StringHelper.formatNanoDuration(statistics.durationNanos); String durationS = StringHelper.formatNanoDuration(statistics.durationNanos);

View File

@ -112,7 +112,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
this.commands = new ArrayList<>(); this.commands = new ArrayList<>();
this.lockedElements = new HashSet<>(); this.lockedElements = new HashSet<>();
this.closeStrategy = TransactionCloseStrategy.COMMIT; this.closeStrategy = TransactionCloseStrategy.ROLLBACK;
this.txResult = new TransactionResult(getRealmName(), System.nanoTime(), new Date()); this.txResult = new TransactionResult(getRealmName(), System.nanoTime(), new Date());
this.txResult.setState(TransactionState.OPEN); this.txResult.setState(TransactionState.OPEN);
} }
@ -156,16 +156,31 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return certificate; return certificate;
} }
@Override private void setCloseStrategy(TransactionCloseStrategy closeStrategy) {
public void setCloseStrategy(TransactionCloseStrategy closeStrategy) {
this.closeStrategy = closeStrategy; this.closeStrategy = closeStrategy;
} }
@Override @Override
public void close() throws StrolchPersistenceException { public void close() throws StrolchTransactionException {
this.closeStrategy.close(this); 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 @Override
public void setSuppressUpdates(boolean suppressUpdates) { public void setSuppressUpdates(boolean suppressUpdates) {
this.suppressUpdates = suppressUpdates; this.suppressUpdates = suppressUpdates;
@ -492,7 +507,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
String msg = "Strolch Transaction for realm {0} failed due to {1}"; //$NON-NLS-1$ String msg = "Strolch Transaction for realm {0} failed due to {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getRealmName(), e.getMessage()); msg = MessageFormat.format(msg, getRealmName(), e.getMessage());
throw new StrolchPersistenceException(msg, e); throw new StrolchTransactionException(msg, e);
} finally { } finally {
releaseElementLocks(); releaseElementLocks();
@ -620,7 +635,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
String msg = "Strolch Transaction for realm {0} failed due to {1}\n{2}"; //$NON-NLS-1$ 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()); msg = MessageFormat.format(msg, getRealmName(), e.getMessage(), sb.toString());
throw new StrolchPersistenceException(msg, e); throw new StrolchTransactionException(msg, e);
} }
private boolean isAuditTrailEnabled() { private boolean isAuditTrailEnabled() {

View File

@ -61,6 +61,7 @@ import li.strolch.service.api.Command;
* StrolchRealm realm = strolchAgent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM); * StrolchRealm realm = strolchAgent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM);
* try(StrolchTransaction tx = realm.openTx(certificate, getClass())){ * try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
* // do work e.g. add commands * // do work e.g. add commands
* tx.commitOnClose();
* } * }
* </code> * </code>
* *
@ -132,28 +133,18 @@ public interface StrolchTransaction extends AutoCloseable {
public PersistenceHandler getPersistenceHandler(); public PersistenceHandler getPersistenceHandler();
/** /**
* Sets the strategy to be used when closing the transaction when {@link #close()} is called. The default is * DO NOT CALL THIS METHOD. If the currently set close strategy is {@link TransactionCloseStrategy#COMMIT}, then
* {@link TransactionCloseStrategy#COMMIT}, but if the user of the transaction decides it wants to use a different * when the transaction is closed, this method is called and all registered {@link Command} are performed, locks on
* strategy, then it may set it using this method * objects are released and any other resources are released
*
* @param closeStrategy
* the new {@link TransactionCloseStrategy} to use
*/ */
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 * DO NOT CALL THIS METHOD. If the currently set close strategy is {@link TransactionCloseStrategy#ROLLBACK}, then
* closed, this method is called and all registered {@link Command} are performed, locks on objects are released and * when the transaction is closed, no further actions are performed and any {@link Command} which were performed
* any other resources are released * have their {@link Command#undo()} method called and any DB connections are also rolled back
*/ */
public void autoCloseableCommit(); public void autoCloseableRollback() throws StrolchTransactionException;
/**
* 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();
/** /**
* <p> * <p>
@ -166,13 +157,34 @@ public interface StrolchTransaction extends AutoCloseable {
* StrolchRealm realm = strolchAgent.getContainer().getRealm("defaultRealm"); * StrolchRealm realm = strolchAgent.getContainer().getRealm("defaultRealm");
* try(StrolchTransaction tx = realm.openTx(certificate, getClass())){ * try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
* // do work * // do work
* tx.commitOnClose();
* } * }
* </code> * </code>
* *
* After the block is closed, the transaction is automatically closed and all allocated resources are released * After the block is closed, the transaction is automatically closed and all allocated resources are released
*/ */
@Override @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);
/** /**
* @return true if the transaction is still open, i.e. not being closed or rolling back, committing, etc. * @return true if the transaction is still open, i.e. not being closed or rolling back, committing, etc.

View File

@ -0,0 +1,39 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 <eitch@eitchnet.ch>
*/
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);
}
}

View File

@ -15,23 +15,23 @@
*/ */
package li.strolch.persistence.api; package li.strolch.persistence.api;
import li.strolch.exception.StrolchException;
public enum TransactionCloseStrategy { public enum TransactionCloseStrategy {
COMMIT() { COMMIT() {
@Override @Override
public void close(StrolchTransaction tx) { public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableCommit(); tx.autoCloseableCommit();
} }
}, },
ROLLBACK() { ROLLBACK() {
@Override @Override
public void close(StrolchTransaction tx) { public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableRollback(); tx.autoCloseableRollback();
} }
}; };
/** public abstract void close(StrolchTransaction tx) throws StrolchException;
* @param tx
*/
public abstract void close(StrolchTransaction tx);
} }

View File

@ -97,6 +97,7 @@ public class DefaultEnumHandler extends StrolchComponent implements EnumHandler
} }
StrolchEnum strolchEnum = new StrolchEnum(name, locale, values); StrolchEnum strolchEnum = new StrolchEnum(name, locale, values);
tx.commitOnClose();
return strolchEnum; return strolchEnum;
} }
} }

View File

@ -201,6 +201,7 @@ public class ComponentContainerTest {
Resource queriedRes = resourceDao.queryBy("Test", "@testRes0"); Resource queriedRes = resourceDao.queryBy("Test", "@testRes0");
assertNotNull(queriedRes); assertNotNull(queriedRes);
assertEquals("@testRes0", queriedRes.getId()); assertEquals("@testRes0", queriedRes.getId());
tx.commitOnClose();
} }
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
@ -209,6 +210,7 @@ public class ComponentContainerTest {
Order queriedOrder = orderDao.queryBy("Test", "@testOrder0"); Order queriedOrder = orderDao.queryBy("Test", "@testOrder0");
assertNotNull(queriedOrder); assertNotNull(queriedOrder);
assertEquals("@testOrder0", queriedOrder.getId()); assertEquals("@testOrder0", queriedOrder.getId());
tx.commitOnClose();
} }
} }
@ -223,6 +225,7 @@ public class ComponentContainerTest {
Resource queriedRes = resourceMap.getBy(tx, "Test", "@testRes1"); Resource queriedRes = resourceMap.getBy(tx, "Test", "@testRes1");
assertNotNull(queriedRes); assertNotNull(queriedRes);
assertEquals("@testRes1", queriedRes.getId()); assertEquals("@testRes1", queriedRes.getId());
tx.commitOnClose();
} }
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { 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"); Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
assertNotNull(queriedOrder); assertNotNull(queriedOrder);
assertEquals("@testOrder1", queriedOrder.getId()); assertEquals("@testOrder1", queriedOrder.getId());
tx.commitOnClose();
} }
} }
@ -251,6 +255,7 @@ public class ComponentContainerTest {
Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1"); Order queriedOrder = orderMap.getBy(tx, "Test", "@testOrder1");
assertNotNull(queriedOrder); assertNotNull(queriedOrder);
assertEquals("@testOrder1", queriedOrder.getId()); assertEquals("@testOrder1", queriedOrder.getId());
tx.commitOnClose();
} }
try (StrolchTransaction tx = container.getRealm("myRealm").openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm("myRealm").openTx(certificate, "test")) {
@ -267,6 +272,7 @@ public class ComponentContainerTest {
assertEquals("MyRealmOrder", myRealmOrder.getId()); assertEquals("MyRealmOrder", myRealmOrder.getId());
Order otherRealmOrder = orderMap.getBy(tx, "TestType", "OtherRealmOrder"); Order otherRealmOrder = orderMap.getBy(tx, "TestType", "OtherRealmOrder");
assertNull(otherRealmOrder); assertNull(otherRealmOrder);
tx.commitOnClose();
} }
try (StrolchTransaction tx = container.getRealm("otherRealm").openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm("otherRealm").openTx(certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
@ -282,6 +288,7 @@ public class ComponentContainerTest {
assertEquals("OtherRealmOrder", otherRealmOrder.getId()); assertEquals("OtherRealmOrder", otherRealmOrder.getId());
Order myRealmOrder = orderMap.getBy(tx, "TestType", "MyRealmOrder"); Order myRealmOrder = orderMap.getBy(tx, "TestType", "MyRealmOrder");
assertNull(myRealmOrder); assertNull(myRealmOrder);
tx.commitOnClose();
} }
} }

View File

@ -86,6 +86,8 @@ public class FindByLocatorTest {
Locator locResIntegerState = Locator.valueOf("Resource/TestType/MyTestResource/State/@integerState"); Locator locResIntegerState = Locator.valueOf("Resource/TestType/MyTestResource/State/@integerState");
IntegerTimedState integerS = tx.findElement(locResIntegerState); IntegerTimedState integerS = tx.findElement(locResIntegerState);
assertNotNull("Should have found a IntegerTimedState with the locator " + locResIntegerState, integerS); assertNotNull("Should have found a IntegerTimedState with the locator " + locResIntegerState, integerS);
tx.commitOnClose();
} }
} }
} }

View File

@ -72,6 +72,7 @@ public class QueryTest {
res1.addParameter(BAG_ID, iP); res1.addParameter(BAG_ID, iP);
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1); tx.getResourceMap().add(tx, res1);
tx.commitOnClose();
} }
ResourceQuery query = ResourceQuery.query("MyType"); ResourceQuery query = ResourceQuery.query("MyType");
@ -85,6 +86,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getResourceDao(tx)); result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getResourceDao(tx));
tx.commitOnClose();
} }
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId()); assertEquals("@1", result.get(0).getId());
@ -104,6 +106,7 @@ public class QueryTest {
o1.addParameter(BAG_ID, iP); o1.addParameter(BAG_ID, iP);
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getOrderMap().add(tx, o1); tx.getOrderMap().add(tx, o1);
tx.commitOnClose();
} }
OrderQuery query = OrderQuery.query("MyType"); OrderQuery query = OrderQuery.query("MyType");
@ -117,6 +120,7 @@ public class QueryTest {
List<Order> result; List<Order> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getOrderDao(tx)); result = inMemoryQuery.doQuery(tx.getPersistenceHandler().getOrderDao(tx));
tx.commitOnClose();
} }
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId()); assertEquals("@1", result.get(0).getId());
@ -134,6 +138,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType"); Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1); tx.getResourceMap().add(tx, res1);
tx.commitOnClose();
} }
ResourceQuery query = ResourceQuery.query("MyType"); ResourceQuery query = ResourceQuery.query("MyType");
@ -143,6 +148,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId()); assertEquals("@1", result.get(0).getId());
@ -160,6 +166,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType"); Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1); tx.getResourceMap().add(tx, res1);
tx.commitOnClose();
} }
ResourceQuery query = ResourceQuery.query("MyType"); ResourceQuery query = ResourceQuery.query("MyType");
@ -169,6 +176,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(0, result.size()); assertEquals(0, result.size());
} }
@ -185,6 +193,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType"); Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1); tx.getResourceMap().add(tx, res1);
tx.commitOnClose();
} }
ResourceQuery query = ResourceQuery.query("MyType"); ResourceQuery query = ResourceQuery.query("MyType");
@ -194,6 +203,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId()); assertEquals("@1", result.get(0).getId());
@ -211,6 +221,7 @@ public class QueryTest {
Resource res1 = createResource("@1", "Test Resource", "MyType"); Resource res1 = createResource("@1", "Test Resource", "MyType");
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1); tx.getResourceMap().add(tx, res1);
tx.commitOnClose();
} }
ResourceQuery query = ResourceQuery.query("MyType"); ResourceQuery query = ResourceQuery.query("MyType");
@ -220,6 +231,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(0, result.size()); assertEquals(0, result.size());
} }
@ -238,6 +250,7 @@ public class QueryTest {
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
tx.getResourceMap().add(tx, res1); tx.getResourceMap().add(tx, res1);
tx.getResourceMap().add(tx, res2); tx.getResourceMap().add(tx, res2);
tx.commitOnClose();
} }
{ {
@ -246,6 +259,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals("@2", result.get(0).getId()); assertEquals("@2", result.get(0).getId());
@ -257,6 +271,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals("@1", result.get(0).getId()); assertEquals("@1", result.get(0).getId());
@ -268,6 +283,7 @@ public class QueryTest {
List<Resource> result; List<Resource> result;
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
result = tx.doQuery(query); result = tx.doQuery(query);
tx.commitOnClose();
} }
assertEquals(0, result.size()); assertEquals(0, result.size());
} }

View File

@ -83,6 +83,7 @@ public abstract class PostgreSqlInitializer implements SystemUserAction {
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(listener, dataStoreF); XmlModelSaxFileReader handler = new XmlModelSaxFileReader(listener, dataStoreF);
handler.parseFile(); handler.parseFile();
statistics = handler.getStatistics(); statistics = handler.getStatistics();
tx.commitOnClose();
} }
logger.info(MessageFormat.format("Realm {0} initialization statistics: {1}", realmName, statistics)); logger.info(MessageFormat.format("Realm {0} initialization statistics: {1}", realmName, statistics));
} }

View File

@ -151,6 +151,8 @@ public class AuditQueryTest {
randomAudit.setAction("create"); randomAudit.setAction("create");
randomAudit.setElementAccessed(randomAudit.getAccessType().name()); randomAudit.setElementAccessed(randomAudit.getAccessType().name());
auditTrail.add(tx, randomAudit); auditTrail.add(tx, randomAudit);
tx.commitOnClose();
} }
} }

View File

@ -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$ 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$ try (StrolchTransaction tx = realm.openTx(certificate, "test")) { //$NON-NLS-1$
tx.getOrderMap().add(tx, newOrder); tx.getOrderMap().add(tx, newOrder);
tx.commitOnClose();
} }
// create resource // create resource
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ 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$ try (StrolchTransaction tx = realm.openTx(certificate, "test");) { //$NON-NLS-1$
tx.getResourceMap().add(tx, newResource); tx.getResourceMap().add(tx, newResource);
tx.commitOnClose();
} }
assertEquals(2, observer.results.size()); assertEquals(2, observer.results.size());

View File

@ -127,6 +127,8 @@ public class QueryTest {
resourceMap.add(tx, ModelGenerator.createResource("@4", "Resource 4", "MyType2")); resourceMap.add(tx, ModelGenerator.createResource("@4", "Resource 4", "MyType2"));
resourceMap.add(tx, ModelGenerator.createResource("@5", "Resource 5", "MyType2")); resourceMap.add(tx, ModelGenerator.createResource("@5", "Resource 5", "MyType2"));
resourceMap.add(tx, ModelGenerator.createResource("@6", "Resource 6", "MyType2")); resourceMap.add(tx, ModelGenerator.createResource("@6", "Resource 6", "MyType2"));
tx.commitOnClose();
} }
} }

View File

@ -91,11 +91,13 @@ public class RealmTest extends AbstractModelTest {
Resource expectedRes1 = ModelGenerator.createResource(expectedId1, "Bla bla", type); //$NON-NLS-1$ Resource expectedRes1 = ModelGenerator.createResource(expectedId1, "Bla bla", type); //$NON-NLS-1$
try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) { try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) {
tx.getResourceMap().add(tx, expectedRes1); tx.getResourceMap().add(tx, expectedRes1);
tx.commitOnClose();
} }
try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) { try (StrolchTransaction tx = firstRealm.openTx(certificate, TEST)) {
Resource res = tx.getResourceMap().getBy(tx, type, expectedId1); Resource res = tx.getResourceMap().getBy(tx, type, expectedId1);
assertEquals("Should find object previously added in same realm!", expectedRes1, res); //$NON-NLS-1$ 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$ Resource expectedRes2 = ModelGenerator.createResource(expectedId2, "Bla bla", type); //$NON-NLS-1$
try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) { try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
tx.getResourceMap().add(tx, expectedRes2); tx.getResourceMap().add(tx, expectedRes2);
tx.commitOnClose();
} }
try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) { try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
Resource res = tx.getResourceMap().getBy(tx, type, expectedId2); Resource res = tx.getResourceMap().getBy(tx, type, expectedId2);
assertEquals("Should find object previously added in same realm!", expectedRes2, res); //$NON-NLS-1$ 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)) { try (StrolchTransaction tx = secondRealm.openTx(certificate, TEST)) {
Resource res = tx.getResourceMap().getBy(tx, type, expectedId1); Resource res = tx.getResourceMap().getBy(tx, type, expectedId1);
assertNull("Should not find object added in differenct realm!", res); //$NON-NLS-1$ assertNull("Should not find object added in differenct realm!", res); //$NON-NLS-1$
tx.commitOnClose();
} }
} }
} }

View File

@ -68,6 +68,7 @@ public class ExistingDbTest {
Order order = tx.getOrderMap().getBy(tx, "MyType", "@1"); //$NON-NLS-1$//$NON-NLS-2$ 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$ assertNotNull("Should be able to read existing element from db", order); //$NON-NLS-1$
tx.commitOnClose();
} }
} }
} }

View File

@ -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$ 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)) { try (StrolchTransaction tx = realm.openTx(certificate, TEST)) {
tx.getOrderMap().add(tx, newOrder); tx.getOrderMap().add(tx, newOrder);
tx.commitOnClose();
} }
// create resource // create resource
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
try (StrolchTransaction tx = realm.openTx(certificate, TEST)) { try (StrolchTransaction tx = realm.openTx(certificate, TEST)) {
tx.getResourceMap().add(tx, newResource); tx.getResourceMap().add(tx, newResource);
tx.commitOnClose();
} }
assertEquals(2, observer.results.size()); assertEquals(2, observer.results.size());

View File

@ -96,6 +96,7 @@ public class Inspector {
size += tx.getOrderMap().querySize(tx); size += tx.getOrderMap().querySize(tx);
RealmOverview realmOverview = new RealmOverview(realmName, size); RealmOverview realmOverview = new RealmOverview(realmName, size);
realmOverviews.add(realmOverview); realmOverviews.add(realmOverview);
tx.commitOnClose();
} }
} }
@ -146,6 +147,8 @@ public class Inspector {
orderOverview.setNrOfElements(orderMap.querySize(tx)); orderOverview.setNrOfElements(orderMap.querySize(tx));
orderOverview.setTypes(orderMap.getTypes(tx)); orderOverview.setTypes(orderMap.getTypes(tx));
elementMapOverviews.add(orderOverview); elementMapOverviews.add(orderOverview);
tx.commitOnClose();
} }
RealmDetail modelOverview = new RealmDetail(elementMapOverviews); RealmDetail modelOverview = new RealmDetail(elementMapOverviews);
@ -189,6 +192,7 @@ public class Inspector {
} }
resourcesOverview = new ElementMapOverview(ElementMapType.RESOURCE.getName(), typeOverviews); resourcesOverview = new ElementMapOverview(ElementMapType.RESOURCE.getName(), typeOverviews);
tx.commitOnClose();
} }
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview, GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview,
@ -232,6 +236,7 @@ public class Inspector {
} }
ordersOverview = new ElementMapOverview(ElementMapType.ORDER.getName(), typeOverviews); ordersOverview = new ElementMapOverview(ElementMapType.ORDER.getName(), typeOverviews);
tx.commitOnClose();
} }
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(ordersOverview, GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(ordersOverview,
@ -278,6 +283,7 @@ public class Inspector {
elementOverviews.add(resourceOverview); elementOverviews.add(resourceOverview);
} }
typeDetail = new TypeDetail(type, elementOverviews); typeDetail = new TypeDetail(type, elementOverviews);
tx.commitOnClose();
} }
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) { GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
@ -319,6 +325,7 @@ public class Inspector {
elementOverviews.add(orderOverview); elementOverviews.add(orderOverview);
} }
typeDetail = new TypeDetail(type, elementOverviews); typeDetail = new TypeDetail(type, elementOverviews);
tx.commitOnClose();
} }
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) { GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
@ -357,6 +364,7 @@ public class Inspector {
Resource resource; Resource resource;
try (StrolchTransaction tx = openTx(cert, realm)) { try (StrolchTransaction tx = openTx(cert, realm)) {
resource = tx.getResourceMap().getBy(tx, type, id); resource = tx.getResourceMap().getBy(tx, type, id);
tx.commitOnClose();
} }
if (resource == null) { if (resource == null) {
throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$ 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; Order order;
try (StrolchTransaction tx = openTx(cert, realm)) { try (StrolchTransaction tx = openTx(cert, realm)) {
order = tx.getOrderMap().getBy(tx, type, id); order = tx.getOrderMap().getBy(tx, type, id);
tx.commitOnClose();
} }
if (order == null) { if (order == null) {
throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$ throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$

View File

@ -44,6 +44,7 @@ public class AddOrderCollectionService extends
AddOrderCollectionCommand command = new AddOrderCollectionCommand(getContainer(), tx); AddOrderCollectionCommand command = new AddOrderCollectionCommand(getContainer(), tx);
command.setOrders(arg.orders); command.setOrders(arg.orders);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -41,6 +41,7 @@ public class AddOrderService extends AbstractService<AddOrderService.AddOrderArg
AddOrderCommand command = new AddOrderCommand(getContainer(), tx); AddOrderCommand command = new AddOrderCommand(getContainer(), tx);
command.setOrder(arg.order); command.setOrder(arg.order);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -44,6 +44,7 @@ public class AddResourceCollectionService extends
AddResourceCollectionCommand command = new AddResourceCollectionCommand(getContainer(), tx); AddResourceCollectionCommand command = new AddResourceCollectionCommand(getContainer(), tx);
command.setResources(arg.resources); command.setResources(arg.resources);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -41,6 +41,7 @@ public class AddResourceService extends AbstractService<AddResourceService.AddRe
AddResourceCommand command = new AddResourceCommand(getContainer(), tx); AddResourceCommand command = new AddResourceCommand(getContainer(), tx);
command.setResource(arg.resource); command.setResource(arg.resource);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -41,11 +41,11 @@ public class ClearModelService extends AbstractService<ClearModelArgument, Servi
ClearModelCommand command; ClearModelCommand command;
try (StrolchTransaction tx = openTx(arg.realm)) { try (StrolchTransaction tx = openTx(arg.realm)) {
command = new ClearModelCommand(getContainer(), tx); command = new ClearModelCommand(getContainer(), tx);
command.setClearOrders(arg.clearOrders); command.setClearOrders(arg.clearOrders);
command.setClearResources(arg.clearResources); command.setClearResources(arg.clearResources);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
ModelStatistics statistics = command.getStatistics(); ModelStatistics statistics = command.getStatistics();

View File

@ -52,7 +52,9 @@ public class RemoveOrderCollectionService extends
RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(getContainer(), tx); RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(getContainer(), tx);
command.setOrders(orders); command.setOrders(orders);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -44,7 +44,9 @@ public class RemoveOrderService extends AbstractService<RemoveOrderService.Remov
RemoveOrderCommand command = new RemoveOrderCommand(getContainer(), tx); RemoveOrderCommand command = new RemoveOrderCommand(getContainer(), tx);
command.setOrder(order); command.setOrder(order);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -52,7 +52,9 @@ public class RemoveResourceCollectionService extends
RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(getContainer(), tx); RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(getContainer(), tx);
command.setResources(resources); command.setResources(resources);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -44,7 +44,9 @@ public class RemoveResourceService extends AbstractService<RemoveResourceService
RemoveResourceCommand command = new RemoveResourceCommand(getContainer(), tx); RemoveResourceCommand command = new RemoveResourceCommand(getContainer(), tx);
command.setResource(resource); command.setResource(resource);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -43,7 +43,9 @@ public class UpdateOrderCollectionService extends
try (StrolchTransaction tx = openTx(arg.realm)) { try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(getContainer(), tx); UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(getContainer(), tx);
command.setOrders(arg.orders); command.setOrders(arg.orders);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -40,7 +40,9 @@ public class UpdateOrderService extends AbstractService<UpdateOrderService.Updat
try (StrolchTransaction tx = openTx(arg.realm)) { try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateOrderCommand command = new UpdateOrderCommand(getContainer(), tx); UpdateOrderCommand command = new UpdateOrderCommand(getContainer(), tx);
command.setOrder(arg.order); command.setOrder(arg.order);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -43,7 +43,9 @@ public class UpdateResourceCollectionService extends
try (StrolchTransaction tx = openTx(arg.realm)) { try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(getContainer(), tx); UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(getContainer(), tx);
command.setResources(arg.resources); command.setResources(arg.resources);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -40,7 +40,9 @@ public class UpdateResourceService extends AbstractService<UpdateResourceService
try (StrolchTransaction tx = openTx(arg.realm)) { try (StrolchTransaction tx = openTx(arg.realm)) {
UpdateResourceCommand command = new UpdateResourceCommand(getContainer(), tx); UpdateResourceCommand command = new UpdateResourceCommand(getContainer(), tx);
command.setResource(arg.resource); command.setResource(arg.resource);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -68,7 +68,9 @@ public class XmlExportModelService extends AbstractService<XmlExportModelArgumen
command.setDoResources(arg.doResources); command.setDoResources(arg.doResources);
command.setOrderTypes(arg.orderTypes); command.setOrderTypes(arg.orderTypes);
command.setResourceTypes(arg.resourceTypes); command.setResourceTypes(arg.resourceTypes);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
ModelStatistics statistics = command.getStatistics(); ModelStatistics statistics = command.getStatistics();

View File

@ -60,7 +60,9 @@ public class XmlImportModelService extends AbstractService<XmlImportModelArgumen
command.setUpdateResources(arg.updateResources); command.setUpdateResources(arg.updateResources);
command.setOrderTypes(arg.orderTypes); command.setOrderTypes(arg.orderTypes);
command.setResourceTypes(arg.resourceTypes); command.setResourceTypes(arg.resourceTypes);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
ModelStatistics statistics = command.getStatistics(); ModelStatistics statistics = command.getStatistics();

View File

@ -46,7 +46,9 @@ public class AddParameterService extends AbstractService<AddParameterService.Add
AddParameterCommand command = new AddParameterCommand(getContainer(), tx); AddParameterCommand command = new AddParameterCommand(getContainer(), tx);
command.setElement(element); command.setElement(element);
command.setParameter(arg.parameter); command.setParameter(arg.parameter);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -45,7 +45,9 @@ public class RemoveParameterService extends AbstractService<RemoveParameterServi
RemoveParameterCommand command = new RemoveParameterCommand(getContainer(), tx); RemoveParameterCommand command = new RemoveParameterCommand(getContainer(), tx);
command.setElement(parameter.getParent()); command.setElement(parameter.getParent());
command.setParameterId(parameter.getId()); command.setParameterId(parameter.getId());
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -54,6 +54,7 @@ public class SetParameterService extends AbstractService<SetParameterService.Set
command.setValueAsString(arg.valueAsString); command.setValueAsString(arg.valueAsString);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -87,11 +87,11 @@ public abstract class AbstractRealmCommandTest {
StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName); StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName);
try (StrolchTransaction tx = realm.openTx(certificate, "test")) { try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
Command command = getCommandInstance(runtimeMock.getContainer(), tx); Command command = getCommandInstance(runtimeMock.getContainer(), tx);
FailCommandFacade commandFacade = new FailCommandFacade(runtimeMock.getContainer(), tx, command); FailCommandFacade commandFacade = new FailCommandFacade(runtimeMock.getContainer(), tx, command);
tx.addCommand(commandFacade); tx.addCommand(commandFacade);
tx.commitOnClose();
} }
} }
@ -100,6 +100,7 @@ public abstract class AbstractRealmCommandTest {
try (StrolchTransaction tx = realm.openTx(certificate, "test")) { try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
Command command = getCommandInstance(runtimeMock.getContainer(), tx); Command command = getCommandInstance(runtimeMock.getContainer(), tx);
tx.addCommand(command); tx.addCommand(command);
tx.commitOnClose();
} }
} }

View File

@ -38,6 +38,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest {
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) { try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
assertEquals(0, tx.getResourceMap().querySize(tx)); assertEquals(0, tx.getResourceMap().querySize(tx));
assertEquals(0, tx.getOrderMap().querySize(tx)); assertEquals(0, tx.getOrderMap().querySize(tx));
tx.commitOnClose();
} }
} }
}; };
@ -58,6 +59,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest {
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) { try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
assertNotEquals(0, tx.getResourceMap().querySize(tx)); assertNotEquals(0, tx.getResourceMap().querySize(tx));
assertEquals(0, tx.getOrderMap().querySize(tx)); assertEquals(0, tx.getOrderMap().querySize(tx));
tx.commitOnClose();
} }
} }
}; };
@ -78,6 +80,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest {
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) { try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
assertNotEquals(0, tx.getOrderMap().querySize(tx)); assertNotEquals(0, tx.getOrderMap().querySize(tx));
assertEquals(0, tx.getResourceMap().querySize(tx)); assertEquals(0, tx.getResourceMap().querySize(tx));
tx.commitOnClose();
} }
} }
}; };
@ -88,5 +91,4 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest {
runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null); runServiceInAllRealmTypes(ClearModelService.class, arg, null, validator, null);
} }
} }

View File

@ -209,6 +209,8 @@ public class LockingTest {
if (arg.longRunning) if (arg.longRunning)
Thread.sleep(5000l); Thread.sleep(5000l);
tx.commitOnClose();
} }
return ServiceResult.success(); return ServiceResult.success();

View File

@ -20,6 +20,7 @@ public abstract class AbstractModelTest {
Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes()); Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes());
try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx(certificate, "test")) { try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx(certificate, "test")) {
tx.getOrderMap().getAllKeys(tx); tx.getOrderMap().getAllKeys(tx);
tx.commitOnClose();
} }
} }

View File

@ -92,6 +92,7 @@ public class AuditModelTestRunner {
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.add(tx, audit); auditTrail.add(tx, audit);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@ -99,6 +100,7 @@ public class AuditModelTestRunner {
Set<String> types = auditTrail.getTypes(tx); Set<String> types = auditTrail.getTypes(tx);
assertEquals(1, types.size()); assertEquals(1, types.size());
assertTrue(types.contains(audit.getElementType())); assertTrue(types.contains(audit.getElementType()));
tx.commitOnClose();
} }
// has // has
@ -112,34 +114,40 @@ public class AuditModelTestRunner {
dbAudit = auditTrail.getBy(tx, "Foo", audit.getId()); dbAudit = auditTrail.getBy(tx, "Foo", audit.getId());
assertNull(dbAudit); assertNull(dbAudit);
tx.commitOnClose();
} }
// remove // remove
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.remove(tx, audit); auditTrail.remove(tx, audit);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
assertNull(dbAudit); assertNull(dbAudit);
tx.commitOnClose();
} }
// update // update
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.add(tx, audit); auditTrail.add(tx, audit);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
dbAudit.setAction("Foo"); dbAudit.setAction("Foo");
auditTrail.update(tx, dbAudit); auditTrail.update(tx, dbAudit);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId());
assertEquals("Foo", dbAudit.getAction()); assertEquals("Foo", dbAudit.getAction());
tx.commitOnClose();
} }
} }
@ -155,6 +163,7 @@ public class AuditModelTestRunner {
assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), containsRange)); assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), containsRange));
assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), earlierRange)); assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), earlierRange));
assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), laterRange)); 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")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.addAll(tx, audits); auditTrail.addAll(tx, audits);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@ -186,17 +196,20 @@ public class AuditModelTestRunner {
assertEquals(0, allElements.size()); assertEquals(0, allElements.size());
allElements = auditTrail.getAllElements(tx, "FooBar", laterRange); allElements = auditTrail.getAllElements(tx, "FooBar", laterRange);
assertEquals(0, allElements.size()); assertEquals(0, allElements.size());
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.removeAll(tx, audits); auditTrail.removeAll(tx, audits);
assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange)); assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange));
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange)); assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange));
tx.commitOnClose();
} }
} }
@ -215,6 +228,7 @@ public class AuditModelTestRunner {
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.addAll(tx, audits); auditTrail.addAll(tx, audits);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@ -232,6 +246,7 @@ public class AuditModelTestRunner {
} }
auditTrail.updateAll(tx, allElements); auditTrail.updateAll(tx, allElements);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@ -240,6 +255,7 @@ public class AuditModelTestRunner {
for (Audit dbAudit : allElements) { for (Audit dbAudit : allElements) {
assertEquals("Foo", dbAudit.getAction()); assertEquals("Foo", dbAudit.getAction());
} }
tx.commitOnClose();
} }
} }
@ -271,6 +287,7 @@ public class AuditModelTestRunner {
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
AuditTrail auditTrail = tx.getAuditTrail(); AuditTrail auditTrail = tx.getAuditTrail();
auditTrail.addAll(tx, audits); auditTrail.addAll(tx, audits);
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { 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, "BarBarBar", containsRange));
assertEquals(5, auditTrail.querySize(tx, "FooFooFoo", containsRange)); assertEquals(5, auditTrail.querySize(tx, "FooFooFoo", containsRange));
assertEquals(5, auditTrail.querySize(tx, "BarFooBar", containsRange)); assertEquals(5, auditTrail.querySize(tx, "BarFooBar", containsRange));
tx.commitOnClose();
} }
try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) {
@ -291,6 +309,7 @@ public class AuditModelTestRunner {
assertEquals(5, auditTrail.removeAll(tx, "BarFooBar", containsRange)); assertEquals(5, auditTrail.removeAll(tx, "BarFooBar", containsRange));
assertEquals(0, auditTrail.querySize(tx, containsRange)); assertEquals(0, auditTrail.querySize(tx, containsRange));
tx.commitOnClose();
} }
} }
} }
@ -307,6 +326,7 @@ public class AuditModelTestRunner {
} }
assertEquals(0, auditTrail.querySize(tx, dateRange)); assertEquals(0, auditTrail.querySize(tx, dateRange));
tx.commitOnClose();
} }
} }

View File

@ -49,6 +49,7 @@ public class OrderModelTestRunner {
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ 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");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().add(tx, newOrder); tx.getOrderMap().add(tx, newOrder);
tx.commitOnClose();
} }
} }
@ -57,6 +58,7 @@ public class OrderModelTestRunner {
// remove all // remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx)); tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx));
tx.commitOnClose();
} }
// create three orders // create three orders
@ -67,6 +69,7 @@ public class OrderModelTestRunner {
tx.getOrderMap().add(tx, order1); tx.getOrderMap().add(tx, order1);
tx.getOrderMap().add(tx, order2); tx.getOrderMap().add(tx, order2);
tx.getOrderMap().add(tx, order3); tx.getOrderMap().add(tx, order3);
tx.commitOnClose();
} }
// query size // query size
@ -85,6 +88,7 @@ public class OrderModelTestRunner {
size = tx.getOrderMap().querySize(tx, "NonExistingType"); size = tx.getOrderMap().querySize(tx, "NonExistingType");
assertEquals("Should have zero objects of type 'NonExistingType'", 0, size); 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); Order newOrder = createOrder(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().add(tx, newOrder); tx.getOrderMap().add(tx, newOrder);
tx.commitOnClose();
} }
// read // read
Order readOrder = null; Order readOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
readOrder = tx.getOrderMap().getBy(tx, TYPE, ID); readOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
tx.commitOnClose();
} }
assertNotNull("Should read Order with id " + ID, readOrder); assertNotNull("Should read Order with id " + ID, readOrder);
@ -109,12 +115,14 @@ public class OrderModelTestRunner {
sParam.setValue(newStringValue); sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().update(tx, readOrder); tx.getOrderMap().update(tx, readOrder);
tx.commitOnClose();
} }
// read updated // read updated
Order updatedOrder = null; Order updatedOrder = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID);
tx.commitOnClose();
} }
assertNotNull("Should read Order with id " + ID, updatedOrder); assertNotNull("Should read Order with id " + ID, updatedOrder);
if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED) if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED)
@ -125,12 +133,14 @@ public class OrderModelTestRunner {
// delete // delete
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getOrderMap().remove(tx, readOrder); tx.getOrderMap().remove(tx, readOrder);
tx.commitOnClose();
} }
// fail to re-read // fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
Order order = tx.getOrderMap().getBy(tx, TYPE, ID); Order order = tx.getOrderMap().getBy(tx, TYPE, ID);
assertNull("Should no read Order with id " + ID, order); 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")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
OrderMap orderMap = tx.getOrderMap(); OrderMap orderMap = tx.getOrderMap();
orderMap.removeAll(tx, orderMap.getAllElements(tx)); 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")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
OrderMap orderMap = tx.getOrderMap(); OrderMap orderMap = tx.getOrderMap();
assertEquals(0, orderMap.querySize(tx)); assertEquals(0, orderMap.querySize(tx));
tx.commitOnClose();
} }
// now add some orders // now add some orders
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getOrderMap().addAll(tx, orders); tx.getOrderMap().addAll(tx, orders);
tx.commitOnClose();
} }
// make sure we have our expected size // make sure we have our expected size
@ -174,11 +187,13 @@ public class OrderModelTestRunner {
OrderMap orderMap = tx.getOrderMap(); OrderMap orderMap = tx.getOrderMap();
assertEquals(orders.size(), orderMap.querySize(tx)); assertEquals(orders.size(), orderMap.querySize(tx));
assertEquals(5, orderMap.querySize(tx, "MyType3")); assertEquals(5, orderMap.querySize(tx, "MyType3"));
tx.commitOnClose();
} }
// now use the remove all by type // now use the remove all by type
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getOrderMap().removeAllBy(tx, "MyType3"); tx.getOrderMap().removeAllBy(tx, "MyType3");
tx.commitOnClose();
} }
// again make sure we have our expected size // again make sure we have our expected size
@ -186,24 +201,28 @@ public class OrderModelTestRunner {
OrderMap orderMap = tx.getOrderMap(); OrderMap orderMap = tx.getOrderMap();
assertEquals(orders.size() - 5, orderMap.querySize(tx)); assertEquals(orders.size() - 5, orderMap.querySize(tx));
assertEquals(0, orderMap.querySize(tx, "MyType3")); assertEquals(0, orderMap.querySize(tx, "MyType3"));
tx.commitOnClose();
} }
// now use the remove all // now use the remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
long removed = tx.getOrderMap().removeAll(tx); long removed = tx.getOrderMap().removeAll(tx);
assertEquals(orders.size() - 5, removed); assertEquals(orders.size() - 5, removed);
tx.commitOnClose();
} }
// again make sure we have our expected size // again make sure we have our expected size
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
OrderMap orderMap = tx.getOrderMap(); OrderMap orderMap = tx.getOrderMap();
assertEquals(0, orderMap.querySize(tx)); assertEquals(0, orderMap.querySize(tx));
tx.commitOnClose();
} }
} }
// now add all again // now add all again
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getOrderMap().addAll(tx, orders); tx.getOrderMap().addAll(tx, orders);
tx.commitOnClose();
} }
Set<String> expectedTypes = new HashSet<>(); Set<String> expectedTypes = new HashSet<>();
@ -215,6 +234,7 @@ public class OrderModelTestRunner {
List<Order> allOrders = tx.getOrderMap().getAllElements(tx); List<Order> allOrders = tx.getOrderMap().getAllElements(tx);
Collections.sort(allOrders, comparator); Collections.sort(allOrders, comparator);
assertEquals(orders, allOrders); assertEquals(orders, allOrders);
tx.commitOnClose();
} }
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@ -233,6 +253,7 @@ public class OrderModelTestRunner {
List<Order> ordersByType = orderMap.getElementsBy(tx, type); List<Order> ordersByType = orderMap.getElementsBy(tx, type);
assertEquals(5, ordersByType.size()); assertEquals(5, ordersByType.size());
} }
tx.commitOnClose();
} }
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@ -242,6 +263,7 @@ public class OrderModelTestRunner {
assertNotNull(order); assertNotNull(order);
order = tx.getOrderMap().getBy(tx, "MyType3", "@00000011"); order = tx.getOrderMap().getBy(tx, "MyType3", "@00000011");
assertNotNull(order); assertNotNull(order);
tx.commitOnClose();
} }
} }
} }

View File

@ -49,6 +49,7 @@ public class ResourceModelTestRunner {
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ 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");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().add(tx, newResource); tx.getResourceMap().add(tx, newResource);
tx.commitOnClose();
} }
} }
@ -57,6 +58,7 @@ public class ResourceModelTestRunner {
// remove all // remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx)); tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx));
tx.commitOnClose();
} }
// create three resources // create three resources
@ -67,6 +69,7 @@ public class ResourceModelTestRunner {
tx.getResourceMap().add(tx, resource1); tx.getResourceMap().add(tx, resource1);
tx.getResourceMap().add(tx, resource2); tx.getResourceMap().add(tx, resource2);
tx.getResourceMap().add(tx, resource3); tx.getResourceMap().add(tx, resource3);
tx.commitOnClose();
} }
// query size // query size
@ -85,6 +88,7 @@ public class ResourceModelTestRunner {
size = tx.getResourceMap().querySize(tx, "NonExistingType"); size = tx.getResourceMap().querySize(tx, "NonExistingType");
assertEquals("Should have zero objects of type 'NonExistingType'", 0, size); 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); Resource newResource = createResource(ID, NAME, TYPE);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().add(tx, newResource); tx.getResourceMap().add(tx, newResource);
tx.commitOnClose();
} }
// read // read
Resource readResource = null; Resource readResource = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
readResource = tx.getResourceMap().getBy(tx, TYPE, ID); readResource = tx.getResourceMap().getBy(tx, TYPE, ID);
tx.commitOnClose();
} }
assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$
@ -109,12 +115,14 @@ public class ResourceModelTestRunner {
sParam.setValue(newStringValue); sParam.setValue(newStringValue);
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().update(tx, readResource); tx.getResourceMap().update(tx, readResource);
tx.commitOnClose();
} }
// read updated // read updated
Resource updatedResource = null; Resource updatedResource = null;
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID);
tx.commitOnClose();
} }
assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$
if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED) if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED)
@ -125,12 +133,14 @@ public class ResourceModelTestRunner {
// delete // delete
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
tx.getResourceMap().remove(tx, readResource); tx.getResourceMap().remove(tx, readResource);
tx.commitOnClose();
} }
// fail to re-read // fail to re-read
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) {
Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID); Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID);
assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ 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")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); 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")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
assertEquals(0, resourceMap.querySize(tx)); assertEquals(0, resourceMap.querySize(tx));
tx.commitOnClose();
} }
// now add some resources // now add some resources
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getResourceMap().addAll(tx, resources); tx.getResourceMap().addAll(tx, resources);
tx.commitOnClose();
} }
// make sure we have our expected size // make sure we have our expected size
@ -174,11 +187,13 @@ public class ResourceModelTestRunner {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
assertEquals(resources.size(), resourceMap.querySize(tx)); assertEquals(resources.size(), resourceMap.querySize(tx));
assertEquals(5, resourceMap.querySize(tx, "MyType3")); assertEquals(5, resourceMap.querySize(tx, "MyType3"));
tx.commitOnClose();
} }
// now use the remove all by type // now use the remove all by type
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getResourceMap().removeAllBy(tx, "MyType3"); tx.getResourceMap().removeAllBy(tx, "MyType3");
tx.commitOnClose();
} }
// again make sure we have our expected size // again make sure we have our expected size
@ -186,24 +201,28 @@ public class ResourceModelTestRunner {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
assertEquals(resources.size() - 5, resourceMap.querySize(tx)); assertEquals(resources.size() - 5, resourceMap.querySize(tx));
assertEquals(0, resourceMap.querySize(tx, "MyType3")); assertEquals(0, resourceMap.querySize(tx, "MyType3"));
tx.commitOnClose();
} }
// now use the remove all // now use the remove all
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
long removed = tx.getResourceMap().removeAll(tx); long removed = tx.getResourceMap().removeAll(tx);
assertEquals(resources.size() - 5, removed); assertEquals(resources.size() - 5, removed);
tx.commitOnClose();
} }
// again make sure we have our expected size // again make sure we have our expected size
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
assertEquals(0, resourceMap.querySize(tx)); assertEquals(0, resourceMap.querySize(tx));
tx.commitOnClose();
} }
} }
// now add all again // now add all again
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
tx.getResourceMap().addAll(tx, resources); tx.getResourceMap().addAll(tx, resources);
tx.commitOnClose();
} }
Set<String> expectedTypes = new HashSet<>(); Set<String> expectedTypes = new HashSet<>();
@ -215,6 +234,7 @@ public class ResourceModelTestRunner {
List<Resource> allResources = tx.getResourceMap().getAllElements(tx); List<Resource> allResources = tx.getResourceMap().getAllElements(tx);
Collections.sort(allResources, comparator); Collections.sort(allResources, comparator);
assertEquals(resources, allResources); assertEquals(resources, allResources);
tx.commitOnClose();
} }
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@ -233,6 +253,7 @@ public class ResourceModelTestRunner {
List<Resource> resourcesByType = resourceMap.getElementsBy(tx, type); List<Resource> resourcesByType = resourceMap.getElementsBy(tx, type);
assertEquals(5, resourcesByType.size()); assertEquals(5, resourcesByType.size());
} }
tx.commitOnClose();
} }
try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) {
@ -242,6 +263,7 @@ public class ResourceModelTestRunner {
assertNotNull(resource); assertNotNull(resource);
resource = tx.getResourceMap().getBy(tx, "MyType3", "@00000011"); resource = tx.getResourceMap().getBy(tx, "MyType3", "@00000011");
assertNotNull(resource); assertNotNull(resource);
tx.commitOnClose();
} }
} }
} }