org.vertexium.mutation.ExistingElementMutationImpl Maven / Gradle / Ivy
package org.vertexium.mutation;
import org.vertexium.*;
import org.vertexium.property.MutablePropertyImpl;
import org.vertexium.search.IndexHint;
import org.vertexium.util.Preconditions;
import java.util.ArrayList;
import java.util.List;
public abstract class ExistingElementMutationImpl implements ElementMutation, ExistingElementMutation {
private final List properties = new ArrayList<>();
private final List propertyDeletes = new ArrayList<>();
private final List propertySoftDeletes = new ArrayList<>();
private final List alterPropertyVisibilities = new ArrayList<>();
private final List setPropertyMetadatas = new ArrayList<>();
private final List extendedDatas = new ArrayList<>();
private final List extendedDataDeletes = new ArrayList<>();
private final List additionalVisibilityAddMutations = new ArrayList<>();
private final List additionalVisibilityDeleteMutations = new ArrayList<>();
private final List additionalExtendedDataVisibilities = new ArrayList<>();
private final List additionalExtendedDataVisibilityDeletes = new ArrayList<>();
private final List markPropertyHiddenMutations = new ArrayList<>();
private final List markPropertyVisibleMutations = new ArrayList<>();
private final T element;
private Visibility newElementVisibility;
private Object newElementVisibilityData;
private Visibility oldElementVisibility;
private IndexHint indexHint = IndexHint.INDEX;
public ExistingElementMutationImpl(T element) {
this.element = element;
if (element != null) {
this.oldElementVisibility = element.getVisibility();
}
}
@Override
public ElementType getElementType() {
return ElementType.getTypeFromElement(getElement());
}
@Override
public String getId() {
return getElement().getId();
}
@Override
public Visibility getVisibility() {
return getElement().getVisibility();
}
public abstract T save(Authorizations authorizations);
public ElementMutation setProperty(String name, Object value, Visibility visibility) {
return setProperty(name, value, Metadata.create(FetchHints.ALL), visibility);
}
public ElementMutation setProperty(String name, Object value, Metadata metadata, Visibility visibility) {
return addPropertyValue(DEFAULT_KEY, name, value, metadata, visibility);
}
public ElementMutation addPropertyValue(String key, String name, Object value, Visibility visibility) {
return addPropertyValue(key, name, value, Metadata.create(FetchHints.ALL), visibility);
}
public ElementMutation addPropertyValue(String key, String name, Object value, Metadata metadata, Visibility visibility) {
return addPropertyValue(key, name, value, metadata, null, visibility);
}
@Override
public ElementMutation addPropertyValue(String key, String name, Object value, Metadata metadata, Long timestamp, Visibility visibility) {
Preconditions.checkNotNull(name, "property name cannot be null for property: " + name + ":" + key);
Preconditions.checkNotNull(value, "property value cannot be null for property: " + name + ":" + key);
properties.add(new MutablePropertyImpl(key, name, value, metadata, timestamp, null, visibility, FetchHints.ALL_INCLUDING_HIDDEN));
return this;
}
public Iterable getProperties() {
return properties;
}
@Override
public Iterable getPropertyDeletes() {
return propertyDeletes;
}
@Override
public Iterable getPropertySoftDeletes() {
return propertySoftDeletes;
}
@Override
public Iterable getExtendedData() {
return extendedDatas;
}
@Override
public ElementMutation deleteProperty(Property property) {
if (!element.getFetchHints().isIncludePropertyAndMetadata(property.getName())) {
throw new VertexiumMissingFetchHintException(element.getFetchHints(), "Property " + property.getName() + " needs to be included with metadata");
}
Preconditions.checkNotNull(property, "property cannot be null");
propertyDeletes.add(new PropertyPropertyDeleteMutation(property));
return this;
}
@Override
public Iterable getExtendedDataDeletes() {
return extendedDataDeletes;
}
@Override
public ExistingElementMutation deleteProperties(String name) {
for (Property prop : this.element.getProperties(name)) {
deleteProperty(prop);
}
return this;
}
@Override
public ExistingElementMutation deleteProperties(String key, String name) {
for (Property prop : this.element.getProperties(key, name)) {
deleteProperty(prop);
}
return this;
}
@Override
public ElementMutation deleteProperty(String name, Visibility visibility) {
Property property = this.element.getProperty(name, visibility);
if (property != null) {
deleteProperty(property);
}
return this;
}
@Override
public ElementMutation deleteProperty(String key, String name, Visibility visibility) {
Property property = this.element.getProperty(key, name, visibility);
if (property != null) {
deleteProperty(property);
}
return this;
}
@Override
public ElementMutation softDeleteProperty(Property property, Object eventData) {
Preconditions.checkNotNull(property, "property cannot be null");
propertySoftDeletes.add(new PropertyPropertySoftDeleteMutation(property, eventData));
return this;
}
@Override
public ExistingElementMutation softDeleteProperties(String name, Object eventData) {
for (Property prop : this.element.getProperties(name)) {
softDeleteProperty(prop, eventData);
}
return this;
}
@Override
public ExistingElementMutation softDeleteProperties(String key, String name, Object eventData) {
for (Property prop : this.element.getProperties(key, name)) {
softDeleteProperty(prop, eventData);
}
return this;
}
@Override
public ElementMutation softDeleteProperty(String name, Visibility visibility, Object eventData) {
Property property = this.element.getProperty(name, visibility);
if (property != null) {
softDeleteProperty(property, eventData);
}
return this;
}
@Override
public ElementMutation softDeleteProperty(String key, String name, Visibility visibility, Object eventData) {
Property property = this.element.getProperty(key, name, visibility);
if (property != null) {
softDeleteProperty(property, eventData);
}
return this;
}
@Override
public ExistingElementMutation alterPropertyVisibility(Property property, Visibility visibility, Object eventData) {
if (!element.getFetchHints().isIncludePropertyAndMetadata(property.getName())) {
throw new VertexiumMissingFetchHintException(element.getFetchHints(), "Property " + property.getName() + " needs to be included with metadata");
}
this.alterPropertyVisibilities.add(new AlterPropertyVisibility(property.getKey(), property.getName(), property.getVisibility(), visibility, eventData));
return this;
}
@Override
public ExistingElementMutation alterPropertyVisibility(String name, Visibility visibility, Object eventData) {
return alterPropertyVisibility(DEFAULT_KEY, name, visibility, eventData);
}
@Override
public ExistingElementMutation alterPropertyVisibility(String key, String name, Visibility visibility, Object eventData) {
if (!element.getFetchHints().isIncludePropertyAndMetadata(name)) {
throw new VertexiumMissingFetchHintException(element.getFetchHints(), "Property " + name + " needs to be included with metadata");
}
this.alterPropertyVisibilities.add(new AlterPropertyVisibility(key, name, null, visibility, eventData));
return this;
}
@Override
public ExistingElementMutation alterElementVisibility(Visibility visibility, Object eventData) {
this.newElementVisibility = visibility;
this.newElementVisibilityData = eventData;
return this;
}
@Override
public ExistingElementMutation setPropertyMetadata(Property property, String metadataName, Object newValue, Visibility visibility) {
this.setPropertyMetadatas.add(new SetPropertyMetadata(property.getKey(), property.getName(), property.getVisibility(), metadataName, newValue, visibility));
return this;
}
@Override
public ExistingElementMutation setPropertyMetadata(String propertyName, String metadataName, Object newValue, Visibility visibility) {
return setPropertyMetadata(DEFAULT_KEY, propertyName, metadataName, newValue, visibility);
}
@Override
public ExistingElementMutation setPropertyMetadata(String propertyKey, String propertyName, String metadataName, Object newValue, Visibility visibility) {
this.setPropertyMetadatas.add(new SetPropertyMetadata(propertyKey, propertyName, null, metadataName, newValue, visibility));
return this;
}
@Override
public ElementMutation addAdditionalVisibility(String visibility, Object eventData) {
this.additionalVisibilityAddMutations.add(new AdditionalVisibilityAddMutation(visibility, eventData));
return this;
}
@Override
public ElementMutation deleteAdditionalVisibility(String visibility, Object eventData) {
this.additionalVisibilityDeleteMutations.add(new AdditionalVisibilityDeleteMutation(visibility, eventData));
return this;
}
@Override
public ElementMutation addExtendedDataAdditionalVisibility(
String tableName,
String row,
String additionalVisibility,
Object eventData
) {
this.additionalExtendedDataVisibilities.add(new AdditionalExtendedDataVisibilityAddMutation(
tableName,
row,
additionalVisibility,
eventData
));
return this;
}
@Override
public ElementMutation deleteExtendedDataAdditionalVisibility(
String tableName,
String row,
String additionalVisibility,
Object eventData
) {
this.additionalExtendedDataVisibilityDeletes.add(new AdditionalExtendedDataVisibilityDeleteMutation(
tableName,
row,
additionalVisibility,
eventData
));
return this;
}
@Override
public ExistingElementMutation addExtendedData(String tableName, String row, String column, Object value, Visibility visibility) {
return addExtendedData(tableName, row, column, null, value, null, visibility);
}
@Override
public ExistingElementMutation addExtendedData(String tableName, String row, String column, Object value, Long timestamp, Visibility visibility) {
return addExtendedData(tableName, row, column, null, value, timestamp, visibility);
}
@Override
public ExistingElementMutation addExtendedData(String tableName, String row, String column, String key, Object value, Visibility visibility) {
return addExtendedData(tableName, row, column, key, value, null, visibility);
}
@Override
public ExistingElementMutation addExtendedData(String tableName, String row, String column, String key, Object value, Long timestamp, Visibility visibility) {
this.extendedDatas.add(new ExtendedDataMutation(tableName, row, column, key, value, timestamp, visibility));
return this;
}
@Override
public ExistingElementMutation deleteExtendedData(String tableName, String row, String column, Visibility visibility) {
return deleteExtendedData(tableName, row, column, null, visibility);
}
@Override
public ExistingElementMutation deleteExtendedData(String tableName, String row, String column, String key, Visibility visibility) {
extendedDataDeletes.add(new ExtendedDataDeleteMutation(tableName, row, column, key, visibility));
return this;
}
@Override
public ElementMutation markPropertyHidden(
String key,
String name,
Visibility propertyVisibility,
Long timestamp,
Visibility visibility,
Object eventData
) {
markPropertyHiddenMutations.add(new MarkPropertyHiddenMutation(key, name, propertyVisibility, timestamp, visibility, eventData));
return this;
}
@Override
public ElementMutation markPropertyVisible(
String key,
String name,
Visibility propertyVisibility,
Long timestamp,
Visibility visibility,
Object eventData
) {
markPropertyVisibleMutations.add(new MarkPropertyVisibleMutation(key, name, propertyVisibility, timestamp, visibility, eventData));
return this;
}
@Override
public T getElement() {
return element;
}
@Override
public Visibility getNewElementVisibility() {
return newElementVisibility;
}
@Override
public Object getNewElementVisibilityData() {
return newElementVisibilityData;
}
@Override
public Visibility getOldElementVisibility() {
return oldElementVisibility;
}
@Override
public List getAlterPropertyVisibilities() {
return alterPropertyVisibilities;
}
@Override
public List getSetPropertyMetadatas() {
return setPropertyMetadatas;
}
@Override
public IndexHint getIndexHint() {
return indexHint;
}
@Override
public Iterable getAdditionalVisibilities() {
return additionalVisibilityAddMutations;
}
@Override
public Iterable getAdditionalVisibilityDeletes() {
return additionalVisibilityDeleteMutations;
}
@Override
public List getAdditionalExtendedDataVisibilities() {
return additionalExtendedDataVisibilities;
}
@Override
public List getAdditionalExtendedDataVisibilityDeletes() {
return additionalExtendedDataVisibilityDeletes;
}
@Override
public List getMarkPropertyHiddenMutations() {
return markPropertyHiddenMutations;
}
@Override
public List getMarkPropertyVisibleMutations() {
return markPropertyVisibleMutations;
}
@Override
public ElementMutation setIndexHint(IndexHint indexHint) {
this.indexHint = indexHint;
return this;
}
@Override
public boolean hasChanges() {
if (properties.size() > 0) {
return true;
}
if (propertyDeletes.size() > 0) {
return true;
}
if (propertySoftDeletes.size() > 0) {
return true;
}
if (newElementVisibility != null) {
return true;
}
if (alterPropertyVisibilities.size() > 0) {
return true;
}
if (setPropertyMetadatas.size() > 0) {
return true;
}
if (extendedDatas.size() > 0) {
return true;
}
if (extendedDataDeletes.size() > 0) {
return true;
}
if (markPropertyHiddenMutations.size() > 0) {
return true;
}
if (markPropertyVisibleMutations.size() > 0) {
return true;
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy