/**
* {@inheritDoc}
*/
@Override
public Void beforeCommit(TransactionData data) throws Exception {
ImprovedTransactionData improvedTransactionData = new LazyTransactionData(data);
long delta = 0;
//handle new friendships
for (Relationship newFriendship : improvedTransactionData.getAllCreatedRelationships()) {
if (newFriendship.isType(FRIEND_OF)) {
delta += (long) newFriendship.getProperty(STRENGTH, 0L);
}
}
//handle changed friendships
for (Change<Relationship> changedFriendship : improvedTransactionData.getAllChangedRelationships()) {
if (changedFriendship.getPrevious().isType(FRIEND_OF)) {
delta -= (long) changedFriendship.getPrevious().getProperty(STRENGTH, 0L);
delta += (long) changedFriendship.getCurrent().getProperty(STRENGTH, 0L);
}
}
//handle deleted friendships
for (Relationship deletedFriendship : improvedTransactionData.getAllDeletedRelationships()) {
if (deletedFriendship.isType(FRIEND_OF)) {
delta -= (long) deletedFriendship.getProperty(STRENGTH, 0L);
}
}