[New] Added StrolchTransaction.isReadOnly()
This commit is contained in:
parent
b4aa75c884
commit
1437780443
|
@ -125,6 +125,8 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
return this.txResult.getState().isOpen();
|
return this.txResult.getState().isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRollingBack() {
|
public boolean isRollingBack() {
|
||||||
return this.txResult.getState().isRollingBack();
|
return this.txResult.getState().isRollingBack();
|
||||||
|
@ -320,8 +322,13 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
||||||
this.commands.add(command);
|
this.commands.add(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isReadOnly() {
|
public boolean isReadOnly() {
|
||||||
return this.closeStrategy == TransactionCloseStrategy.READ_ONLY;
|
return this.closeStrategy.isReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable() {
|
||||||
|
return this.closeStrategy.isReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNotReadOnly() {
|
private void assertNotReadOnly() {
|
||||||
|
|
|
@ -406,6 +406,16 @@ public interface StrolchTransaction extends AutoCloseable {
|
||||||
*/
|
*/
|
||||||
boolean isOpen();
|
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}
|
* @return if the current state of the StrolchTransaction is {@link TransactionState#ROLLING_BACK}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -28,12 +28,16 @@ import li.strolch.exception.StrolchException;
|
||||||
public enum TransactionCloseStrategy {
|
public enum TransactionCloseStrategy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>The default close strategy. It defines a read-only transaction, i.e. no modifications will be persisted,
|
* <p>The default close strategy. It defines a writeable transaction</p>
|
||||||
* modifications will be logged as an error</p>
|
|
||||||
*/
|
*/
|
||||||
DEFAULT() {
|
DEFAULT() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isReadonly() {
|
public boolean isReadonly() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +64,11 @@ public enum TransactionCloseStrategy {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(StrolchTransaction tx) throws StrolchException {
|
public void close(StrolchTransaction tx) throws StrolchException {
|
||||||
tx.autoCloseableReadOnly();
|
tx.autoCloseableReadOnly();
|
||||||
|
@ -76,6 +85,11 @@ public enum TransactionCloseStrategy {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(StrolchTransaction tx) throws StrolchException {
|
public void close(StrolchTransaction tx) throws StrolchException {
|
||||||
tx.autoCloseableCommit();
|
tx.autoCloseableCommit();
|
||||||
|
@ -92,6 +106,11 @@ public enum TransactionCloseStrategy {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(StrolchTransaction tx) throws StrolchException {
|
public void close(StrolchTransaction tx) throws StrolchException {
|
||||||
tx.autoCloseableRollback();
|
tx.autoCloseableRollback();
|
||||||
|
@ -101,4 +120,6 @@ public enum TransactionCloseStrategy {
|
||||||
public abstract void close(StrolchTransaction tx) throws StrolchException;
|
public abstract void close(StrolchTransaction tx) throws StrolchException;
|
||||||
|
|
||||||
public abstract boolean isReadonly();
|
public abstract boolean isReadonly();
|
||||||
|
|
||||||
|
public abstract boolean isWriteable();
|
||||||
}
|
}
|
Loading…
Reference in New Issue