List of usage examples for com.amazonaws.services.dynamodbv2.document KeyAttribute KeyAttribute
public KeyAttribute(String attrName, Object value)
From source file:com.exorath.service.lobbymsg.impl.DynamoDBService.java
License:Apache License
public static KeyAttribute getPrimaryKey() { return new KeyAttribute(ID_FIELD, ID_VALUE); }
From source file:com.exorath.service.party.service.DynamoDatabaseProvider.java
License:Apache License
/** * Get an update item spec for the given party argument * This does not call the update, just returns an object that can be used to update the party * * @param party Generate the update spec based on this party * @return Update spec with all the information to update the party *//*from w ww .ja v a2 s .c o m*/ private UpdateItemSpec getUpdateItemSpec(Party party) { UpdateItemSpec update = new UpdateItemSpec(); update.withPrimaryKey(new KeyAttribute(PARTY_UUID, party.getPartyUuid())); //update.addAttributeUpdate(new AttributeUpdate(PARTY_UUID).put(party.getPartyUuid())); update.addAttributeUpdate(new AttributeUpdate(OWNER_UUID).put(party.getOwnerUuid())); update.addAttributeUpdate(new AttributeUpdate(SERVER_ID).put(party.getServerId())); update.addAttributeUpdate(new AttributeUpdate(MEMBERS).put(party.getMembers())); update.addAttributeUpdate(new AttributeUpdate(EXPIRE).put(party.getExpiry())); return update; }
From source file:com.exorath.service.party.service.DynamoDatabaseProvider.java
License:Apache License
/** * Removes a party from the database using its party_uuid * * @param uuid The party unique id//ww w. j a v a 2s . c o m */ public void removeParty(String uuid) { if (getPartyFromId(uuid) != null) { DeleteItemSpec deleteItemSpec = new DeleteItemSpec(); deleteItemSpec.withPrimaryKey(new KeyAttribute(PARTY_UUID, uuid)); table.deleteItem(deleteItemSpec); } }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
private PrimaryKey getPrimaryKeyFromItem(Item item) { KeyAttribute[] keyAttributes = schemata.stream().map(keySchemaElement -> { final String attrName = keySchemaElement.getAttributeName(); Preconditions.checkArgument(item.hasAttribute(attrName), "must provide keys with " + attrName + " field set"); return new KeyAttribute(attrName, item.get(attrName)); }).toArray(KeyAttribute[]::new); return new PrimaryKey(keyAttributes); }
From source file:org.chodavarapu.jgitaws.repositories.PackDescriptionRepository.java
License:Eclipse Distribution License
private List<PrimaryKey> createKeysToDeleteList(List<PackDescriptionOperation> portion) { return operationsOfType(portion, Operation.REMOVAL).map(removal -> new PrimaryKey( new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, removal.getRepositoryDescription().getRepositoryName()), new KeyAttribute(NAME_ATTRIBUTE, packName(removal)))).collect(Collectors.toList()); }
From source file:org.chodavarapu.jgitaws.repositories.PackDescriptionRepository.java
License:Eclipse Distribution License
private List<Item> createItemsToPutList(List<PackDescriptionOperation> portion) { return operationsOfType(portion, Operation.ADDITION).map(addition -> new Item() .withPrimaryKey(new PrimaryKey( new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, addition.getRepositoryDescription().getRepositoryName()), new KeyAttribute(NAME_ATTRIBUTE, packName(addition)))) .withString(DESCRIPTION_ATTRIBUTE, toJson(addition))).collect(Collectors.toList()); }
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()); }// w w w .j ava 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); }