2

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();
}
  • This seems to be specifically for read-sides, right? – erip Jul 06 '18 at 22:32
  • There are two ways to have a reference on your data : By ReadSide or by EntityRef which is the fastest if you do not have a filter to do. My problem is if I do the second approach without adding the field status, I will always have a Ref on my data while I made a delete operation – tarek hentati Jul 09 '18 at 09:31
  • Yes, I know. :) My question is -- are you asking specifially about read-sides? – erip Jul 09 '18 at 15:55
  • First question : is the first approach correct? If yes, how to handle the crash of nullPointerException in the readSide ? – tarek hentati Jul 09 '18 at 16:02

2 Answers2

0

The first approach is correct, but you should handle empty option on the read side properly

Rafał Sobota
  • 1,468
  • 1
  • 17
  • 32
0

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