Operations now default to non-idempotent unless explictly set in the statement or if they contain fields that are idempotent (e.g. @Column(idempotent=true) or part of the primary key for the row).
This commit is contained in:
parent
a993af6c29
commit
d30361538c
13 changed files with 105 additions and 11 deletions
|
@ -1,7 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
for f in $(find ./src -name \*.java); do
|
||||
echo Formatting $f
|
||||
java -jar ./lib/google-java-format-1.3-all-deps.jar --replace $f
|
||||
done
|
||||
if [ "X$1" == "Xall" ]; then
|
||||
for f in $(find ./src -name \*.java); do
|
||||
echo Formatting $f
|
||||
java -jar ./lib/google-java-format-1.3-all-deps.jar --replace $f
|
||||
done
|
||||
else
|
||||
for file in $(git status --short | awk '{print $2}'); do
|
||||
echo $file
|
||||
java -jar ./lib/google-java-format-1.3-all-deps.jar --replace $file
|
||||
done
|
||||
fi
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
private boolean showCql = false;
|
||||
private boolean showValues = true;
|
||||
private ConsistencyLevel consistencyLevel;
|
||||
private boolean idempotent = true;
|
||||
private boolean idempotent = false;
|
||||
private MetricRegistry metricRegistry = new MetricRegistry();
|
||||
private Tracer zipkinTracer;
|
||||
private PrintStream printStream = System.out;
|
||||
|
@ -147,6 +147,11 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
return consistencyLevel;
|
||||
}
|
||||
|
||||
public SessionInitializer setOperationsIdempotentByDefault() {
|
||||
this.idempotent = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SessionInitializer idempotentQueryExecution(boolean idempotent) {
|
||||
this.idempotent = idempotent;
|
||||
return this;
|
||||
|
|
|
@ -108,6 +108,12 @@ public abstract class AbstractFilterOperation<E, O extends AbstractFilterOperati
|
|||
ifFilters.add(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isIdempotentOperation() {
|
||||
return filters.stream().anyMatch(filter -> !filter.getNode().getProperty().isIdempotent())
|
||||
|| super.isIdempotentOperation();
|
||||
}
|
||||
|
||||
protected List<Facet> bindFacetValues(List<Facet> facets) {
|
||||
if (facets == null) {
|
||||
return new ArrayList<Facet>();
|
||||
|
|
|
@ -47,10 +47,10 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
private ConsistencyLevel consistencyLevel;
|
||||
private ConsistencyLevel serialConsistencyLevel;
|
||||
private RetryPolicy retryPolicy;
|
||||
private boolean idempotent = false;
|
||||
private boolean enableTracing = false;
|
||||
private long[] defaultTimestamp = null;
|
||||
private int[] fetchSize = null;
|
||||
protected boolean idempotent = false;
|
||||
|
||||
public AbstractStatementOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
|
@ -247,7 +247,7 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
statement.setFetchSize(fetchSize[0]);
|
||||
}
|
||||
|
||||
if (idempotent) {
|
||||
if (isIdempotentOperation()) {
|
||||
statement.setIdempotent(true);
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,11 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
return (O) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isIdempotentOperation() {
|
||||
return idempotent;
|
||||
}
|
||||
|
||||
public Statement statement() {
|
||||
return buildStatement(false);
|
||||
}
|
||||
|
|
|
@ -134,6 +134,10 @@ public final class DeleteOperation extends AbstractFilterOperation<ResultSet, De
|
|||
return bindFacetValues(getFacets());
|
||||
}
|
||||
|
||||
protected boolean isIdempotentOperation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet sync() throws TimeoutException {
|
||||
ResultSet result = super.sync();
|
||||
|
|
|
@ -315,6 +315,12 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isIdempotentOperation() {
|
||||
return values.stream().map(v -> v._1.getProperty()).allMatch(prop -> prop.isIdempotent())
|
||||
|| super.isIdempotentOperation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T sync() throws TimeoutException {
|
||||
T result = super.sync();
|
||||
|
@ -346,10 +352,6 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
adjustTtlAndWriteTime((MapExportable) result);
|
||||
}
|
||||
cacheUpdate(uow, result, bindFacetValues());
|
||||
} else {
|
||||
if (entity.isCacheable()) {
|
||||
sessionOps.cacheEvict(bindFacetValues());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -210,6 +210,10 @@ public abstract class Operation<E> {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean isIdempotentOperation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Statement options(Statement statement) {
|
||||
return statement;
|
||||
}
|
||||
|
|
|
@ -783,6 +783,28 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isIdempotentOperation() {
|
||||
return assignments
|
||||
.values()
|
||||
.stream()
|
||||
.allMatch(
|
||||
facet -> {
|
||||
if (facet != null) {
|
||||
Set<HelenusProperty> props = facet.getProperties();
|
||||
if (props != null && props.size() > 0) {
|
||||
return props.stream().allMatch(prop -> prop.isIdempotent());
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// In this case our UPDATE statement made mutations via the List, Set, Map methods only.
|
||||
return false;
|
||||
}
|
||||
})
|
||||
|| super.isIdempotentOperation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E sync() throws TimeoutException {
|
||||
E result = super.sync();
|
||||
|
|
|
@ -63,6 +63,11 @@ public final class HelenusNamedProperty implements HelenusProperty {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdempotent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getJavaType() {
|
||||
throw new HelenusMappingException("will never called");
|
||||
|
|
|
@ -35,6 +35,7 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
private final String propertyName;
|
||||
private final Optional<IdentityName> indexName;
|
||||
private final boolean caseSensitiveIndex;
|
||||
private final boolean idempotent;
|
||||
|
||||
private final ColumnInformation columnInfo;
|
||||
|
||||
|
@ -56,6 +57,15 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
|
||||
this.columnInfo = new ColumnInformation(getter);
|
||||
|
||||
switch (this.columnInfo.getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
this.idempotent = true;
|
||||
break;
|
||||
default:
|
||||
this.idempotent = MappingUtil.idempotent(getter);
|
||||
}
|
||||
|
||||
this.genericJavaType = getter.getGenericReturnType();
|
||||
this.javaType = getter.getReturnType();
|
||||
this.abstractJavaType = MappingJavaTypes.resolveJavaType(this.javaType);
|
||||
|
@ -112,6 +122,11 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
return caseSensitiveIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdempotent() {
|
||||
return idempotent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
|
|
|
@ -37,6 +37,8 @@ public interface HelenusProperty {
|
|||
|
||||
boolean caseSensitiveIndex();
|
||||
|
||||
boolean isIdempotent();
|
||||
|
||||
Class<?> getJavaType();
|
||||
|
||||
AbstractDataType getDataType();
|
||||
|
|
|
@ -124,6 +124,15 @@ public final class MappingUtil {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean idempotent(Method getterMethod) {
|
||||
Column column = getterMethod.getDeclaredAnnotation(Column.class);
|
||||
|
||||
if (column != null) {
|
||||
return column.idempotent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getPropertyName(Method getter) {
|
||||
return getter.getName();
|
||||
}
|
||||
|
|
|
@ -59,4 +59,12 @@ public @interface Column {
|
|||
* @return true if name have to be quoted
|
||||
*/
|
||||
boolean forceQuote() default false;
|
||||
|
||||
/**
|
||||
* Used to determin if updates can be retried. Also, mutations to this field do not trigger
|
||||
* objects in the session cache to be evicted.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean idempotent() default false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue