A transaction manager applies inserts, updates and deletes to a table as they arrive, but keeps each one as a command object until the transaction ends. Commit forgets the commands; rollback undoes every one of them in reverse.
Table and TransactionManager are provided in the starter code. Implement only the command types they use: TableCommand, InsertCommand, UpdateCommand and DeleteCommand (ITableCommand in C#).
The provided Table is the receiver. has(key) says whether a row exists, get(key) returns its value or an empty string, put(key, value) writes a row, remove(key) deletes it, and size() counts rows.
The provided TransactionManager behaves as follows:
TransactionManager() starts with an empty table and no open transaction.boolean begin() opens a transaction and returns true, or returns false when one is already open.boolean insertRow(String key, String value) adds a row and returns true. It returns false and changes nothing when no transaction is open, the key is empty, or the key already exists.boolean updateRow(String key, String value) overwrites a row and returns true. It returns false and changes nothing when no transaction is open or the key does not exist.boolean deleteRow(String key) removes a row and returns true. It returns false and changes nothing when no transaction is open or the key does not exist.int commit() closes the transaction, keeps every change, and returns how many commands it contained. It returns -1 when no transaction is open.int rollback() closes the transaction, undoes every command newest first, and returns how many it undid. It returns -1 when no transaction is open.String read(String key) returns the row's value, or "MISSING".int rowCount() returns how many rows the table holds.int pendingCount() returns how many commands the open transaction holds.Changes are visible as soon as they run, so a read inside a transaction sees the new value. Rollback has to reconstruct what every row held before the transaction started, one command at a time.
The tests call the provided TransactionManager; your work should be confined to the command contract and the three concrete command classes.
Input:
Output:
Explanation: Three commands run inside one transaction. Rollback undoes them newest first: the update restores Ann, then both inserts remove their rows.
Input:
Output:
Explanation: A committed insert survives. In the next transaction the delete succeeds and the update is refused because the row is gone. Rollback puts the deleted row back with the value it held.
0 <= key.length <= 10 and 0 <= value.length <= 2020 commands are held in one transaction.100 calls in total are made across all methods.Implement the TableCommand contract and the three concrete commands. Table and TransactionManager are complete and must not be modified.
Full marks when `TableCommand` defines `execute` and `undo` and the three concrete commands implement it with the constructors the provided `TransactionManager` uses. Lose points when a command needs changes to the manager or the table.
Full marks when `UpdateCommand` and `DeleteCommand` read the current value during `execute`, before they change the row, and undo writes that value back. Lose points heavily when undo deletes an updated row, restores an empty value, or reads the table after the change.
Full marks when `InsertCommand.undo` removes the key it inserted rather than writing an empty value, so a rolled back insert leaves the row count unchanged. Lose points for printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new TransactionManager() | null |
| begin() | true |
| insertRow("u1", "Ann") | true |
| insertRow("u2", "Bob") | true |
| updateRow("u1", "Anna") | true |
| read("u1") | "Anna" |
| rollback() | 3 |
| read("u1") | "MISSING" |
| rowCount() | 0 |
Three commands run inside one transaction. Rollback undoes them newest first: the update restores Ann, then both inserts remove their rows.
Run checks these cases. Submit also runs a larger hidden set.

