public Pair<Update.Where, Object[]> generateCollectionAndMapUpdateOperation(PersistentStateHolder context, DirtyCheckChangeSet changeSet) {
log.trace("Generate collection/map update operation for dirty change set {}", changeSet);
final Object entity = context.getEntity();
final EntityMeta meta = context.getEntityMeta();
final EntityMetaConfig metaConfig = meta.config();
final Optional<Integer> ttlO = context.getTtl();
final Optional<Long> timestampO = context.getTimestamp();
final List<CASCondition> CASConditions = context.getCasConditions();
final Update.Conditions conditions = update(metaConfig.getKeyspaceName(), metaConfig.getTableName()).onlyIf();
List<Object> casEncodedValues = addAndEncodeCasConditions(meta, CASConditions, conditions);
Object[] boundValues = new Object[] { };
if (ttlO.isPresent()) {
conditions.using(ttl(ttlO.get()));
boundValues = addAll(boundValues, new Object[] { ttlO.get() });
}
if (timestampO.isPresent()) {
conditions.using(timestamp(timestampO.get()));
boundValues = addAll(boundValues, new Object[] { timestampO.get() });
}
final CollectionAndMapChangeType operationType = changeSet.getChangeType();
Pair<Assignments, Object[]> updateClauseAndBoundValues;
switch (operationType) {
case SET_TO_LIST_AT_INDEX:
updateClauseAndBoundValues = changeSet.generateUpdateForSetAtIndexElement(conditions);
break;
case REMOVE_FROM_LIST_AT_INDEX:
updateClauseAndBoundValues = changeSet.generateUpdateForRemovedAtIndexElement(conditions);
break;
default:
throw new AchillesException(String.format("Should not generate non-prepared statement for collection/map change of type '%s'", operationType));
}
final Pair<Update.Where, Object[]> whereClauseAndBoundValues = meta.getIdMeta().forStatementGeneration().generateWhereClauseForUpdate(entity, changeSet.getPropertyMeta(), updateClauseAndBoundValues.left);
boundValues = addAll(addAll(boundValues, addAll(updateClauseAndBoundValues.right, whereClauseAndBoundValues.right)), casEncodedValues.toArray());
return Pair.create(whereClauseAndBoundValues.left, boundValues);
}