List of usage examples for com.amazonaws.services.dynamodbv2.document.utils NameMap NameMap
NameMap
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
private <P extends ParaObject> String readPageFromSharedTable(String appid, Pager pager, LinkedList<P> results) { String lastKeyFragment = ""; ValueMap valueMap = new ValueMap().withString(":aid", appid); NameMap nameMap = null;// w w w .jav a 2 s. co m if (!StringUtils.isBlank(pager.getLastKey())) { lastKeyFragment = " and #stamp > :ts"; valueMap.put(":ts", pager.getLastKey()); nameMap = new NameMap().with("#stamp", Config._TIMESTAMP); } Index index = getSharedIndex(); QuerySpec spec = new QuerySpec().withMaxPageSize(pager.getLimit()).withMaxResultSize(pager.getLimit()) .withKeyConditionExpression(Config._APPID + " = :aid" + lastKeyFragment).withValueMap(valueMap) .withNameMap(nameMap); if (index != null) { Page<Item, QueryOutcome> items = index.query(spec).firstPage(); for (Item item : items) { P obj = ParaObjectUtils.setAnnotatedFields(item.asMap()); if (obj != null) { results.add(obj); } } } if (!results.isEmpty()) { return Long.toString(results.peekLast().getTimestamp()); } else { return null; } }
From source file:com.netflix.hollow.example.producer.infrastructure.DynamoDBAnnouncer.java
License:Apache License
@Override public void announce(long stateVersion) { Table table = dynamoDB.getTable(tableName); UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("namespace", blobNamespace) .withUpdateExpression("set #version = :ver").withNameMap(new NameMap().with("#version", "version")) .withValueMap(new ValueMap().withNumber(":ver", stateVersion)); table.updateItem(updateItemSpec);//from w ww . ja va 2 s . c o m }
From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java
License:Eclipse Distribution License
public Observable<Boolean> compareAndPut(String repositoryName, Ref oldRef, Ref newRef) { boolean isSymbolic = newRef.isSymbolic(); boolean isPeeled = newRef.isPeeled(); String target = newRef.isSymbolic() ? newRef.getTarget().getName() : newRef.getObjectId().name(); logger.debug("Saving ref {} -> {} in repository {}", newRef.getName(), target, repositoryName); UpdateItemSpec updateSpec = new UpdateItemSpec() .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName), new KeyAttribute(NAME_ATTRIBUTE, newRef.getName()))); StringBuilder updateExpression = new StringBuilder(COMPARE_AND_PUT_EXPRESSION); ValueMap valueMap = new ValueMap().withString(":target", target).withBoolean(":isSymbolic", isSymbolic) .withBoolean(":isPeeled", isPeeled); if (isPeeled && newRef.getPeeledObjectId() != null) { updateExpression.append(", "); updateExpression.append(PEELED_TARGET_ATTRIBUTE); updateExpression.append(" = :peeledTarget"); valueMap = valueMap.withString(":peeledTarget", newRef.getPeeledObjectId().name()); }//from w ww .j a va 2 s . co m if (oldRef != null && oldRef.getStorage() != Ref.Storage.NEW) { String expected = oldRef.isSymbolic() ? oldRef.getTarget().getName() : oldRef.getObjectId().name(); updateSpec = updateSpec.withConditionExpression("#target = :expected") .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE)); valueMap = valueMap.withString(":expected", expected); } updateSpec = updateSpec.withUpdateExpression(updateExpression.toString()).withValueMap(valueMap); return configuration.getDynamoClient() .updateItem(configuration.getRefsTableName(), updateSpec, tableCreator).map(v -> true) .doOnNext(v -> logger.debug("Saved ref {} in repository {}", newRef.getName(), repositoryName)) .onErrorReturn(t -> false); }
From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java
License:Eclipse Distribution License
public Observable<Boolean> compareAndRemove(String repositoryName, Ref ref) { String expected = ref.isSymbolic() ? ref.getTarget().getName() : ref.getObjectId().name(); logger.debug("Removing ref {} -> {} from repository {}", ref.getName(), expected, repositoryName); return configuration.getDynamoClient() .deleteItem(configuration.getRefsTableName(), new DeleteItemSpec() .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName), new KeyAttribute(NAME_ATTRIBUTE, ref.getName()))) .withConditionExpression("#target = :expected") .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE)) .withValueMap(new ValueMap().with(":expected", expected))) .map(v -> true).doOnNext(v -> logger.debug("Removed ref {} -> {} from repository {}", ref.getName(), expected, repositoryName)) .onErrorReturn(t -> false); }