com.kenshoo.pl.entity.FieldsCombination 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;
import java.util.Collection;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toSet;
/**
* The final state of a certain combination of fields in the database.
* This will be the state of fields after all changes have been applied on the current state and contains the final values of the entity's fields.
*
*/
public class FieldsCombination> implements FieldsValueMap {
private final EntityChange entityChange;
private final CurrentEntityState currentState;
private final Collection> fields;
private final ChangeOperation changeOperation;
public FieldsCombination(EntityChange entityChange, CurrentEntityState currentState, Stream> fields, ChangeOperation changeOperation) {
this.entityChange = entityChange;
this.currentState = currentState;
this.fields = fields.collect(toSet());
this.changeOperation = changeOperation;
}
@Override
public boolean containsField(EntityField field) {
return entityChange.containsField(field) || currentState.containsField(field);
}
@Override
public T get(EntityField field) {
if (!fields.contains(field)) {
throw new IllegalArgumentException("Illegal field: " + field);
}
if (entityChange.isFieldChanged(field)) {
return entityChange.get(field);
} else {
if (changeOperation == ChangeOperation.UPDATE) {
return currentState.get(field);
} else {
return null;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy