@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof AttributeValue)) { return false; } AttributeValue other = (AttributeValue) obj; return Objects.equals(s(), other.s()) && Objects.equals(n(), other.n()) && Objects.equals(b(), other.b()) && Objects.equals(ss(), other.ss()) && Objects.equals(ns(), other.ns()) && Objects.equals(bs(), other.bs()) && Objects.equals(m(), other.m()) && Objects.equals(l(), other.l()) && Objects.equals(bool(), other.bool()) && Objects.equals(nul(), other.nul()); }
if (!isNullOrEmpty(exclusiveStartOrderId)) { scanBuilder.exclusiveStartKey(Collections.singletonMap(ORDER_ID, AttributeValue.builder().s(exclusiveStartOrderId).build())); if (result.lastEvaluatedKey() != null && !result.lastEvaluatedKey().isEmpty()) { if ((!result.lastEvaluatedKey().containsKey(ORDER_ID) || isNullOrEmpty(result.lastEvaluatedKey().get(ORDER_ID).s()))) { throw new IllegalStateException( "orderId did not exist or was not a non-empty string in the lastEvaluatedKey"); } else { builder.lastEvaluatedKey(result.lastEvaluatedKey().get(ORDER_ID).s());
builder.orderId(item.get(ORDER_ID).s()); } catch (NullPointerException e) { throw new IllegalStateException( builder.customerId(item.get("customerId").s()); } catch (NullPointerException e) { throw new IllegalStateException( builder.preTaxAmount(new BigDecimal(item.get("preTaxAmount").n())); } catch (NullPointerException | NumberFormatException e) { throw new IllegalStateException( builder.postTaxAmount(new BigDecimal(item.get("postTaxAmount").n())); } catch (NullPointerException | NumberFormatException e) { throw new IllegalStateException( builder.version(Long.valueOf(item.get("version").n())); } catch (NullPointerException | NumberFormatException e) { throw new IllegalStateException(
public static String safeGetString(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return null; } else { return av.s(); } }
private LockItem createLockItem(final GetLockOptions options, final Map<String, AttributeValue> immutableItem) { Map<String, AttributeValue> item = new HashMap<>(immutableItem); final Optional<ByteBuffer> data = Optional.ofNullable(item.get(DATA)).map(dataAttributionValue -> { item.remove(DATA); return dataAttributionValue.b().asByteBuffer(); }); final AttributeValue ownerName = item.remove(OWNER_NAME); final AttributeValue leaseDuration = item.remove(LEASE_DURATION); final AttributeValue recordVersionNumber = item.remove(RECORD_VERSION_NUMBER); final boolean isReleased = item.containsKey(IS_RELEASED); item.remove(IS_RELEASED); item.remove(this.partitionKeyName); /* * The person retrieving the lock in DynamoDB should err on the side of * not expiring the lock, so they don't start counting until after the * call to DynamoDB succeeds */ final long lookupTime = LockClientUtils.INSTANCE.millisecondTime(); final LockItem lockItem = new LockItem(this, options.getPartitionKey(), options.getSortKey(), data, options.isDeleteLockOnRelease(), ownerName.s(), Long.parseLong(leaseDuration.s()), lookupTime, recordVersionNumber.s(), isReleased, Optional.empty(), item); return lockItem; }
public static Long safeGetLong(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return null; } else { return new Long(av.n()); } }
public static List<String> safeGetSS(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return new ArrayList<String>(); } else { return av.ss(); } }
@Override public AttributeValue build() { return new AttributeValue(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("AttributeValue").add("S", s()).add("N", n()).add("B", b()).add("SS", ss()).add("NS", ns()) .add("BS", bs()).add("M", m()).add("L", l()).add("BOOL", bool()).add("NUL", nul()).build(); }
.build()); return Order.builder() .orderId(item.get(ORDER_ID).s()) .customerId(item.get("customerId").s()) .preTaxAmount(new BigDecimal(item.get("preTaxAmount").n())) .postTaxAmount(new BigDecimal(item.get("postTaxAmount").n())) .version(Long.valueOf(item.get("version").n())) .build(); } catch (ConditionalCheckFailedException e) {
public static String safeGetString(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return null; } else { return av.s(); } }
public static Long safeGetLong(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return null; } else { return new Long(av.n()); } }
public static List<String> safeGetSS(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return new ArrayList<String>(); } else { return av.ss(); } }
@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(s()); hashCode = 31 * hashCode + Objects.hashCode(n()); hashCode = 31 * hashCode + Objects.hashCode(b()); hashCode = 31 * hashCode + Objects.hashCode(ss()); hashCode = 31 * hashCode + Objects.hashCode(ns()); hashCode = 31 * hashCode + Objects.hashCode(bs()); hashCode = 31 * hashCode + Objects.hashCode(m()); hashCode = 31 * hashCode + Objects.hashCode(l()); hashCode = 31 * hashCode + Objects.hashCode(bool()); hashCode = 31 * hashCode + Objects.hashCode(nul()); return hashCode; }
new HashMap<String,AttributeValue>(); key_to_get.put("Name", AttributeValue.builder() .s(name) .build());
/** * <p> * Retrieves all the lock items from DynamoDB. * </p> * <p> * Not that this will may return a lock item even if it was released. * </p> * * @param deleteOnRelease Whether or not the {@link LockItem} should delete the item * when {@link LockItem#close()} is called on it. * @return A non parallel {@link Stream} of all the {@link LockItem}s in * DynamoDB. Note that the item can exist in the table even if it is * released, as noted by @{link LockItem#isReleased()}. */ public Stream<LockItem> getAllLocksFromDynamoDB(final boolean deleteOnRelease) { final ScanRequest scanRequest = ScanRequest.builder().tableName(this.tableName).build(); final LockItemPaginatedScanIterator iterator = new LockItemPaginatedScanIterator(this.dynamoDB, scanRequest, item -> { final String key = item.get(this.partitionKeyName).s(); GetLockOptionsBuilder options = GetLockOptions.builder(key).withDeleteLockOnRelease(deleteOnRelease); options = this.sortKeyName.map(item::get).map(AttributeValue::s).map(options::withSortKey).orElse(options); final LockItem lockItem = this.createLockItem(options.build(), item); return lockItem; }); final Iterable<LockItem> iterable = () -> iterator; return StreamSupport.stream(iterable.spliterator(), false /*isParallelStream*/); }
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "S": return Optional.ofNullable(clazz.cast(s())); case "N": return Optional.ofNullable(clazz.cast(n())); case "B": return Optional.ofNullable(clazz.cast(b())); case "SS": return Optional.ofNullable(clazz.cast(ss())); case "NS": return Optional.ofNullable(clazz.cast(ns())); case "BS": return Optional.ofNullable(clazz.cast(bs())); case "M": return Optional.ofNullable(clazz.cast(m())); case "L": return Optional.ofNullable(clazz.cast(l())); case "BOOL": return Optional.ofNullable(clazz.cast(bool())); case "NUL": return Optional.ofNullable(clazz.cast(nul())); default: return Optional.empty(); } }