All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.gc.aafc.dina.jpa.OneToManyDinaService Maven / Gradle / Ivy

The newest version!
package ca.gc.aafc.dina.jpa;

import ca.gc.aafc.dina.entity.DinaEntity;
import ca.gc.aafc.dina.service.DefaultDinaService;
import lombok.NonNull;
import org.springframework.validation.SmartValidator;

import java.util.List;

/**
 * OneToManyDinaService is a DefaultDinaService that will handle resolving associations for children of a
 * declared parent type. The constructor will require you to submit a list of {@link OneToManyFieldHandler},
 * one for each One to many field you want to resolve. Fields without handlers will not be resolved.
 *
 * @param  Type of Parent
 */
public abstract class OneToManyDinaService extends DefaultDinaService {

  private final List> handlers;

  public OneToManyDinaService(
    BaseDAO baseDAO,
    SmartValidator validator,
    @NonNull List> handlers
  ) {
    super(baseDAO, validator);
    this.handlers = handlers;
  }

  @Override
  public E create(E entity) {
    handlers.forEach(h -> h.onCreate(entity));
    return super.create(entity);
  }

  @Override
  public E update(E entity) {
    handlers.forEach(h -> h.onUpdate(entity, this));
    return super.update(entity);
  }

  @Override
  public void delete(E entity) {
    handlers.forEach(h -> h.onDelete(entity));
    super.delete(entity);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy