Created
December 1, 2011 17:03
-
-
Save mrnovalles/1418215 to your computer and use it in GitHub Desktop.
Every DB Call opens a session, and then closes it
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 static BlockInfo getBlockInfo(long blockId) { | |
int tries = RETRY_COUNT; | |
boolean done = false; | |
Session session = DBConnector.sessionFactory.getSession(); //Gets a session | |
Transaction tx = session.currentTransaction(); //Starts transaction | |
while (done == false && tries > 0) { | |
try { | |
tx.begin(); | |
BlockInfo ret = getBlockInfoInternal(blockId, session, false); | |
tx.commit(); | |
session.flush(); | |
done=true; | |
return ret; | |
} | |
catch (ClusterJException e){ | |
tx.rollback(); | |
System.err.println("getBlockInfo failed " + e.getMessage()); | |
tries--; | |
} | |
finally { | |
session.close (); | |
} | |
} | |
return null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment