Skip to content

Instantly share code, notes, and snippets.

@NickHeiner
Created March 5, 2012 16:38
Show Gist options
  • Save NickHeiner/1979177 to your computer and use it in GitHub Desktop.
Save NickHeiner/1979177 to your computer and use it in GitHub Desktop.
transactions via closures
getInvadeStartInstanceTransaction(long defendingPlayerId, long invadingPlayerId, Long defendingPlayerInstanceId, int defendingPlayerFloorCount) {
return new Transact<InstanceEntity>() {
@Override
public void run(DAOT daot) {
InstanceEntity instance =
defendingPlayerInstanceId != null
? daot.getInstanceEntity(defendingPlayerInstanceId)
: new InstanceEntity(defendingPlayerId, defendingPlayerFloorCount);
instance.addInvadingPlayer(invadingPlayerId);
instance.setCurrentFloor(invadingPlayerId, 0);
daot.put(instance);
result = instance;
}
};
}
Transact<InstanceEntity> invadeStart = getInvadeStartTransaction(foo, bar, baz, batz);
// ...
invadeStart.result();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment