Refine search
@Override public AttributeValue marshall(Object obj) { String string = (String) obj; if (string.length() == 0) { // Sticking with the legacy behavior for now. return null; } return new AttributeValue().withS(string); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getS() == null) ? 0 : getS().hashCode()); hashCode = prime * hashCode + ((getN() == null) ? 0 : getN().hashCode()); hashCode = prime * hashCode + ((getB() == null) ? 0 : getB().hashCode()); hashCode = prime * hashCode + ((getSS() == null) ? 0 : getSS().hashCode()); hashCode = prime * hashCode + ((getNS() == null) ? 0 : getNS().hashCode()); hashCode = prime * hashCode + ((getBS() == null) ? 0 : getBS().hashCode()); hashCode = prime * hashCode + ((getM() == null) ? 0 : getM().hashCode()); hashCode = prime * hashCode + ((getL() == null) ? 0 : getL().hashCode()); hashCode = prime * hashCode + ((getNULL() == null) ? 0 : getNULL().hashCode()); hashCode = prime * hashCode + ((getBOOL() == null) ? 0 : getBOOL().hashCode()); return hashCode; }
@Override public AttributeValue marshall(Object obj) { Boolean bool = (Boolean) obj; if (bool == null || bool == false) { return new AttributeValue().withN("0"); } else { return new AttributeValue().withN("1"); } } }
@Override public AttributeValue marshall(Object obj) { return new AttributeValue().withB((ByteBuffer) obj); } }
@Override public AttributeValue marshall(Object obj) { return new AttributeValue().withS( DateUtils.formatISO8601Date((Date) obj)); } }
update.getValue() .withB(entry.getValue().getB()) .withBS(entry.getValue().getBS()) .withN(entry.getValue().getN()) .withNS(entry.getValue().getNS()) .withS(entry.getValue().getS()) .withSS(entry.getValue().getSS()) .withM(entry.getValue().getM()) .withL(entry.getValue().getL()) .withNULL(entry.getValue().getNULL()) .withBOOL(entry.getValue().getBOOL()); } else { updateValues.put(entry.getKey(), new AttributeValueUpdate(entry.getValue(), "PUT"));
update.getValue() .withB(entry.getValue().getB()) .withBS(entry.getValue().getBS()) .withN(entry.getValue().getN()) .withNS(entry.getValue().getNS()) .withS(entry.getValue().getS()) .withSS(entry.getValue().getSS()); } else { updateValues.put(entry.getKey(), new AttributeValueUpdate(entry.getValue(), "PUT"));
AttributeValue result = new AttributeValue(); if (value == null) { return result.withNULL(Boolean.TRUE); } else if (value instanceof Boolean) { return result.withBOOL((Boolean)value); } else if (value instanceof String) { return result.withS((String) value); } else if (value instanceof BigDecimal) { BigDecimal bd = (BigDecimal) value; return result.withN(bd.toPlainString()); } else if (value instanceof Number) { return result.withN(value.toString()); } else if (value instanceof byte[]) { return result.withB(ByteBuffer.wrap((byte[]) value)); } else if (value instanceof ByteBuffer) { return result.withB((ByteBuffer) value); } else if (value instanceof Set) { Set<Object> set = (Set<Object>) value; if (set.size() == 0) { result.setSS(new LinkedHashSet<String>()); return result; @SuppressWarnings("unchecked") Set<String> ss = (Set<String>) value; result.setSS(new ArrayList<String>(ss)); } else if (element instanceof Number) { @SuppressWarnings("unchecked")
public static void updateItem(AmazonDynamoDBClient client, String tableName, String id, String val) { java.util.Map<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("Id", new AttributeValue().withN(id)); Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>(); AttributeValueUpdate update = new AttributeValueUpdate() .withAction(AttributeAction.PUT) .withValue(new AttributeValue().withS(val)); attributeUpdates.put("attribute-2", update); UpdateItemRequest updateItemRequest = new UpdateItemRequest() .withTableName(tableName) .withKey(key) .withAttributeUpdates(attributeUpdates); client.updateItem(updateItemRequest); }
keys.put("id", new AttributeValue().withS("hashKey")); Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(); AttributeValueUpdate update = new AttributeValueUpdate().withValue(new AttributeValue() .withS("newValue1")); updates.put("firstValue", update); MockTwoValuePlusVersionClass.class, "aws-android-sdk-dynamodbmapper-test", keys, updates, config); assertEquals(transformed.get("firstValue").getValue().getS(), "NEWVALUE1"); assertNull(transformed.get("id"));
@Override protected void onNonKeyAttribute(String attributeName, AttributeValue currentValue) { /* If it's a set attribute and the mapper is configured with APPEND_SET, * we do an "ADD" update instead of the default "PUT". */ if (getLocalSaveBehavior() == SaveBehavior.APPEND_SET) { if (currentValue.getBS() != null || currentValue.getNS() != null || currentValue.getSS() != null) { getAttributeValueUpdates().put( attributeName, new AttributeValueUpdate().withValue( currentValue).withAction("ADD")); return; } } /* Otherwise, we do the default "PUT" update. */ super.onNonKeyAttribute(attributeName, currentValue); }
@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 public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<Date> dates = (Set<Date>) obj; List<String> timestamps = new ArrayList<String>(dates.size()); for (Date date : dates) { timestamps.add(DateUtils.formatISO8601Date(date)); } return new AttributeValue().withSS(timestamps); } }
@Override public BigDecimal increment(final BigDecimal delta) throws IOException { return new BigDecimal( this.item.put( DyCounters.ATTR_VALUE, new AttributeValueUpdate( new AttributeValue().withN(delta.toString()), AttributeAction.ADD ) ).get(DyCounters.ATTR_VALUE).getN() ); } }
@Test public void testObject() { assertEquals(new HashMap<String, AttributeValue>() { { put("name", new AttributeValue("name")); put("value", new AttributeValue().withN("123")); } }, convert("getObject", new SubClass()).getM()); }
/** * Make an update. * @param action The action * @return The update */ public AttributeValueUpdate update(final AttributeAction action) { return new AttributeValueUpdate() .withAction(action) .withValue( new AttributeValue().withN( Long.toString(this.longValue()) ) ); }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("updatekey: " + key + " from table: " + table); } Map<String, AttributeValueUpdate> attributes = new HashMap<>(values.size()); for (Entry<String, ByteIterator> val : values.entrySet()) { AttributeValue v = new AttributeValue(val.getValue().toString()); attributes.put(val.getKey(), new AttributeValueUpdate().withValue(v).withAction("PUT")); } UpdateItemRequest req = new UpdateItemRequest(table, createPrimaryKey(key), attributes); try { dynamoDB.updateItem(req); } catch (AmazonServiceException ex) { LOGGER.error(ex); return Status.ERROR; } catch (AmazonClientException ex) { LOGGER.error(ex); return CLIENT_ERROR; } return Status.OK; }
@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("insertkey: " + primaryKeyName + "-" + key + " from table: " + table); } Map<String, AttributeValue> attributes = createAttributes(values); // adding primary key attributes.put(primaryKeyName, new AttributeValue(key)); if (primaryKeyType == PrimaryKeyType.HASH_AND_RANGE) { // If the primary key type is HASH_AND_RANGE, then what has been put // into the attributes map above is the range key part of the primary // key, we still need to put in the hash key part here. attributes.put(hashKeyName, new AttributeValue(hashKeyValue)); } PutItemRequest putItemRequest = new PutItemRequest(table, attributes); try { dynamoDB.putItem(putItemRequest); } catch (AmazonServiceException ex) { LOGGER.error(ex); return Status.ERROR; } catch (AmazonClientException ex) { LOGGER.error(ex); return CLIENT_ERROR; } return Status.OK; }
protected Object getValue(Map<String, AttributeValue> item, String keyName, String valueType) { if ( ALLOWABLE_VALUE_STRING.getValue().equals(valueType)) { AttributeValue val = item.get(keyName); if ( val == null ) return val; else return val.getS(); } else { AttributeValue val = item.get(keyName); if ( val == null ) return val; else return val.getN(); } }
@Override public List<MaterializedView> getMaterializedViews(String project) { List<Map<String, AttributeValue>> items = dynamoDBClient.scan(new ScanRequest() .withTableName(tableConfig.getTableName()) .withFilterExpression("#P = :pValue AND begins_with(type_table_name, :prefix)") .withExpressionAttributeNames(of("#P", "project")) .withExpressionAttributeValues(of( ":pValue", new AttributeValue(project), ":prefix", new AttributeValue("materialized_")))).getItems(); return items.stream() .map(item -> JsonHelper.read(item.get("value").getS(), MaterializedView.class)) .collect(Collectors.toList()); }