[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
64fed84708
commit
8c91c12948
|
@ -30,6 +30,7 @@ import li.strolch.persistence.api.StrolchTransaction;
|
|||
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.configuration.StrolchConfigurationException;
|
||||
import li.strolch.runtime.observer.ObserverHandler;
|
||||
|
@ -99,11 +100,7 @@ public class PostgreSqlPersistenceHandler extends StrolchComponent implements Pe
|
|||
super.start();
|
||||
}
|
||||
|
||||
public StrolchTransaction openTx() {
|
||||
return openTx(StrolchConstants.DEFAULT_REALM);
|
||||
}
|
||||
|
||||
public StrolchTransaction openTx(String realm) {
|
||||
public StrolchTransaction openTx(StrolchRealm realm) {
|
||||
PostgreSqlStrolchTransaction tx = new PostgreSqlStrolchTransaction(realm, this);
|
||||
if (getContainer().hasComponent(ObserverHandler.class)) {
|
||||
tx.setObserverHandler(getContainer().getComponent(ObserverHandler.class));
|
||||
|
|
|
@ -21,14 +21,15 @@ import java.util.Date;
|
|||
import java.util.Set;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.persistence.api.AbstractTransaction;
|
||||
import li.strolch.persistence.api.ModificationResult;
|
||||
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.persistence.api.TransactionResult;
|
||||
import li.strolch.persistence.api.TransactionState;
|
||||
import li.strolch.runtime.agent.impl.StrolchRealm;
|
||||
import li.strolch.runtime.observer.ObserverHandler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -36,11 +37,10 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
public class PostgreSqlStrolchTransaction implements StrolchTransaction {
|
||||
public class PostgreSqlStrolchTransaction extends AbstractTransaction {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PostgreSqlStrolchTransaction.class);
|
||||
private PostgreSqlPersistenceHandler persistenceHandler;
|
||||
private String realm;
|
||||
|
||||
private TransactionCloseStrategy closeStrategy;
|
||||
private ObserverHandler observerHandler;
|
||||
|
@ -54,10 +54,10 @@ public class PostgreSqlStrolchTransaction implements StrolchTransaction {
|
|||
private TransactionResult txResult;
|
||||
private boolean open;
|
||||
|
||||
public PostgreSqlStrolchTransaction(String realm, PostgreSqlPersistenceHandler persistenceHandler) {
|
||||
public PostgreSqlStrolchTransaction(StrolchRealm realm, PostgreSqlPersistenceHandler persistenceHandler) {
|
||||
super(realm);
|
||||
this.startTime = System.nanoTime();
|
||||
this.startTimeDate = new Date();
|
||||
this.realm = realm;
|
||||
this.persistenceHandler = persistenceHandler;
|
||||
this.suppressUpdates = false;
|
||||
this.closeStrategy = TransactionCloseStrategy.COMMIT;
|
||||
|
@ -152,7 +152,7 @@ public class PostgreSqlStrolchTransaction implements StrolchTransaction {
|
|||
this.txResult.setStartTime(this.startTimeDate);
|
||||
this.txResult.setTxDuration(txDuration);
|
||||
this.txResult.setCloseDuration(closeDuration);
|
||||
this.txResult.setRealm(this.realm);
|
||||
this.txResult.setRealm(getRealm().getRealm());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("TX was completed after "); //$NON-NLS-1$
|
||||
|
@ -201,7 +201,7 @@ public class PostgreSqlStrolchTransaction implements StrolchTransaction {
|
|||
this.txResult.setStartTime(this.startTimeDate);
|
||||
this.txResult.setTxDuration(txDuration);
|
||||
this.txResult.setCloseDuration(closeDuration);
|
||||
this.txResult.setRealm(this.realm);
|
||||
this.txResult.setRealm(getRealm().getRealm());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,7 +233,7 @@ public class PostgreSqlStrolchTransaction implements StrolchTransaction {
|
|||
*/
|
||||
Connection getConnection() {
|
||||
if (this.connection == null) {
|
||||
this.connection = this.persistenceHandler.getConnection(this.realm);
|
||||
this.connection = this.persistenceHandler.getConnection(getRealm().getRealm());
|
||||
}
|
||||
return this.connection;
|
||||
}
|
||||
|
|
|
@ -113,13 +113,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