Search in sources :

Example 6 with ConflictingVersionException

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConflictingVersionException(io.automatiko.engine.api.workflow.ConflictingVersionException) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet)

Aggregations

ConflictingVersionException (io.automatiko.engine.api.workflow.ConflictingVersionException)6 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)2 LinkedHashSet (java.util.LinkedHashSet)2 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 ProcessInstanceEntity (io.automatiko.engine.addons.persistence.db.model.ProcessInstanceEntity)1 Model (io.automatiko.engine.api.Model)1 EventBatch (io.automatiko.engine.api.event.EventBatch)1 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)1 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)1 ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)1 ProcessInstanceExecutionException (io.automatiko.engine.api.workflow.ProcessInstanceExecutionException)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 Document (org.bson.Document)1 StaleObjectStateException (org.hibernate.StaleObjectStateException)1