@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(tableName()); hashCode = 31 * hashCode + Objects.hashCode(key()); hashCode = 31 * hashCode + Objects.hashCode(attributesToGet()); hashCode = 31 * hashCode + Objects.hashCode(consistentRead()); hashCode = 31 * hashCode + Objects.hashCode(returnConsumedCapacityAsString()); hashCode = 31 * hashCode + Objects.hashCode(projectionExpression()); hashCode = 31 * hashCode + Objects.hashCode(expressionAttributeNames()); return hashCode; }
@Override public GetItemRequest build() { return new GetItemRequest(this); }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("GetItemRequest").add("TableName", tableName()).add("Key", key()) .add("AttributesToGet", attributesToGet()).add("ConsistentRead", consistentRead()) .add("ReturnConsumedCapacity", returnConsumedCapacityAsString()) .add("ProjectionExpression", projectionExpression()).add("ExpressionAttributeNames", expressionAttributeNames()) .build(); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof GetItemRequest)) { return false; } GetItemRequest other = (GetItemRequest) obj; return Objects.equals(tableName(), other.tableName()) && Objects.equals(key(), other.key()) && Objects.equals(attributesToGet(), other.attributesToGet()) && Objects.equals(consistentRead(), other.consistentRead()) && Objects.equals(returnConsumedCapacityAsString(), other.returnConsumedCapacityAsString()) && Objects.equals(projectionExpression(), other.projectionExpression()) && Objects.equals(expressionAttributeNames(), other.expressionAttributeNames()); }
private GetItemResponse readFromDynamoDB(final String key, final Optional<String> sortKey) { final Map<String, AttributeValue> dynamoDBKey = new HashMap<>(); dynamoDBKey.put(this.partitionKeyName, AttributeValue.builder().s(key).build()); if (this.sortKeyName.isPresent()) { dynamoDBKey.put(this.sortKeyName.get(), AttributeValue.builder().s(sortKey.get()).build()); } final GetItemRequest getItemRequest = GetItemRequest.builder().tableName(tableName).key(dynamoDBKey) .consistentRead(true) .build(); return this.dynamoDB.getItem(getItemRequest); }
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "TableName": return Optional.ofNullable(clazz.cast(tableName())); case "Key": return Optional.ofNullable(clazz.cast(key())); case "AttributesToGet": return Optional.ofNullable(clazz.cast(attributesToGet())); case "ConsistentRead": return Optional.ofNullable(clazz.cast(consistentRead())); case "ReturnConsumedCapacity": return Optional.ofNullable(clazz.cast(returnConsumedCapacityAsString())); case "ProjectionExpression": return Optional.ofNullable(clazz.cast(projectionExpression())); case "ExpressionAttributeNames": return Optional.ofNullable(clazz.cast(expressionAttributeNames())); default: return Optional.empty(); } }
/** * Returns an order or throws if the order does not exist. * @param orderId id of order to get * @return the order if it exists * @throws OrderDoesNotExistException if the order does not exist */ public Order getOrder(final String orderId) { try { return Optional.ofNullable( dynamoDb.getItem(GetItemRequest.builder() .tableName(tableName) .key(Collections.singletonMap(ORDER_ID, AttributeValue.builder().s(orderId).build())) .build())) .map(GetItemResponse::item) .map(this::convert) .orElseThrow(() -> new OrderDoesNotExistException("Order " + orderId + " does not exist")); } catch (ResourceNotFoundException e) { throw new TableDoesNotExistException("Order table " + tableName + " does not exist"); } }
throws ProvisionedThroughputExceededException, ResourceNotFoundException, RequestLimitExceededException, InternalServerErrorException, AwsServiceException, SdkClientException, DynamoDbException { return getItem(GetItemRequest.builder().applyMutation(getItemRequest).build());
return getItem(GetItemRequest.builder().applyMutation(getItemRequest).build());
log.debug("Getting lease with key {}", leaseKey); GetItemRequest request = GetItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(leaseKey)) .consistentRead(consistentReads).build(); final AWSExceptionManager exceptionManager = createExceptionManager();
log.debug("Getting lease with key {}", leaseKey); GetItemRequest request = GetItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(leaseKey)) .consistentRead(consistentReads).build(); final AWSExceptionManager exceptionManager = createExceptionManager();