| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.store; |
| 7 |
|
| 8 |
import org.h2.message.DbException; |
| 9 |
|
| 10 |
/** |
| 11 |
* Represents an in-doubt transaction (a transaction in the prepare phase). |
| 12 |
*/ |
| 13 |
public interface InDoubtTransaction { |
| 14 |
|
| 15 |
/** |
| 16 |
* The transaction state meaning this transaction is not committed yet, but |
| 17 |
* also not rolled back (in-doubt). |
| 18 |
*/ |
| 19 |
int IN_DOUBT = 0; |
| 20 |
|
| 21 |
/** |
| 22 |
* The transaction state meaning this transaction is committed. |
| 23 |
*/ |
| 24 |
int COMMIT = 1; |
| 25 |
|
| 26 |
/** |
| 27 |
* The transaction state meaning this transaction is rolled back. |
| 28 |
*/ |
| 29 |
int ROLLBACK = 2; |
| 30 |
|
| 31 |
/** |
| 32 |
* Change the state of this transaction. |
| 33 |
* This will also update the transaction log. |
| 34 |
* |
| 35 |
* @param state the new state |
| 36 |
*/ |
| 37 |
void setState(int state); |
| 38 |
|
| 39 |
/** |
| 40 |
* Get the state of this transaction. |
| 41 |
* |
| 42 |
* @return the transaction state |
| 43 |
*/ |
| 44 |
int getState(); |
| 45 |
|
| 46 |
/** |
| 47 |
* Get the state of this transaction as a text. |
| 48 |
* |
| 49 |
* @return the transaction state text |
| 50 |
*/ |
| 51 |
default String getStateDescription() { |
| 52 |
int state = getState(); |
| 53 |
switch (state) { |
| 54 |
case 0: |
| 55 |
return "IN_DOUBT"; |
| 56 |
case 1: |
| 57 |
return "COMMIT"; |
| 58 |
case 2: |
| 59 |
return "ROLLBACK"; |
| 60 |
default: |
| 61 |
throw DbException.getInternalError("state=" + state); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get the name of the transaction. |
| 67 |
* |
| 68 |
* @return the transaction name |
| 69 |
*/ |
| 70 |
String getTransactionName(); |
| 71 |
} |