@Override public MaterializedView getMaterializedView(String project, String tableName) { Map<String, AttributeValue> item = dynamoDBClient.getItem(new GetItemRequest().withTableName(tableConfig.getTableName()) .withAttributesToGet("value") .withKey(of( "project", new AttributeValue(project), "type_table_name", new AttributeValue("materialized_" + tableName)))).getItem(); if (item == null) { throw new NotExistsException("Materialized view"); } return JsonHelper.read(item.get("value").getS(), MaterializedView.class); }
@Override public <T> T getConfig(String project, String configName, Class<T> clazz) { Map<String, AttributeValue> item = dynamoDBClient.getItem(new GetItemRequest() .withTableName(tableConfig.getTableName()) .withKey(new SimpleImmutableEntry<>("project", new AttributeValue(project)), new SimpleImmutableEntry<>("id", new AttributeValue(configName))) .withAttributesToGet("value") .withConsistentRead(true)).getItem(); if (item == null) { return null; } String value = item.get("value").getS(); return value == null ? null : JsonHelper.read(value, clazz); }
@Override protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn, Object keyValue) { final List<String> attributeNames = new ArrayList<>(); for (SelectItem selectItem : selectItems) { attributeNames.add(selectItem.getColumn().getName()); } final GetItemRequest getItemRequest = new GetItemRequest(table.getName(), Collections.singletonMap( primaryKeyColumn.getName(), DynamoDbUtils.toAttributeValue(keyValue))).withAttributesToGet( attributeNames); final GetItemResult item = _dynamoDb.getItem(getItemRequest); final Object[] values = new Object[selectItems.size()]; for (int i = 0; i < values.length; i++) { final AttributeValue attributeValue = item.getItem().get(attributeNames.get(i)); values[i] = DynamoDbUtils.toValue(attributeValue); } return new DefaultRow(new SimpleDataSetHeader(selectItems), values); }
private void checkExpectedValues(String tableName, Map<String, AttributeValue> itemKey, Map<String, ExpectedAttributeValue> expectedValues) { if (expectedValues != null && !expectedValues.isEmpty()) { for (Map.Entry<String, ExpectedAttributeValue> entry : expectedValues.entrySet()) { if ((entry.getValue().isExists() == null || entry.getValue().isExists() == true) && entry.getValue().getValue() == null) { throw new IllegalArgumentException("An explicit value is required when Exists is null or true, " + "but none was found in expected values for item with key " + itemKey + ": " + expectedValues); } } // simulate by loading the item and checking the values; // this also has the effect of locking the item, which gives the // same behavior GetItemResult result = getItem(new GetItemRequest() .withAttributesToGet(expectedValues.keySet()) .withKey(itemKey) .withTableName(tableName)); Map<String, AttributeValue> item = result.getItem(); try { checkExpectedValues(expectedValues, item); } catch (ConditionalCheckFailedException e) { throw new ConditionalCheckFailedException("Item " + itemKey + " had unexpected attributes: " + e.getMessage()); } } }