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


Java AmazonDynamoDB.putItem方法代码示例

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


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

示例1: createItemIfNotExists

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

		LambdaLogger logger = context.getLogger();
		AmazonDynamoDB client = createDynamoDBClient(cc);
		String functionName = context.getFunctionName();

		try {
			// Create a record if it does not exist
			PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
					.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
					.addItemEntry(COL_KEY, new AttributeValue(key))
					.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
					.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
					.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
			client.putItem(req);
			return true;
		} catch (ConditionalCheckFailedException e) {
			logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
			return false;
		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:24,代码来源:LambdaLock.java

示例2: testUpdateETag

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Test
public void testUpdateETag() {
    AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
    Map<String, AttributeValue> newItem = new HashMap<String, AttributeValue>();
    newItem.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    newItem.put(DynamoDBWorkerUtils.ETAG_KEY, new AttributeValue(eTag));
    dynamoDB.putItem(table, newItem);
    PowerMock.expectLastCall().andReturn(null);
    PowerMock.replayAll();
    DynamoDBWorkerUtils.updateETag(dynamoDB, table, resource, eTag);
    PowerMock.verifyAll();
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-mars-json-demo,代码行数:13,代码来源:DynamoDBWorkerUtilsTest.java

示例3: put

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public Item put(final Map<String, AttributeValue> attributes)
    throws IOException {
    final AmazonDynamoDB aws = this.credentials.aws();
    try {
        final PutItemRequest request = new PutItemRequest();
        request.setTableName(this.self);
        request.setItem(attributes);
        request.setReturnValues(ReturnValue.NONE);
        request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
        final PutItemResult result = aws.putItem(request);
        final long start = System.currentTimeMillis();
        Logger.info(
            this, "#put('%[text]s'): created item in '%s', %s, in %[ms]s",
            attributes, this.self,
            new PrintableConsumedCapacity(
                result.getConsumedCapacity()
            ).print(),
            System.currentTimeMillis() - start
        );
        return new AwsItem(
            this.credentials,
            this.frame(),
            this.self,
            new Attributes(attributes).only(this.keys()),
            new Array<String>(this.keys())
        );
    } catch (final AmazonClientException ex) {
        throw new IOException(
            String.format(
                "failed to put into \"%s\" with %s",
                this.self, attributes
            ),
            ex
        );
    } finally {
        aws.shutdown();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:40,代码来源:AwsTable.java

示例4: execute

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
@Override
public void execute() throws MetaModelException {
    final Map<String, AttributeValue> itemValues = new HashMap<>();
    final Column[] columns = getColumns();
    final Object[] values = getValues();
    for (int i = 0; i < columns.length; i++) {
        final Column column = columns[i];
        final Object value = values[i];
        if (column.isPrimaryKey() && value == null) {
            throw new IllegalArgumentException("Value for '" + column.getName() + "' cannot be null");
        }

        final AttributeValue attributeValue = DynamoDbUtils.toAttributeValue(value);
        itemValues.put(column.getName(), attributeValue);
    }

    final AmazonDynamoDB dynamoDb = getUpdateCallback().getDataContext().getDynamoDb();
    dynamoDb.putItem(getTable().getName(), itemValues);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:20,代码来源:DynamoDbRowInsertionBuilder.java

示例5: startsAndStops

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
/**
 * Instances can start and stop.
 * @throws Exception If something is wrong
 */
@Test
public void startsAndStops() throws Exception {
    final int port = this.reserve();
    final Instances instances = new Instances();
    instances.start(
        new File(InstancesTest.DIST), port,
        new File(System.getProperty("java.home")),
        Collections.singletonList("-inMemory")
    );
    try {
        final AmazonDynamoDB aws = new AmazonDynamoDBClient(
            new BasicAWSCredentials("AWS-key", "AWS-secret")
        );
        aws.setEndpoint(String.format("http://localhost:%d", port));
        final String table = "test";
        final String attr = "key";
        final CreateTableResult result = aws.createTable(
            new CreateTableRequest()
                .withTableName(table)
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(1L)
                        .withWriteCapacityUnits(1L)
                )
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName(attr)
                        .withAttributeType(ScalarAttributeType.S)
                )
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName(attr)
                        .withKeyType(KeyType.HASH)
                )
        );
        MatcherAssert.assertThat(
            result.getTableDescription().getTableName(),
            Matchers.equalTo(table)
        );
        aws.putItem(
            new PutItemRequest()
                .withTableName(table)
                .addItemEntry(attr, new AttributeValue("testvalue"))
        );
    } finally {
        instances.stop(port);
    }
}
 
开发者ID:jcabi,项目名称:jcabi-dynamodb-maven-plugin,代码行数:53,代码来源:InstancesTest.java

示例6: updateETag

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //导入方法依赖的package包/类
/**
 * Updates the resource table for the specified resource with the specified ETag.
 *
 * @param dynamoDB
 *            DynamoDB client configured with a region and credentials
 * @param table
 *            The DynamoDB resource table
 * @param resource
 *            The resource URL
 * @param eTag
 *            The new ETag for the resource
 */
public static void updateETag(final AmazonDynamoDB dynamoDB, final String table, final String resource,
    final String eTag) {
    // Build item
    final Map<String, AttributeValue> newResource = new HashMap<>();
    newResource.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    newResource.put(DynamoDBWorkerUtils.ETAG_KEY, new AttributeValue(eTag));
    dynamoDB.putItem(table, newResource);
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-mars-json-demo,代码行数:21,代码来源:DynamoDBWorkerUtils.java


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