@Override public boolean exists(Serializable id, Class<?> type) { Assert.notNull(id, "Id must not be null!"); Assert.notNull(type, "Type must not be null!"); try { AerospikePersistentEntity<?> entity = mappingContext.getPersistentEntity(type); Key key = getKey(id, entity); Record record = this.client.operate(null, key, Operation.getHeader()); return record != null; } catch (AerospikeException e) { DataAccessException translatedException = exceptionTranslator.translateExceptionIfPossible(e); throw translatedException == null ? e : translatedException; } }
Record record = client.operate(writePolicy, key, Operation.touch(), Operation.getHeader());
private void doPersistWithCas(Object document, AerospikePersistentEntity<?> entity) { try { AerospikeWriteData data = AerospikeWriteData.forWrite(); converter.write(document, data); Key key = data.getKey(); Bin[] bins = data.getBinsAsArray(); ConvertingPropertyAccessor accessor = getPropertyAccessor(entity, document); WritePolicy policy = getCasAwareWritePolicy(data, entity, accessor); Operation[] operations = OperationUtils.operations(bins, Operation::put, Operation.getHeader()); Record newRecord = client.operate(policy, key, operations); accessor.setProperty(entity.getVersionProperty(), newRecord.generation); } catch (AerospikeException e) { int code = e.getResultCode(); if (code == ResultCode.KEY_EXISTS_ERROR || code == ResultCode.GENERATION_ERROR) { throw new OptimisticLockingFailureException("Save document with version value failed", e); } DataAccessException translatedException = exceptionTranslator.translateExceptionIfPossible(e); throw translatedException == null ? e : translatedException; } }