Search code examples
javascalaakkamicroserviceslagom

How can I proceed a delete operation in Lagom Framework?


I am a little newbie on the Lagom framework and I need to know what the right way to do a delete operation in this framework. I develop with Java and I tested two approaches:

  1. when I handle the delete event I set the state to Optional.empty () but it returns nullPointerException crashes and the line in my readSide (Cassandra DataBase) is not deleted
  2. I add a Status field to my entity and when I handle the delete event I pass it to -1. When I refer to my entity I test on State.present and status! = -1 to make sure the entity and deleted. For the readSide, the line is deleted properly

In terms of logic, I think the second approach is the most logical but I want to know if there is a good practice that the Lagom framework offers developers to do delete operations

EDIT 1 This is my ReadSideHandler code, how can I proceed to handle properly the empty option

@Override
public ReadSideHandler<AuthenticationEvent> buildHandler() {
    return readSide.<AuthenticationEvent>builder("authenticationEventOffset")
            .setGlobalPrepare(this::createTables)
            .setPrepare(tag -> prepareStatements())
            .setEventHandler(AuthenticationLoginEvent.class,
                    e -> insertAuthentication(e.getAuthentication()))
            .setEventHandler(AuthenticationLogoutEvent.class, e -> deleteAuthentication(e.getAccessToken()))
            .build();
}

Solution

  • I finally found the problem. it was bad handling in my event class, I was using Preconditions.checkNotNull on my variable which is apparently wrong. I removed this xpression from my code and everything works fine