本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.GetItemRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetItemRequest类的具体用法?Java GetItemRequest怎么用?Java GetItemRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetItemRequest类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了GetItemRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchTheValue
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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;
}
}
}
示例2: get
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
/**
* Get ticket.
*
* @param ticketId the ticket id
* @return the ticket
*/
public Ticket get(final String ticketId) {
final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
if (metadata != null) {
final Map<String, AttributeValue> keys = new HashMap<>();
keys.put(ColumnNames.ID.getName(), new AttributeValue(ticketId));
final GetItemRequest request = new GetItemRequest()
.withKey(keys)
.withTableName(metadata.getProperties().getStorageName());
LOGGER.debug("Submitting request [{}] to get ticket item [{}]", request, ticketId);
final Map<String, AttributeValue> returnItem = amazonDynamoDBClient.getItem(request).getItem();
if (returnItem != null) {
final Ticket ticket = deserializeTicket(returnItem);
LOGGER.debug("Located ticket [{}]", ticket);
return ticket;
}
} else {
LOGGER.warn("No ticket definition could be found in the catalog to match [{}]", ticketId);
}
return null;
}
示例3: fetchChannelLanguages
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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(" +"));
}
示例4: doInBackground
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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;
}
示例5: getRowByKey
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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);
}
示例6: readRow
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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;
}
示例7: get
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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);
}
示例8: retrieveItem
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的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);
}
}
示例9: retrieveItem
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
public static void retrieveItem(String threadId, String replyDateTime) throws IOException {
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withS(threadId));
key.put("ReplyDateTime", new AttributeValue().withS(replyDateTime));
GetItemRequest getReplyRequest = new GetItemRequest()
.withTableName(tableName)
.withKey(key)
.withConsistentRead(true);
GetItemResult getReplyResult = client.getItem(getReplyRequest);
// Decompress the reply message and print
Map<String, AttributeValue> reply = getReplyResult.getItem();
String message = decompressString(reply.get("ExtendedMessage").getB());
System.out.println("Reply message:\n"
+ " Id: " + reply.get("Id").getS() + "\n"
+ " ReplyDateTime: " + reply.get("ReplyDateTime").getS() + "\n"
+ " PostedBy: " + reply.get("PostedBy").getS() + "\n"
+ " Message: " + reply.get("Message").getS() + "\n"
+ " ExtendedMessage (decompressed): " + message);
}
示例10: describeUser
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
/**
* Returns the list of usernames stored in the user table.
*/
public void describeUser(String username, String userTable) {
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("username", new AttributeValue().withS(username));
GetItemRequest getItemRequest = new GetItemRequest()
.withTableName(userTable)
.withKey(key);
Map<String, AttributeValue> list = ddb.getItem(getItemRequest).getItem();
if (list.isEmpty()) {
System.err.println("No record found for username '" + username + "'");
return;
}
for (Entry<String, AttributeValue> entry : list.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue().getS());
}
}
示例11: executePrimaryKeyLookupQuery
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
@Override
protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn,
Object keyValue) {
final List<String> attributeNames = new ArrayList<>();
for (SelectItem selectItem : selectItems) {
attributeNames.add(selectItem.getColumn().getName());
}
final GetItemRequest getItemRequest = new GetItemRequest(table.getName(), Collections.singletonMap(
primaryKeyColumn.getName(), DynamoDbUtils.toAttributeValue(keyValue))).withAttributesToGet(
attributeNames);
final GetItemResult item = _dynamoDb.getItem(getItemRequest);
final Object[] values = new Object[selectItems.size()];
for (int i = 0; i < values.length; i++) {
final AttributeValue attributeValue = item.getItem().get(attributeNames.get(i));
values[i] = DynamoDbUtils.toValue(attributeValue);
}
return new DefaultRow(new SimpleDataSetHeader(selectItems), values);
}
示例12: getPoint
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
public GetPointResult getPoint(GetPointRequest getPointRequest) {
long geohash = S2Manager.generateGeohash(getPointRequest.getGeoPoint());
long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());
GetItemRequest getItemRequest = getPointRequest.getGetItemRequest();
getItemRequest.setTableName(config.getTableName());
AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
getItemRequest.getKey().put(config.getHashKeyAttributeName(), hashKeyValue);
getItemRequest.getKey().put(config.getRangeKeyAttributeName(), getPointRequest.getRangeKeyValue());
GetItemResult getItemResult = config.getDynamoDBClient().getItem(getItemRequest);
GetPointResult getPointResult = new GetPointResult(getItemResult);
return getPointResult;
}
示例13: getRegisteredServiceByKeys
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
private RegisteredService getRegisteredServiceByKeys(final Map<String, AttributeValue> keys) {
final GetItemRequest request = new GetItemRequest()
.withKey(keys)
.withTableName(TABLE_NAME);
LOGGER.debug("Submitting request [{}] to get service with keys [{}]", request, keys);
final Map<String, AttributeValue> returnItem = amazonDynamoDBClient.getItem(request).getItem();
if (returnItem != null) {
final RegisteredService service = deserializeServiceFromBinaryBlob(returnItem);
LOGGER.debug("Located service [{}]", service);
return service;
}
return null;
}
示例14: getItemResultMono
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
private Mono<GetItemResult> getItemResultMono(String url) {
GetItemRequest getItemRequest = new GetItemRequest();
getItemRequest.setTableName(Utils.table.websites);
HashMap<String, AttributeValue> key = new HashMap<>();
key.put(Utils.params.url, new AttributeValue(url));
getItemRequest.setKey(key);
return Mono.fromFuture(
Utils.makeCompletableFuture(
dynamoDBAsync.getItemAsync(getItemRequest)))
.doOnError((throwable -> LOG.error(Utils.error.failed_dynamo_get, url)));
}
示例15: getItemRequest
import com.amazonaws.services.dynamodbv2.model.GetItemRequest; //导入依赖的package包/类
private GetItemRequest getItemRequest(String url) {
GetItemRequest request = new GetItemRequest();
request.setTableName(Utils.table.websites);
HashMap<String, AttributeValue> key = new HashMap<>();
key.put(Utils.params.url, new AttributeValue(url));
request.setKey(key);
return request;
}