use of io.automatiko.engine.api.workflow.ConflictingVersionException in project automatiko-engine by automatiko-io.
the class CassandraProcessInstances method update.
@Override
public void update(String id, ProcessInstance instance) {
String resolvedId = resolveId(id, instance);
LOGGER.debug("update() called for instance {}", resolvedId);
byte[] data = codec.encode(marshaller.marhsallProcessInstance(instance));
if (data == null) {
return;
}
Collection<String> tags = new LinkedHashSet<>(instance.tags().values());
tags.add(resolvedId);
if (instance.businessKey() != null) {
tags.add(instance.businessKey());
}
SimpleStatement statement = QueryBuilder.update(config.keyspace().orElse("automatiko"), tableName).setColumn(CONTENT_FIELD, bindMarker()).setColumn(TAGS_FIELD, bindMarker()).setColumn(VERSION_FIELD, literal(((AbstractProcessInstance<?>) instance).getVersionTracker() + 1)).setColumn(STATUS_FIELD, literal(((AbstractProcessInstance<?>) instance).status())).whereColumn(INSTANCE_ID_FIELD).isEqualTo(literal(resolvedId)).ifColumn(VERSION_FIELD).isEqualTo(literal(((AbstractProcessInstance<?>) instance).getVersionTracker())).build();
ResultSet rs = cqlSession.execute(cqlSession.prepare(statement).bind(ByteBuffer.wrap(data), tags));
if (!rs.wasApplied()) {
throw new ConflictingVersionException("Process instance with id '" + instance.id() + "' has older version than the stored one");
}
disconnect(instance);
cachedInstances.remove(resolvedId);
}
Aggregations