package org.h2.store;
import org.h2.message.DbException;
public class PageStoreInDoubtTransaction implements InDoubtTransaction {
private final PageStore store;
private final int sessionId;
private final int pos;
private final String transactionName;
private int state;
public PageStoreInDoubtTransaction(PageStore store, int sessionId, int pos,
String transaction) {
this.store = store;
this.sessionId = sessionId;
this.pos = pos;
this.transactionName = transaction;
this.state = IN_DOUBT;
}
@Override
public void setState(int state) {
switch (state) {
case COMMIT:
store.setInDoubtTransactionState(sessionId, pos, true);
break;
case ROLLBACK:
store.setInDoubtTransactionState(sessionId, pos, false);
break;
default:
DbException.throwInternalError("state="+state);
}
this.state = state;
}
@Override
public String getState() {
switch (state) {
case IN_DOUBT:
return "IN_DOUBT";
case COMMIT:
return "COMMIT";
case ROLLBACK:
return "ROLLBACK";
default:
throw DbException.throwInternalError("state="+state);
}
}
@Override
public String getTransactionName() {
return transactionName;
}
}