Created
July 18, 2014 03:36
-
-
Save josh-padnick/932eb6f32b9fe8e0ee9a to your computer and use it in GitHub Desktop.
Ugly Sample of JDBC Promises in Play (probably with anti-patterns)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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