com.kenshoo.pl.entity.internal.CreationDateEnricher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.pl.entity.internal;
import com.kenshoo.pl.entity.ChangeContext;
import com.kenshoo.pl.entity.ChangeEntityCommand;
import com.kenshoo.pl.entity.ChangeOperation;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.SupportedChangeOperation;
import com.kenshoo.pl.entity.spi.PostFetchCommandEnricher;
import java.time.Instant;
import java.util.Collection;
import java.util.stream.Stream;
/**
* Created by yuvalr on 2/3/16.
*/
public class CreationDateEnricher> implements PostFetchCommandEnricher {
private final EntityField creationDateField;
public CreationDateEnricher(EntityField creationDateField) {
this.creationDateField = creationDateField;
}
@Override
public void enrich(Collection extends ChangeEntityCommand> changeEntityCommands, ChangeOperation changeOperation, ChangeContext changeContext) {
Instant now = Instant.now();
changeEntityCommands.forEach(command -> command.set(creationDateField, now));
}
@Override
public Stream> fieldsToEnrich() {
return Stream.of(creationDateField);
}
@Override
public SupportedChangeOperation getSupportedChangeOperation() {
return SupportedChangeOperation.CREATE;
}
}