Nested transactions, Transaction#executeOther(Transaction), where the
inner transaction performed a query ran into NPE since the Database
used for the query had not been defined.
* ShutdownHook: No sessions to save check
ShutdownHook now checks if it needs to save any sessions and does not
start the database if no sessions are unsaved.
* SessionCache.getActiveSessions() now immutable
* [#769] Bukkit and Sponge server shutdown save
Implemented following save procedure for Bukkit:
- On plugin disable check if server is shutting down and save sessions
- Shutdown hook triggered on JVM shutdown calls the same session save
- Save clears sessions from cache, so the sessions are not saved twice
Implemented following save procedure for Sponge:
- Listen for GameStoppingServerEvent
- On plugin disable ask listener if shutting down and save sessions
- Shutdown hook triggered on JVM shutdown calls the same session save
- Save clears sessions from cache, so the sessions are not saved twice
Test:
- Tests ShutdownSave on reload
- Tests ShutdownSave on shutdown
- Tests ShutdownSave on JVM shutdown
These can be summarized in 3 categories of changes:
### Moved SQL queries from `Table` classes to `Queries` classes.
`Table` classes were turned into static information classes that only contain statements and table fields for the tables. Classes with static methods were created that return `Query<T>` objects that can be passed to the Database. This simplifies addition of multi-table queries.
### Changes are now executed via Transactions
A new `Transaction` class was made, and executing row updating statements was limited inside these classes. This allows committing changes once per multiple statements (speedup) and rolling back partial failed transactions (reliability).
### Database ExecutorService and access lock
A single thread executor was added to be in charge of executing Transactions. All submitted transactions will be executed by this one thread.
Queries will be held until database is operational (Patches have been applied). This should alleviate issues such as #893
## Other changes
- SaveOperations, CheckOperations, CountOperations, SearchOperations were all removed. FetchOperations was completely deprecated, but since it is still provided by `PlanAPI` it was kept in place.
`FetchOperations` is scheduled for removal upon implementation of the new PluginData API.
- Database interface was not very useful, so it was changed to make it usable instead of SQLDB.
- [Wrong branch] Moved to using JUnit 5.4 TempDir instead of junitpioneer
- `DataCache` was split off to a separate class `NicknameCache` and `SessionCache` no longer saves the session when ended, responsibility is now with the caller