当前位置: 首页>>代码示例>>Java>>正文


Java Table.updateItem方法代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.document.Table.updateItem方法的典型用法代码示例。如果您正苦于以下问题:Java Table.updateItem方法的具体用法?Java Table.updateItem怎么用?Java Table.updateItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.dynamodbv2.document.Table的用法示例。


在下文中一共展示了Table.updateItem方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transform

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Override
public void transform(Item scoreItem, DynamoDB dynamodb) {
    String playerName = scoreItem.getString(PLAYER_NAME);
    int score = scoreItem.getInt(SCORE);
    int gameLength = scoreItem.getInt(GAME_LENGTH);
    
    /*
     * The XSpec API allows you to use DynamoDB's expression language
     * to execute expressions on the service-side.
     *  
     * https://java.awsblog.com/post/TxBG87QOQZRZJF/-DynamoDB-XSpec-API  
     */
    Table viewTable = dynamodb.getTable(PLAYER_STATS_TABLE_NAME);
    UpdateItemExpressionSpec incrementTotalOrder = new ExpressionSpecBuilder()
            .addUpdate(N(TOTAL_SCORE).add(score))
            .addUpdate(N(TOTAL_GAMEPLAY).add(gameLength))
            .addUpdate(N(TOTAL_GAMES).add(1))
            .buildForUpdate();
    viewTable.updateItem(PLAYER_NAME, playerName, incrementTotalOrder);
}
 
开发者ID:aws-samples,项目名称:reinvent2015-practicaldynamodb,代码行数:21,代码来源:DataTransformer.java

示例2: announce

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@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);
}
 
开发者ID:Netflix,项目名称:hollow-reference-implementation,代码行数:13,代码来源:DynamoDBAnnouncer.java

示例3: updateItem

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {

		AmazonDynamoDB client = createDynamoDBClient(cc);

		String functionName = context.getFunctionName();
		try {
			long sec = currentTimeMillis - expiredIntervalMillis;

			DynamoDB dynamoDB = new DynamoDB(client);
			Table table = dynamoDB.getTable(TABLE_NAME);

			Map<String, String> expressionAttributeNames = new HashMap<>();
			expressionAttributeNames.put("#created_time", COL_CREATED_TIME);

			Map<String, Object> expressionAttributeValues = new HashMap<>();
			expressionAttributeValues.put(":now", currentTimeMillis);
			expressionAttributeValues.put(":expired", sec);

			table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
					"#created_time < :expired", // ConditionExpression
					expressionAttributeNames, expressionAttributeValues);

			return true;
		} catch (ConditionalCheckFailedException e) {
			return false;
		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:30,代码来源:LambdaLock.java

示例4: main

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
public static void main(String[] args)  {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");
        
        int year = 2015;
        String title = "The Big New Movie";

        // Conditional update (will fail)

        UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey(new PrimaryKey("year", 2015, "title",  "The Big New Movie"))
            .withUpdateExpression("remove info.actors[0]")
            .withConditionExpression("size(info.actors) > :num")
            .withValueMap(new ValueMap().withNumber(":num", 3));

        System.out.println("Attempting a conditional update...");
        try {
            table.updateItem(updateItemSpec);
            System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
        } catch (ConditionalCheckFailedException e) {
            e.printStackTrace();
            System.out.println("UpdateItem failed");
        }

    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:30,代码来源:MoviesItemOps05.java

示例5: main

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
public static void main(String[] args)  {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");
        
        int year = 2015;
        String title = "The Big New Movie";
        
        UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey("year", year, "title", title)
            .withUpdateExpression("set info.rating = info.rating + :val")
            .withValueMap(new ValueMap()
                .withNumber(":val", 1));

        System.out.println("Incrementing an atomic counter...");
        try {
            table.updateItem(updateItemSpec);
            System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
        } catch (Exception e) {
            System.out.println("UpdateItem failed");
            e.printStackTrace();
        }

    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:28,代码来源:MoviesItemOps04.java

示例6: main

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
public static void main(String[] args)  {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");
        
        int year = 2015;
        String title = "The Big New Movie";

        UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey("year", year, "title", title)
            .withUpdateExpression("set info.rating = :r, info.plot=:p, info.actors=:a")
            .withValueMap(new ValueMap()
                .withNumber(":r", 5.5)
                .withString(":p", "Everything happens all at once.")
                .withList(":a", Arrays.asList("Larry","Moe","Curly")));

        System.out.println("Updating the item...");
        try {
            table.updateItem(updateItemSpec);
            System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
        } catch (Exception e) {
            System.out.println("UpdateItem failed");
            e.printStackTrace();
        }
                

    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:31,代码来源:MoviesItemOps03.java

示例7: updateAddNewAttribute

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
private static void updateAddNewAttribute() {
    Table table = dynamoDB.getTable(tableName);

    try {

        Map<String, String> expressionAttributeNames = new HashMap<String, String>();
        expressionAttributeNames.put("#na", "NewAttribute");

        UpdateItemSpec updateItemSpec = new UpdateItemSpec()
        .withPrimaryKey("Id", 121)
        .withUpdateExpression("set #na = :val1")
        .withNameMap(new NameMap()
            .with("#na", "NewAttribute"))
        .withValueMap(new ValueMap()
            .withString(":val1", "Some value"))
        .withReturnValues(ReturnValue.ALL_NEW);

        UpdateItemOutcome outcome =  table.updateItem(updateItemSpec);

        // Check the response.
        System.out.println("Printing item after adding new attribute...");
        System.out.println(outcome.getItem().toJSONPretty());           

    }   catch (Exception e) {
        System.err.println("Failed to add new attribute in " + tableName);
        System.err.println(e.getMessage());
    }        
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:29,代码来源:DocumentAPIItemCRUDExample.java

示例8: updateMultipleAttributes

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
private static void updateMultipleAttributes() {

        Table table = dynamoDB.getTable(tableName);

        try {

           UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey("Id", 120)
            .withUpdateExpression("add #a :val1 set #na=:val2")
            .withNameMap(new NameMap()
                .with("#a", "Authors")
                .with("#na", "NewAttribute"))
            .withValueMap(new ValueMap()
                .withStringSet(":val1", "Author YY", "Author ZZ")
                .withString(":val2", "someValue"))
            .withReturnValues(ReturnValue.ALL_NEW);

            UpdateItemOutcome outcome = table.updateItem(updateItemSpec);

            // Check the response.
            System.out
            .println("Printing item after multiple attribute update...");
            System.out.println(outcome.getItem().toJSONPretty());

        } catch (Exception e) {
            System.err.println("Failed to update multiple attributes in "
                    + tableName);
            System.err.println(e.getMessage());

        }
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:32,代码来源:DocumentAPIItemCRUDExample.java

示例9: updateExistingAttributeConditionally

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
private static void updateExistingAttributeConditionally() {

        Table table = dynamoDB.getTable(tableName);

        try {

            // Specify the desired price (25.00) and also the condition (price =
            // 20.00)

            UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey("Id", 120)
            .withReturnValues(ReturnValue.ALL_NEW)
            .withUpdateExpression("set #p = :val1")
            .withConditionExpression("#p = :val2")
            .withNameMap(new NameMap()
                .with("#p", "Price"))
            .withValueMap(new ValueMap()
                .withNumber(":val1", 25)
                .withNumber(":val2", 20));

            UpdateItemOutcome outcome = table.updateItem(updateItemSpec);

            // Check the response.
            System.out
            .println("Printing item after conditional update to new attribute...");
            System.out.println(outcome.getItem().toJSONPretty());

        } catch (Exception e) {
            System.err.println("Error updating item in " + tableName);
            System.err.println(e.getMessage());
        }
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:33,代码来源:DocumentAPIItemCRUDExample.java


注:本文中的com.amazonaws.services.dynamodbv2.document.Table.updateItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。