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


Java GetItemResult类代码示例

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


GetItemResult类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了GetItemResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchTheValue

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
private void fetchTheValue() {

        final GetItemRequest req = new GetItemRequest().withAttributesToGet("value")
                .withTableName(TableName)
                .withKey(Collections.singletonMap("id", new AttributeValue(this.id)));
        try {
            final GetItemResult result = ddb.getItem(req);
            synchronized (this.monitor) {
                if (result.getItem() == null) {
                    this.x = new RuntimeException("not found: id=" + this.id);
                } else {
                    this.v = result.getItem().get("value").getS();
                    if (this.v == null) {
                        this.x = new RuntimeException("found but no value for: id=" + this.id);
                    }
                }
            }
        } catch (final RuntimeException x) {
            synchronized (this.monitor) {
                this.x = x;
            }
        }

    }
 
开发者ID:aztecrex,项目名称:java-translatebot,代码行数:25,代码来源:DBValueRetriever.java

示例2: fetchChannelLanguages

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
private Collection<String> fetchChannelLanguages(final String channel) {

        final String id = "channel:" + channel + ":languages";
        final GetItemRequest getItemRequest = new GetItemRequest()
                .withAttributesToGet(Collections.singletonList("value"))
                .withKey(Collections.singletonMap("id", new AttributeValue(id)))
                .withTableName(TableName);
        final GetItemResult getItemResult = ddb.getItem(getItemRequest);
        final Optional<String> maybeValue = Optional.ofNullable(getItemResult.getItem())
                .map(i -> i.get("value"))
                .map(AttributeValue::getS);
        if (!maybeValue.isPresent())
            return Collections.emptyList();

        return Arrays.asList(maybeValue.get().trim().split(" +"));
    }
 
开发者ID:aztecrex,项目名称:java-translatebot,代码行数:17,代码来源:CommandHandler.java

示例3: doInBackground

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
protected DDBTaskResult doInBackground(Void... params) {

		Log.i("doInBackground", "Starting DDBGettask");
		
		DDBTaskResult result = new DDBTaskResult();

		try {
			// Need to specify the key of our item, which is a Map of our primary key attribute(s)
			Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
			key.put("userid", new AttributeValue().withS("user1234"));
			key.put("recordid", new AttributeValue().withS("highScore"));
			 
			GetItemRequest getItemRequest = new GetItemRequest(AWSClientManager.DDB_TABLE_NAME,key);
			GetItemResult getItemResult = ddb.getItem(getItemRequest);
			 
			result.setAttributeNumber(Integer.parseInt(getItemResult.getItem().get("data").getN()));
			
		} catch (AmazonServiceException ex) {
			ex.printStackTrace();
			Log.e("ddb-get-doInBackground", ex.getMessage());
		}
	
		return result;
	}
 
开发者ID:jinman,项目名称:snake-game-aws,代码行数:25,代码来源:DDBGetTask.java

示例4: test_deleteItem_WithAllParameters

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
@Test
public void test_deleteItem_WithAllParameters() throws Exception {
  createTable();
  putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);

  Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
  key.put(TEST_ATTRIBUTE, new AttributeValue()
    .withS(TEST_ATTRIBUTE_VALUE));
  String returnValues = "";

  DeleteItemResult deleteResult = dynamoDb.deleteItem(TEST_TABLE_NAME, key, returnValues);
  AttributeValue attributeValue = deleteResult.getAttributes().get(TEST_ATTRIBUTE);

  GetItemResult getResult = getItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);

  assertThat(attributeValue.getS(), equalTo(TEST_ATTRIBUTE_VALUE));
  assertThat(getResult, nullValue());
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:19,代码来源:AmazonDynamoDBStubTest.java

示例5: test_updateItem_WithAllParameters

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
@Test
public void test_updateItem_WithAllParameters() throws Exception {
  createTable();
  putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);

  String UPDATE_ATTRIBUTE_VALUE = "UpdateAttributeValue1";

  Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
  key.put(TEST_ATTRIBUTE, new AttributeValue()
    .withS(TEST_ATTRIBUTE_VALUE));
  Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
  attributeUpdates.put(TEST_ATTRIBUTE, new AttributeValueUpdate()
    .withAction(AttributeAction.PUT)
    .withValue(new AttributeValue()
      .withS(UPDATE_ATTRIBUTE_VALUE)));
  String returnValues = "";

  UpdateItemResult result = dynamoDb.updateItem(TEST_TABLE_NAME, key, attributeUpdates, returnValues);
  Double units = result.getConsumedCapacity().getCapacityUnits();

  GetItemResult getItemResult = getItem(TEST_ATTRIBUTE, UPDATE_ATTRIBUTE_VALUE);
  String updatedValue = getItemResult.getItem().get(TEST_ATTRIBUTE).getS();

  assertThat(units.doubleValue(), equalTo(1.0));
  assertThat(updatedValue, equalTo(UPDATE_ATTRIBUTE_VALUE));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:27,代码来源:AmazonDynamoDBStubTest.java

示例6: shouldDeleteItem_withItem

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
@Test
public void shouldDeleteItem_withItem() throws Exception {
    // Given
    final StubItem createdItem = dataGenerator.createStubItem();
    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(databaseSchemaHolder);
    dynamoDbTemplate.initialize(amazonDynamoDbClient);

    // When
    dynamoDbTemplate.delete(createdItem);

    // Then
    final Map<String, AttributeValue> key = new HashMap<>();
    key.put("id", new AttributeValue(createdItem.getId()));
    final GetItemResult result = amazonDynamoDbClient
            .getItem(dataGenerator.getUnitTestSchemaName() + "." + dataGenerator.getStubItemTableName(), key);
    assertNull(result.getItem());
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:18,代码来源:DynamoDbTemplateIntegrationTest.java

示例7: shouldDeleteItem_withItemWithCompoundPk

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
@Test
public void shouldDeleteItem_withItemWithCompoundPk() throws Exception {
    // Given
    final StubWithRangeItem createdItem = dataGenerator.createStubWithRangeItem();
    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(databaseSchemaHolder);
    dynamoDbTemplate.initialize(amazonDynamoDbClient);

    // When
    dynamoDbTemplate.delete(createdItem);

    // Then
    final Map<String, AttributeValue> key = new HashMap<>();
    key.put("id", new AttributeValue(createdItem.getId()));
    key.put("supportingId", new AttributeValue(createdItem.getSupportingId()));
    final GetItemResult result = amazonDynamoDbClient.getItem(
            dataGenerator.getUnitTestSchemaName() + "." + dataGenerator.getStubItemWithRangeTableName(), key);
    assertNull(result.getItem());
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:19,代码来源:DynamoDbTemplateIntegrationTest.java

示例8: getRowByKey

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
/**
 * Get item of table with provided key-value.
 * 
 * @param tableName
 * @param combinedKey
 * @return
 */
public static Row getRowByKey(String tableName, Key... combinedKey) {
	Map<String, AttributeValue> transformedKey = new HashMap<>();
	for (Key key : combinedKey) {
		transformedKey.put(key.getName(),
				new AttributeValue().withS(key.getValue()));
	}

	GetItemResult result = DynamoDbHandler.CLIENT
			.getItem(new GetItemRequest(tableName, transformedKey));

	List<Attribute> attributes = new ArrayList<>();
	for (String resultKey : result.getItem().keySet()) {
		attributes.add(new Attribute(resultKey, result.getItem()
				.get(resultKey).getS()));
	}

	return new Row(attributes);
}
 
开发者ID:raethlein,项目名称:ColumnStoreUnifier,代码行数:26,代码来源:DynamoDbQueryHandler.java

示例9: getLastUpdate

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
/**
 * Method which returns the update information for an Aggregator process.
 * 
 * @param streamName The Stream name which is being aggregated.
 * @param applicationName The application which is hosting the aggregator.
 * @param workerId The worker ID which is running an aggregator instance.
 * @return Tuple of Last Write Time (String), Last Low Sequence, and Last
 *         High Sequence
 */
public InventoryStatus getLastUpdate(final String streamName, final String applicationName,
        final String namespace, final String shardId) {
    GetItemResult response = dynamoClient.getItem(InventoryModel.TABLE_NAME,
            getKey(streamName, applicationName, namespace, shardId));
    if (response.getItem() != null) {
        Map<String, AttributeValue> item = response.getItem();
        AttributeValue lastTime, lowSeq, highSeq = null;
        lastTime = item.get(InventoryModel.LAST_WRITE_TIME);
        lowSeq = item.get(InventoryModel.LAST_LOW_SEQ);
        highSeq = item.get(InventoryModel.LAST_HIGH_SEQ);

        return new InventoryStatus(lastTime == null ? null : lastTime.getS(),
                lowSeq == null ? null : lowSeq.getS(), highSeq == null ? null : highSeq.getS());
    } else {
        return null;
    }
}
 
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:27,代码来源:InventoryModel.java

示例10: readRow

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
private Map<String, AttributeValue> readRow(String key, String appid) {
	if (StringUtils.isBlank(key) || StringUtils.isBlank(appid)) {
		return null;
	}
	Map<String, AttributeValue> row = null;
	try {
		GetItemRequest getItemRequest = new GetItemRequest(getTableNameForAppid(appid),
				Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid))));
		GetItemResult res = client().getItem(getItemRequest);
		if (res != null && res.getItem() != null && !res.getItem().isEmpty()) {
			row = res.getItem();
		}
	} catch (Exception e) {
		logger.error("Could not read row from DB - appid={}, key={}", appid, key, e);
	}
	return (row == null || row.isEmpty()) ? null : row;
}
 
开发者ID:Erudika,项目名称:para,代码行数:18,代码来源:AWSDynamoDAO.java

示例11: loadClientByClientId

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
    GetItemResult result = client.getItem(schema.getTableName(), Collections.singletonMap(schema.getColumnClientId(), new AttributeValue(clientId)));
    
    Map<String, AttributeValue> item = result.getItem();
    if (item == null) { 
        return null;
    }
    
    String resourceIds = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnResourceIds()));
    String scopes = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnScopes()));
    String grantTypes = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorizedGrantTypes()));
    String authorities = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnAuthorities()));
    String redirectUris = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnRegisteredRedirectUris()));
    
    String clientSecret = DynamoDBUtils.nullSafeGetS(item.get(schema.getColumnClientSecret()));
    
    ClientDetails clientDetails = createClientDetails(clientId, resourceIds, scopes, grantTypes, authorities, redirectUris, clientSecret, item);
    return clientDetails;
}
 
开发者ID:Vivastream,项目名称:spring-security-oauth2-dynamodb,代码行数:21,代码来源:DynamoDBClientDetailsService.java

示例12: get

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
public <T> T get(String tableName, Map<String, AttributeValue> key, final ObjectExtractor<T> extractor, String... columnsToInclude) throws EmptyResultDataAccessException {
    Assert.notNull(tableName, "Table must not be null");
    Assert.notNull(extractor, "ObjectExtractor must not be null");
    if (logger.isDebugEnabled()) {
        logger.debug("Executing query on " + tableName + " for " + renderKey(key));
    }

    GetItemRequest request = new GetItemRequest(tableName, key, true);
    if (columnsToInclude != null && columnsToInclude.length > 0) {
        request.setAttributesToGet(Arrays.asList(columnsToInclude));
    }

    GetItemResult result = client.getItem(request);

    Map<String, AttributeValue> item = result.getItem();
    if (item == null) {
        throw new EmptyResultDataAccessException("No results found in " + tableName + "for " + renderKey(key));
    }

    return extractor.extract(item);
}
 
开发者ID:Vivastream,项目名称:spring-security-oauth2-dynamodb,代码行数:22,代码来源:DynamoDBTemplate.java

示例13: getStoredETag

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
/**
 * Retrieves the stored ETag, if one exists, from DynamoDB.
 *
 * @param dynamoDB
 *            DynamoDB client configured with a region and credentials
 * @param table
 *            The resource table name
 * @param resource
 *            The URL String of the resource
 * @return The ETag String of the last copy processed or null if the resource has never been processed
 */
public static String getStoredETag(final AmazonDynamoDB dynamoDB, final String table, final String resource) {
    String oldETag;
    // Build key to retrieve item
    final Map<String, AttributeValue> resourceKey = new HashMap<String, AttributeValue>();
    resourceKey.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    // Get item
    final GetItemResult result = dynamoDB.getItem(table, resourceKey);
    final Map<String, AttributeValue> item = result.getItem();
    if (item != null && item.containsKey(ETAG_KEY)) {
        // Item was found and contains ETag
        oldETag = item.get(ETAG_KEY).getS();
    } else {
        // Item was not found or did not contain ETag
        oldETag = null;
    }
    return oldETag;
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-mars-json-demo,代码行数:29,代码来源:DynamoDBWorkerUtils.java

示例14: testGetStoredETagExists

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
@Test
public void testGetStoredETagExists() {
    AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
    Map<String, AttributeValue> resourceKey = new HashMap<String, AttributeValue>();
    resourceKey.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    // Get item
    dynamoDB.getItem(table, resourceKey);
    Map<String, AttributeValue> resourceResult = new HashMap<String, AttributeValue>();
    resourceResult.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    resourceResult.put(DynamoDBWorkerUtils.ETAG_KEY, new AttributeValue(eTag));
    GetItemResult result = new GetItemResult().withItem(resourceResult);
    PowerMock.expectLastCall().andReturn(result);
    PowerMock.replayAll();
    String resultETag = DynamoDBWorkerUtils.getStoredETag(dynamoDB, table, resource);
    assertEquals(eTag, resultETag);
    PowerMock.verifyAll();
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-mars-json-demo,代码行数:18,代码来源:DynamoDBWorkerUtilsTest.java

示例15: retrieveItem

import com.amazonaws.services.dynamodbv2.model.GetItemResult; //导入依赖的package包/类
private static void retrieveItem() {
    try {
        
        HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
        key.put("Id", new AttributeValue().withN("120"));
        GetItemRequest getItemRequest = new GetItemRequest()
            .withTableName(tableName)
            .withKey(key)
            .withProjectionExpression("Id, ISBN, Title, Authors");
        
        GetItemResult result = client.getItem(getItemRequest);

        // Check the response.
        System.out.println("Printing item after retrieving it....");
        printItem(result.getItem());            
                    
    }  catch (AmazonServiceException ase) {
                System.err.println("Failed to retrieve item in " + tableName);
    }   

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


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