Skip to content

Instantly share code, notes, and snippets.

@mrnovalles
Created December 1, 2011 17:03
Show Gist options
  • Save mrnovalles/1418215 to your computer and use it in GitHub Desktop.
Save mrnovalles/1418215 to your computer and use it in GitHub Desktop.
Every DB Call opens a session, and then closes it
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