[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:
parent
9532c97ef1
commit
46ccb921df
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -112,7 +112,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 +156,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;
|
||||
|
@ -492,7 +507,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();
|
||||
|
@ -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$
|
||||
msg = MessageFormat.format(msg, getRealmName(), e.getMessage(), sb.toString());
|
||||
throw new StrolchPersistenceException(msg, e);
|
||||
throw new StrolchTransactionException(msg, e);
|
||||
}
|
||||
|
||||
private boolean isAuditTrailEnabled() {
|
||||
|
|
|
@ -61,6 +61,7 @@ import li.strolch.service.api.Command;
|
|||
* StrolchRealm realm = strolchAgent.getContainer().getRealm(StrolchConstants.DEFAULT_REALM);
|
||||
* try(StrolchTransaction tx = realm.openTx(certificate, getClass())){
|
||||
* // do work e.g. add commands
|
||||
* tx.commitOnClose();
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -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();
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* @return true if the transaction is still open, i.e. not being closed or rolling back, committing, etc.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -97,6 +97,7 @@ public class DefaultEnumHandler extends StrolchComponent implements EnumHandler
|
|||
}
|
||||
|
||||
StrolchEnum strolchEnum = new StrolchEnum(name, locale, values);
|
||||
tx.commitOnClose();
|
||||
return strolchEnum;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Resource> 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<Order> 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<Resource> 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<Resource> 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<Resource> 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<Resource> 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<Resource> 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<Resource> 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<Resource> result;
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) {
|
||||
result = tx.doQuery(query);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
assertEquals(0, result.size());
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -151,6 +151,8 @@ public class AuditQueryTest {
|
|||
randomAudit.setAction("create");
|
||||
randomAudit.setElementAccessed(randomAudit.getAccessType().name());
|
||||
auditTrail.add(tx, randomAudit);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview,
|
||||
|
@ -232,6 +236,7 @@ public class Inspector {
|
|||
}
|
||||
|
||||
ordersOverview = new ElementMapOverview(ElementMapType.ORDER.getName(), typeOverviews);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(ordersOverview,
|
||||
|
@ -278,6 +283,7 @@ public class Inspector {
|
|||
elementOverviews.add(resourceOverview);
|
||||
}
|
||||
typeDetail = new TypeDetail(type, elementOverviews);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
|
||||
|
@ -319,6 +325,7 @@ public class Inspector {
|
|||
elementOverviews.add(orderOverview);
|
||||
}
|
||||
typeDetail = new TypeDetail(type, elementOverviews);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(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$
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -41,6 +41,7 @@ public class AddOrderService extends AbstractService<AddOrderService.AddOrderArg
|
|||
AddOrderCommand command = new AddOrderCommand(getContainer(), tx);
|
||||
command.setOrder(arg.order);
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -44,6 +44,7 @@ public class AddResourceCollectionService extends
|
|||
AddResourceCollectionCommand command = new AddResourceCollectionCommand(getContainer(), tx);
|
||||
command.setResources(arg.resources);
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -41,6 +41,7 @@ public class AddResourceService extends AbstractService<AddResourceService.AddRe
|
|||
AddResourceCommand command = new AddResourceCommand(getContainer(), tx);
|
||||
command.setResource(arg.resource);
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -41,11 +41,11 @@ public class ClearModelService extends AbstractService<ClearModelArgument, Servi
|
|||
|
||||
ClearModelCommand command;
|
||||
try (StrolchTransaction tx = openTx(arg.realm)) {
|
||||
|
||||
command = new ClearModelCommand(getContainer(), tx);
|
||||
command.setClearOrders(arg.clearOrders);
|
||||
command.setClearResources(arg.clearResources);
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ModelStatistics statistics = command.getStatistics();
|
||||
|
|
|
@ -52,7 +52,9 @@ public class RemoveOrderCollectionService extends
|
|||
|
||||
RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(getContainer(), tx);
|
||||
command.setOrders(orders);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -44,7 +44,9 @@ public class RemoveOrderService extends AbstractService<RemoveOrderService.Remov
|
|||
|
||||
RemoveOrderCommand command = new RemoveOrderCommand(getContainer(), tx);
|
||||
command.setOrder(order);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -52,7 +52,9 @@ public class RemoveResourceCollectionService extends
|
|||
|
||||
RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(getContainer(), tx);
|
||||
command.setResources(resources);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -44,7 +44,9 @@ public class RemoveResourceService extends AbstractService<RemoveResourceService
|
|||
|
||||
RemoveResourceCommand command = new RemoveResourceCommand(getContainer(), tx);
|
||||
command.setResource(resource);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -43,7 +43,9 @@ public class UpdateOrderCollectionService extends
|
|||
try (StrolchTransaction tx = openTx(arg.realm)) {
|
||||
UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(getContainer(), tx);
|
||||
command.setOrders(arg.orders);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -40,7 +40,9 @@ public class UpdateOrderService extends AbstractService<UpdateOrderService.Updat
|
|||
try (StrolchTransaction tx = openTx(arg.realm)) {
|
||||
UpdateOrderCommand command = new UpdateOrderCommand(getContainer(), tx);
|
||||
command.setOrder(arg.order);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -43,7 +43,9 @@ public class UpdateResourceCollectionService extends
|
|||
try (StrolchTransaction tx = openTx(arg.realm)) {
|
||||
UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(getContainer(), tx);
|
||||
command.setResources(arg.resources);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -40,7 +40,9 @@ public class UpdateResourceService extends AbstractService<UpdateResourceService
|
|||
try (StrolchTransaction tx = openTx(arg.realm)) {
|
||||
UpdateResourceCommand command = new UpdateResourceCommand(getContainer(), tx);
|
||||
command.setResource(arg.resource);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -68,7 +68,9 @@ public class XmlExportModelService extends AbstractService<XmlExportModelArgumen
|
|||
command.setDoResources(arg.doResources);
|
||||
command.setOrderTypes(arg.orderTypes);
|
||||
command.setResourceTypes(arg.resourceTypes);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ModelStatistics statistics = command.getStatistics();
|
||||
|
|
|
@ -60,7 +60,9 @@ public class XmlImportModelService extends AbstractService<XmlImportModelArgumen
|
|||
command.setUpdateResources(arg.updateResources);
|
||||
command.setOrderTypes(arg.orderTypes);
|
||||
command.setResourceTypes(arg.resourceTypes);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
ModelStatistics statistics = command.getStatistics();
|
||||
|
|
|
@ -46,7 +46,9 @@ public class AddParameterService extends AbstractService<AddParameterService.Add
|
|||
AddParameterCommand command = new AddParameterCommand(getContainer(), tx);
|
||||
command.setElement(element);
|
||||
command.setParameter(arg.parameter);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -45,7 +45,9 @@ public class RemoveParameterService extends AbstractService<RemoveParameterServi
|
|||
RemoveParameterCommand command = new RemoveParameterCommand(getContainer(), tx);
|
||||
command.setElement(parameter.getParent());
|
||||
command.setParameterId(parameter.getId());
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -54,6 +54,7 @@ public class SetParameterService extends AbstractService<SetParameterService.Set
|
|||
command.setValueAsString(arg.valueAsString);
|
||||
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -87,11 +87,11 @@ public abstract class AbstractRealmCommandTest {
|
|||
|
||||
StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName);
|
||||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
|
||||
Command command = getCommandInstance(runtimeMock.getContainer(), tx);
|
||||
|
||||
FailCommandFacade commandFacade = new FailCommandFacade(runtimeMock.getContainer(), tx, command);
|
||||
|
||||
tx.addCommand(commandFacade);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,7 @@ public abstract class AbstractRealmCommandTest {
|
|||
try (StrolchTransaction tx = realm.openTx(certificate, "test")) {
|
||||
Command command = getCommandInstance(runtimeMock.getContainer(), tx);
|
||||
tx.addCommand(command);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ public class ClearModelServiceTest extends AbstractRealmServiceTest {
|
|||
try (StrolchTransaction tx = strolchRealm.openTx(ClearModelServiceTest.this.certificate, "test")) {
|
||||
assertEquals(0, tx.getResourceMap().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")) {
|
||||
assertNotEquals(0, tx.getResourceMap().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")) {
|
||||
assertNotEquals(0, tx.getOrderMap().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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -209,6 +209,8 @@ public class LockingTest {
|
|||
|
||||
if (arg.longRunning)
|
||||
Thread.sleep(5000l);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
|
||||
return ServiceResult.success();
|
||||
|
|
|
@ -20,6 +20,7 @@ public abstract class AbstractModelTest {
|
|||
Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes());
|
||||
try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx(certificate, "test")) {
|
||||
tx.getOrderMap().getAllKeys(tx);
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ public class AuditModelTestRunner {
|
|||
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")) {
|
||||
|
@ -99,6 +100,7 @@ public class AuditModelTestRunner {
|
|||
Set<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> expectedTypes = new HashSet<>();
|
||||
|
@ -215,6 +234,7 @@ public class OrderModelTestRunner {
|
|||
List<Order> 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<Order> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> expectedTypes = new HashSet<>();
|
||||
|
@ -215,6 +234,7 @@ public class ResourceModelTestRunner {
|
|||
List<Resource> 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<Resource> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue