A common situation with database applications is the need to use the result of one database operation to perform another database operation. This is most often seen when inserting new data that uses a database-generated primary key that is then used to insert data into dependent tables that reference the newly created identifier. When a synchronous connection is in use, this scenario is easily handled, as the database operation that generated the primary key will have finished before the next line of code to insert the dependent data executes. With an asynchronous connection, the database operation must be carefully chained so that the function handling the result of the first insert has access to the information needed to insert the dependent data.
Another common situation is the need to execute multiple database operations at once. A SQLConnection supports SQLStatement queueing provided every database operation uses a unique SQLStatement instance. In particular, when looping over a set of identifiers that each needs to be loaded, a single prepared SQLStatement can not be used to queue up all the database operations if using an asynchronous connection. Reusing the same SQLStatement on a synchronous connection is valid since the call to execute() will have finished before the parameters on the SQLStatement are changed.
Lastly, only one database operation can be executing on a SQLConnection at a time. If both long-running and short-running database operations will occur that are independent of each other, it is possible to have multiple connections open to the same database. In order to take advantage of multiple connections, you will need to use asynchronous connections. One connection can handle the long-running database operations while another connection handles the short database operations. However, it is not recommended to use multiple connections if both read and write database operations will be used simultaneously. Attempting to update a database on one connection while reading on another will generate an exception. How the Allurent Desktop Connection used this multiple connection approach is described in the next section.