Bug #119705 Session State Tracker documentation improvements
Submitted: 16 Jan 8:38
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Open Impact on me:
None 
Category:Connector / J Documentation Severity:S3 (Non-critical)
Version:9.5 OS:Any
Assigned to: CPU Architecture:Any

[16 Jan 8:38] Daniël van Eeden
Description:
Page: https://dev.mysql.com/doc/connector-j/en/connector-j-session-state-tracker.html

> MysqlConnection.getServerSessionStateController().addSessionStateChangesListener(listener);

As `DriverManager.getConnection()` returns a `Connection` and not a `MysqlConnection` this may need some explanation or a better example.

What I used in my code is this:
```
((MysqlConnection) conn).getServerSessionStateController().addSessionStateChangesListener(...)
```

> System.out.print(change.getType() + " == > ");

This lists the number associated with the change. So this would print `3 ==>` instead of `SESSION_TRACK_GTIDS ==>` which would be more recognizable.

Maybe something like this:

```
        String changeType;
	switch (change.getType()) {
		case ServerSessionStateController.SESSION_TRACK_SYSTEM_VARIABLES:
			changeType = "SESSION_TRACK_SYSTEM_VARIABLES";
			break;
		case ServerSessionStateController.SESSION_TRACK_SCHEMA:
			changeType = "SESSION_TRACK_SCHEMA";
			break;
                case ServerSessionStateController.SESSION_TRACK_STATE_CHANGE:
			changeType = "SESSION_TRACK_STATE_CHANGE";
			break;
                case ServerSessionStateController.SESSION_TRACK_GTIDS:
			changeType = "gtids";
			break;
                case ServerSessionStateController.SESSION_TRACK_TRANSACTION_CHARACTERISTICS:
			changeType = "SESSION_TRACK_TRANSACTION_CHARACTERISTICS";
			break;
                case ServerSessionStateController.SESSION_TRACK_TRANSACTION_STATE:
			changeType = "SESSION_TRACK_TRANSACTION_STATE";
			break;
		default:
			changeType = "UNKNOWN_" + change.getType();
	}
```

The closing bracket for the class isn't in the first column, which looks like incorrect formatting (nitpick).

How to repeat:
See description.

Suggested fix:
It would be good to:
- List example output (e.g. `3 == > 859bfcf9-f1f7-11f0-ab7b-ee172f58920a:74`)
- Make this a complete standalone runnable example (or link to one).
- Show how to get get a `MysqlConnection` and also extend the documentation for `MysqlConnection`.
- Print change names instead numbers (possibly with a simple switch statement).