[Major] refactored how transactions are opened
Now the ElementMapHandler is the central object and clients do not use access DAOs or the PersistenceHandler anymore. This is now transparent.
This commit is contained in:
parent
28f4353405
commit
4a0fb74d21
|
@ -25,9 +25,9 @@ import li.strolch.persistence.api.PersistenceHandler;
|
|||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.xml.model.OrderContextFactory;
|
||||
import li.strolch.persistence.xml.model.ResourceContextFactory;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.agent.api.StrolchComponent;
|
||||
import li.strolch.runtime.agent.impl.ComponentContainerImpl;
|
||||
import li.strolch.runtime.agent.impl.StrolchRealm;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
import li.strolch.runtime.observer.ObserverHandler;
|
||||
import ch.eitchnet.xmlpers.api.IoMode;
|
||||
|
@ -69,15 +69,10 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten
|
|||
super.initialize(componentConfiguration);
|
||||
}
|
||||
|
||||
public StrolchTransaction openTx() {
|
||||
return openTx(StrolchConstants.DEFAULT_REALM);
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
// caller will/must close
|
||||
public StrolchTransaction openTx(String realm) {
|
||||
PersistenceTransaction tx = this.persistenceManager.openTx(realm);
|
||||
XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(tx);
|
||||
@Override
|
||||
public StrolchTransaction openTx(StrolchRealm realm) {
|
||||
PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm());
|
||||
XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, tx);
|
||||
if (getContainer().hasComponent(ObserverHandler.class)) {
|
||||
strolchTx.setObserverHandler(getContainer().getComponent(ObserverHandler.class));
|
||||
}
|
||||
|
|
|
@ -18,24 +18,26 @@ package li.strolch.persistence.xml;
|
|||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.persistence.api.AbstractTransaction;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.api.TransactionCloseStrategy;
|
||||
import li.strolch.runtime.agent.impl.StrolchRealm;
|
||||
import li.strolch.runtime.observer.ObserverHandler;
|
||||
import ch.eitchnet.xmlpers.api.ModificationResult;
|
||||
import ch.eitchnet.xmlpers.api.PersistenceTransaction;
|
||||
import ch.eitchnet.xmlpers.api.TransactionResult;
|
||||
|
||||
public class XmlStrolchTransaction implements StrolchTransaction {
|
||||
public class XmlStrolchTransaction extends AbstractTransaction {
|
||||
|
||||
private ObserverHandler observerHandler;
|
||||
private boolean suppressUpdates;
|
||||
private PersistenceTransaction tx;
|
||||
private TransactionCloseStrategy closeStrategy;
|
||||
|
||||
public XmlStrolchTransaction(PersistenceTransaction tx) {
|
||||
public XmlStrolchTransaction(StrolchRealm realm, PersistenceTransaction tx) {
|
||||
super(realm);
|
||||
this.suppressUpdates = false;
|
||||
this.tx = tx;
|
||||
this.closeStrategy = TransactionCloseStrategy.COMMIT;
|
||||
|
|
|
@ -110,13 +110,13 @@ public class ObserverUpdateTest {
|
|||
|
||||
// create order
|
||||
Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
try (StrolchTransaction tx = runtimeMock.getOrderMap().openTx()) {
|
||||
try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) {
|
||||
tx.getOrderDao().save(newOrder);
|
||||
}
|
||||
|
||||
// create resource
|
||||
Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
try (StrolchTransaction tx = runtimeMock.getResourceMap().openTx()) {
|
||||
try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) {
|
||||
tx.getResourceDao().save(newResource);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue