[New] Added StrolchTransaction.isReadOnly()

This commit is contained in:
Robert von Burg 2022-06-03 15:18:37 +02:00
parent b4aa75c884
commit 1437780443
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
3 changed files with 42 additions and 4 deletions

View File

@ -125,6 +125,8 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return this.txResult.getState().isOpen();
}
@Override
public boolean isRollingBack() {
return this.txResult.getState().isRollingBack();
@ -320,8 +322,13 @@ public abstract class AbstractTransaction implements StrolchTransaction {
this.commands.add(command);
}
private boolean isReadOnly() {
return this.closeStrategy == TransactionCloseStrategy.READ_ONLY;
public boolean isReadOnly() {
return this.closeStrategy.isReadonly();
}
@Override
public boolean isWriteable() {
return this.closeStrategy.isReadonly();
}
private void assertNotReadOnly() {

View File

@ -406,6 +406,16 @@ public interface StrolchTransaction extends AutoCloseable {
*/
boolean isOpen();
/**
* @return if the current state of the StrolchTransaction is {@link TransactionCloseStrategy#READ_ONLY} or {@link TransactionCloseStrategy#ROLLBACK}
*/
boolean isReadOnly();
/**
* @return if the current state of the StrolchTransaction is {@link TransactionCloseStrategy#COMMIT}
*/
boolean isWriteable();
/**
* @return if the current state of the StrolchTransaction is {@link TransactionState#ROLLING_BACK}
*/

View File

@ -28,12 +28,16 @@ import li.strolch.exception.StrolchException;
public enum TransactionCloseStrategy {
/**
* <p>The default close strategy. It defines a read-only transaction, i.e. no modifications will be persisted,
* modifications will be logged as an error</p>
* <p>The default close strategy. It defines a writeable transaction</p>
*/
DEFAULT() {
@Override
public boolean isReadonly() {
return false;
}
@Override
public boolean isWriteable() {
return true;
}
@ -60,6 +64,11 @@ public enum TransactionCloseStrategy {
return true;
}
@Override
public boolean isWriteable() {
return false;
}
@Override
public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableReadOnly();
@ -76,6 +85,11 @@ public enum TransactionCloseStrategy {
return false;
}
@Override
public boolean isWriteable() {
return true;
}
@Override
public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableCommit();
@ -92,6 +106,11 @@ public enum TransactionCloseStrategy {
return true;
}
@Override
public boolean isWriteable() {
return false;
}
@Override
public void close(StrolchTransaction tx) throws StrolchException {
tx.autoCloseableRollback();
@ -101,4 +120,6 @@ public enum TransactionCloseStrategy {
public abstract void close(StrolchTransaction tx) throws StrolchException;
public abstract boolean isReadonly();
public abstract boolean isWriteable();
}