Example usage for com.amazonaws.services.dynamodbv2.document AttributeUpdate AttributeUpdate

List of usage examples for com.amazonaws.services.dynamodbv2.document AttributeUpdate AttributeUpdate

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document AttributeUpdate AttributeUpdate.

Prototype

public AttributeUpdate(String attributeName) 

Source Link

Document

Used to update an attribute.

Usage

From source file:com.exorath.service.lastserver.dynamodb.DynamoDBService.java

License:Apache License

@Override
public PutResult setLastServer(UUID playerId, String gameId, String requestBody) {
    if (gameId == null) {
        return new PutResult("gameId can't be null.");
    }/*from w ww . ja va 2 s  .c  o m*/

    Map<String, String> body;
    try {
        body = Gson.fromJson(requestBody, MapStringStringType);
    } catch (JsonSyntaxException ex) {
        return new PutResult(ex.getMessage());
    }

    UpdateItemSpec spec = new UpdateItemSpec().withPrimaryKey(PRIM_KEY, playerId.toString())
            .withAttributeUpdate(new AttributeUpdate(GAMEID_ATTR).put(gameId),
                    new AttributeUpdate(MAPID_ATTR).put(body.get(MAPID_ATTR)),
                    new AttributeUpdate(FLAVORID_ATTR).put(body.get(FLAVORID_ATTR)));
    try {
        UpdateItemOutcome outcome = table.updateItem(spec);
        logger.info("Successfully set last server data for player " + playerId + ": gameId(" + gameId
                + ") mapId(" + body.get(MAPID_ATTR) + ") flavorId(" + body.get(FLAVORID_ATTR) + ")");
        return new PutResult();
    } catch (ConditionalCheckFailedException ex) {
        logger.warn("Failed to set last server data for player" + playerId + ": gameId(" + gameId + ") mapId("
                + body.get(MAPID_ATTR) + ") flavorId(" + body.get(FLAVORID_ATTR) + ")\n:" + ex.getMessage());
        return new PutResult(ex.getMessage());
    }
}

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   ww w . j av  a 2s .  com*/
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.treasurehunt.dynamodb.DynamoDBService.java

License:Apache License

@Override
public PutResult setTreasure(UUID playerId, String treasureId) {
    UpdateItemSpec spec = new UpdateItemSpec().withPrimaryKey(PRIM_KEY, playerId.toString())
            .withAttributeUpdate(new AttributeUpdate(TREASURES_FIELD).addElements(treasureId))
            .withReturnValues(ReturnValue.UPDATED_OLD);
    try {//from  w  ww  .  ja  v a 2 s  . c o  m
        UpdateItemOutcome outcome = table.updateItem(spec);
        if (!outcome.getUpdateItemResult().toString().contains(treasureId)) {
            logger.info("Successfully set treasure " + treasureId + " for player " + playerId);
            return new PutResult();
        } else {
            logger.warn(
                    "Attempted to set treasure " + treasureId + " for player " + playerId + " a second time");
            return new PutResult("Treasure " + treasureId + " already set for player " + playerId);
        }
    } catch (ConditionalCheckFailedException ex) {
        logger.warn(
                "Updated treasure " + treasureId + " for player " + playerId + " failed\n:" + ex.getMessage());
        return new PutResult(ex.getMessage());
    }
}

From source file:com.yahoo.athenz.zts.cert.impl.DynamoDBCertRecordStoreConnection.java

License:Apache License

@Override
public boolean updateX509CertRecord(X509CertRecord certRecord) {

    final String primaryKey = getPrimaryKey(certRecord.getProvider(), certRecord.getInstanceId(),
            certRecord.getService());//  ww w. j a  v a 2 s .co  m

    try {
        UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey(KEY_PRIMARY, primaryKey)
                .withAttributeUpdate(new AttributeUpdate(KEY_INSTANCE_ID).put(certRecord.getInstanceId()),
                        new AttributeUpdate(KEY_PROVIDER).put(certRecord.getProvider()),
                        new AttributeUpdate(KEY_SERVICE).put(certRecord.getService()),
                        new AttributeUpdate(KEY_CURRENT_SERIAL).put(certRecord.getCurrentSerial()),
                        new AttributeUpdate(KEY_CURRENT_IP).put(certRecord.getCurrentIP()),
                        new AttributeUpdate(KEY_CURRENT_TIME).put(certRecord.getCurrentTime().getTime()),
                        new AttributeUpdate(KEY_PREV_SERIAL).put(certRecord.getPrevSerial()),
                        new AttributeUpdate(KEY_PREV_IP).put(certRecord.getPrevIP()),
                        new AttributeUpdate(KEY_PREV_TIME).put(certRecord.getPrevTime().getTime()),
                        new AttributeUpdate(KEY_CLIENT_CERT).put(certRecord.getClientCert()),
                        new AttributeUpdate(KEY_TTL)
                                .put(certRecord.getCurrentTime().getTime() / 1000L + expiryTime));
        table.updateItem(updateItemSpec);
        return true;
    } catch (Exception ex) {
        LOGGER.error("DynamoDB Update Error for {}: {}/{}", primaryKey, ex.getClass(), ex.getMessage());
        return false;
    }
}

From source file:io.ignitr.dispatchr.manager.core.data.ClientRepository.java

License:Apache License

/**
 *
 * @param newClient//from  ww  w  .j a  v  a 2  s . c om
 * @return
 */
public Observable<Client> update(Client newClient) {
    return findOne(newClient.getClientId()).last().map(oldClient -> {
        Table clientTable = dynamoDB.getTable(CLIENT_TABLE_NAME);

        UpdateItemOutcome outcome = clientTable
                .updateItem(new UpdateItemSpec().withPrimaryKey("clientId", oldClient.getClientId())
                        .withAttributeUpdate(new AttributeUpdate("ownerName").put(newClient.getOwnerName()))
                        .withAttributeUpdate(new AttributeUpdate("ownerEmail").put(newClient.getOwnerEmail())));

        Item item = outcome.getItem();

        return convertFromItem(item);
    });
}

From source file:org.chodavarapu.jgitaws.repositories.ConfigurationRepository.java

License:Eclipse Distribution License

public Observable<Void> updateConfiguration(String repositoryName, String text) {
    return configuration.getDynamoClient().updateItem(configuration.getConfigurationsTableName(),
            new UpdateItemSpec().withPrimaryKey(REPOSITORY_NAME_ATTRIBUTE, repositoryName)
                    .withAttributeUpdate(new AttributeUpdate(TEXT_ATTRIBUTE).put(text)),
            () -> new CreateTableRequest().withTableName(configuration.getConfigurationsTableName())
                    .withKeySchema(new KeySchemaElement().withAttributeName(REPOSITORY_NAME_ATTRIBUTE)
                            .withKeyType(KeyType.HASH))
                    .withAttributeDefinitions(
                            new AttributeDefinition().withAttributeName(REPOSITORY_NAME_ATTRIBUTE)
                                    .withAttributeType(ScalarAttributeType.S))
                    .withProvisionedThroughput(new ProvisionedThroughput(
                            configuration.getInitialConfigurationsTableReadThroughput(),
                            configuration.getInitialConfigurationsTableWriteThroughput())));
}

From source file:org.springframework.integration.aws.metadata.DynamoDbMetaDataStore.java

License:Apache License

@Override
public String putIfAbsent(String key, String value) {
    Assert.hasText(key, "'key' must not be empty.");
    Assert.hasText(value, "'value' must not be empty.");

    awaitForActive();/*from   w  w w. jav  a2 s.c om*/

    try {
        this.table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY, key)
                .withAttributeUpdate(new AttributeUpdate(VALUE).put(value))
                .withExpected(new Expected(KEY).notExist()));

        return null;
    } catch (ConditionalCheckFailedException e) {
        return get(key);
    }
}

From source file:org.springframework.integration.aws.metadata.DynamoDbMetaDataStore.java

License:Apache License

@Override
public boolean replace(String key, String oldValue, String newValue) {
    Assert.hasText(key, "'key' must not be empty.");
    Assert.hasText(oldValue, "'value' must not be empty.");
    Assert.hasText(newValue, "'newValue' must not be empty.");

    awaitForActive();//w  w  w. java  2  s .c  o  m

    try {
        return this.table.updateItem(new UpdateItemSpec().withPrimaryKey(KEY, key)
                .withAttributeUpdate(new AttributeUpdate(VALUE).put(newValue))
                .withExpected(new Expected(VALUE).eq(oldValue)).withReturnValues(ReturnValue.UPDATED_NEW))
                .getItem() != null;
    } catch (ConditionalCheckFailedException e) {
        return false;
    }
}