Description
While normal use cases are fine assuming no other problems, if somehow multiple threads get ahold of the same Connection and try to run queries on it (which would clearly be a bug) it's possible for them to end up corrupting each other's queries. It would be nice if problems like this are caught. In particular, it seems that the window between validateQuery and setQueryPromise in each Connection.send* function is vulnerable and, unless I'm missing something, the AtomicReference isn't providing much benefit.
A quick glance suggests that setQueryPromise could check whether queryPromise is already defined (e.g., using a simple synchronized {} mutex or AtomicReference.compareAndSet) and throw the ConnectionStillRunningQueryException at that point.
Similarly, since the connection is effectively locked (with this change) during the query, there's no need for preparedStatementCounter to be atomic.