Skip to content

Instantly share code, notes, and snippets.

@josh-padnick
Created July 18, 2014 03:36
Show Gist options
  • Save josh-padnick/932eb6f32b9fe8e0ee9a to your computer and use it in GitHub Desktop.
Save josh-padnick/932eb6f32b9fe8e0ee9a to your computer and use it in GitHub Desktop.
Ugly Sample of JDBC Promises in Play (probably with anti-patterns)
public void sendTextMessage() throws SQLException {
// Open a connection
CustomConnectionMgr.openConnection();
// Tell the connection object to start a transaction
CustomConnectionMgr.startTransaction();
F.Promise<Integer> notifyBatchIdPromise;
F.Promise<Integer> notifyConversationIdPromise;
// Excecute a JDBC statement, which returns a Promise
notifyBatchIdPromise = notifyBatchDao.insert();
// Excecute another JDBC statement, which should be executed after notifyBatchDao.insert()
notifyConversationIdPromise = notifyBatchIdPromise.flatMap( notifyBatchId -> {
return notifyConversationDao.insert(notifyBatchId);
});
// Handle failure for first query
notifyBatchIdPromise.onFailure(exception -> {
throw new Exception( exception )
CustomConnectionMgr.closeConnection();
});
// Handle failure for second query
notifyConversationIdPromise.onFailure(exception -> {
CustomConnectionMgr.closeConnection();
});
CustomConnectionMgr.endTransaction();
CustomConnectionMgr.closeConnection();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment