com.amazonaws.services.dynamodbv2.document.DynamoDB类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中com.amazonaws.services.dynamodbv2.document.DynamoDB类的一些代码示例,展示了DynamoDB类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DynamoDB类的具体详情如下:
包路径:com.amazonaws.services.dynamodbv2.document.DynamoDB
类名称:DynamoDB

DynamoDB介绍

[英]DynamoDB Document API. This class is the entry point to make use of this library.
[中]DynamoDB文档API。此类是使用此库的入口点。

代码示例

代码示例来源:origin: apache/nifi

protected synchronized DynamoDB getDynamoDB() {
  if ( dynamoDB == null )
    dynamoDB = new DynamoDB(client);
  return dynamoDB;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Creates the specified table in DynamoDB.
 */
public Table createTable(String tableName,
    List<KeySchemaElement> keySchema,
    List<AttributeDefinition> attributeDefinitions,
    ProvisionedThroughput provisionedThroughput) {
  return createTable(new CreateTableRequest()
    .withTableName(tableName)
    .withKeySchema(keySchema)
    .withAttributeDefinitions(attributeDefinitions)
    .withProvisionedThroughput(provisionedThroughput));
}

代码示例来源:origin: apache/nifi

tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue)
      .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset)));
  } else {
    tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue)
BatchWriteItemOutcome outcome = dynamoDB.batchWriteItem(tableWriteItems);

代码示例来源:origin: aws-samples/aws-dynamodb-examples

public static void putItem(
  String issueId, String title, String description, String createDate,
  String lastUpdateDate, String dueDate, Integer priority,
    String status) {
  Table table = dynamoDB.getTable(tableName);
  Item item = new Item()
    .withPrimaryKey("IssueId", issueId)
    .withString("Title", title)
    .withString("Description", description)
    .withString("CreateDate", createDate)
    .withString("LastUpdateDate", lastUpdateDate)
    .withString("DueDate", dueDate)
    .withNumber("Priority", priority)
    .withString("Status", status);
  table.putItem(item);
}

代码示例来源:origin: aws-samples/aws-dynamodb-examples

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";

    try {
      table.putItem(new Item()
        .withPrimaryKey("year", year, "title", title)
        .withJSON("info", "{\"plot\" : \"Something happens.\"}"));
      System.out.println("PutItem succeeded: " + 
        table.getItem("year", year, "title", title).toJSONPretty());

    } catch (Exception e) {
      System.out.println("PutItem failed");
      e.printStackTrace();
    }       
  }
}

代码示例来源:origin: aws-samples/aws-dynamodb-examples

DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
infoMap.put("plot",  "Nothing happens at all.");
infoMap.put("rating",  0.0);
Item item = new Item()
  .withPrimaryKey(new PrimaryKey("year", year, "title", title))
  .withMap("info", infoMap);
  table.putItem(putItemSpec);
  System.out.println("PutItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
} catch (ConditionalCheckFailedException e) {
  e.printStackTrace(System.err);

代码示例来源:origin: aws-samples/aws-dynamodb-examples

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();
  }
}

代码示例来源:origin: johnewart/gearman-java

private boolean validateOrCreateTable(Integer readUnits, Integer writeUnits) {
  try {
    Table table =  dynamoDB.getTable(tableName);
    TableDescription tableDescription = table.describe();
            .withWriteCapacityUnits(writeUnits.longValue())
            .withReadCapacityUnits(readUnits.longValue());
        table.updateTable(throughput);
          table.waitForActive();
          LOG.info(
              String.format("Table %s already existed, updated R/W units of %d/%d units/sec",
      Table table = dynamoDB.createTable(request);

代码示例来源:origin: aws-samples/aws-dynamodb-examples

public static void main(String[] args) throws Exception {
  AmazonDynamoDBClient client = new AmazonDynamoDBClient();
  client.setEndpoint("http://localhost:8000");
  DynamoDB dynamoDB = new DynamoDB(client);
  Table table = dynamoDB.getTable("Movies");
  JsonParser parser = new JsonFactory()
    .createParser(new File("moviedata.json"));
      
  Iterator<JsonNode> iter = getRootNode(parser).iterator();
  
  ObjectNode currentNode;
  while (iter.hasNext()) {
    currentNode = (ObjectNode) iter.next();
        int year = getYear(currentNode);
    String title = getTitle(currentNode);
    System.out.println("Adding movie: " + year + " " + title);
    table.putItem(new Item()
      .withPrimaryKey("year", year, "title", title)
      .withJSON("info",  getInfo(currentNode)));
  }
  
  parser.close();
}

代码示例来源:origin: org.wildfly.camel/wildfly-camel-itests-common

public static void deleteTable(AmazonDynamoDB client, String tableName) throws InterruptedException {
  new DynamoDB(client).getTable(tableName).delete();
}

代码示例来源:origin: com.nimbusds/infinispan-cachestore-dynamodb

table = new DynamoDB(client).createTable(requestFactory
    .resolveCreateTableRequest()
    .withProvisionedThroughput(
  Loggers.MAIN_LOG.info("[DS0129] DynamoDB store: Created table {} for cache {}", table.getTableName(), getCacheName());
  table.waitForActive();
} catch (InterruptedException e) {
  throw new PersistenceException("Interrupted while awaiting DynamoDB table to become active: " + e.getMessage(), e);
Loggers.MAIN_LOG.info("[DS0141] DynamoDB store: Table properties: " + table.getDescription());

代码示例来源:origin: aws-samples/aws-dynamodb-examples

DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
  .withValueMap(valueMap);
ItemCollection<QueryOutcome> items = table.query(querySpec);
while (iterator.hasNext()) {
  item = iterator.next();
  System.out.println(item.getNumber("year") + ": " + item.getString("title"));
  .withValueMap(valueMap);
items = table.query(querySpec);
iterator = items.iterator();
while (iterator.hasNext()) {
  item = iterator.next();
  System.out.println(item.toString());

代码示例来源:origin: org.springframework.integration/spring-integration-aws

public DynamoDbMetadataStore(AmazonDynamoDBAsync dynamoDB, String tableName) {
  Assert.notNull(dynamoDB, "'dynamoDB' must not be null.");
  Assert.hasText(tableName, "'tableName' must not be empty.");
  this.dynamoDB = dynamoDB;
  this.table =
      new DynamoDB(this.dynamoDB)
          .getTable(tableName);
}

代码示例来源:origin: aws-samples/aws-dynamodb-examples

private static void deleteTable(String tableName){
  try {
    
    Table table = dynamoDB.getTable(tableName);
    table.delete();
    System.out.println("Waiting for " + tableName
      + " to be deleted...this may take a while...");
    table.waitForDelete();
        } catch (Exception e) {
    System.err.println("Failed to delete table " + tableName);
    e.printStackTrace(System.err);
  }
}

代码示例来源:origin: org.wildfly.camel/wildfly-camel-itests-common

public static TableDescription createTable(AmazonDynamoDB client, String tableName) throws InterruptedException {
  CreateTableRequest tableReq = new CreateTableRequest().withTableName(tableName)
      .withKeySchema(new KeySchemaElement("Id", KeyType.HASH))
      .withAttributeDefinitions(new AttributeDefinition("Id", ScalarAttributeType.N))
      .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L))
      .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_AND_OLD_IMAGES));
  DynamoDB dynamoDB = new DynamoDB(client);
  Table table = dynamoDB.createTable(tableReq);
  return table.waitForActive();
}

代码示例来源:origin: aws-samples/aws-dynamodb-examples

.withItemsToPut(new Item()
    .withPrimaryKey("Name", "Amazon RDS")
    .withNumber("Threads", 0));
BatchWriteItemOutcome outcome = dynamoDB.batchWriteItem(forumTableWriteItems, threadTableWriteItems);
  } else {
    System.out.println("Retrieving the unprocessed items");
    outcome = dynamoDB.batchWriteItemUnprocessed(unprocessedItems);

代码示例来源:origin: aws-samples/aws-dynamodb-examples

System.out.println(dynamoDB.createTable(createTableRequest));
  Table table = dynamoDB.getTable(tableName);
  table.waitForActive();
} catch (InterruptedException e) {
  e.printStackTrace();

代码示例来源:origin: aws-samples/aws-dynamodb-examples

static void createExampleTable() {
  try {
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition()
      .withAttributeName("Id")
      .withAttributeType("N"));
    ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement()
      .withAttributeName("Id")
      .withKeyType(KeyType.HASH));
    CreateTableRequest request = new CreateTableRequest()
      .withTableName(tableName)
      .withKeySchema(keySchema)
      .withAttributeDefinitions(attributeDefinitions)
      .withProvisionedThroughput(new ProvisionedThroughput()
        .withReadCapacityUnits(5L)
        .withWriteCapacityUnits(6L));
    System.out.println("Issuing CreateTable request for " + tableName);
    Table table = dynamoDB.createTable(request);
    System.out.println("Waiting for " + tableName
      + " to be created...this may take a while...");
    table.waitForActive();
    getTableInformation();
  } catch (Exception e) {
    System.err.println("CreateTable request failed for " + tableName);
    System.err.println(e.getMessage());
  }
}

代码示例来源:origin: aws-samples/aws-dynamodb-examples

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");
      
  // Conditional delete (will fail)
  
  DeleteItemSpec deleteItemSpec = new DeleteItemSpec()
    .withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie"))
    .withConditionExpression("info.rating <= :val")
    .withValueMap(new ValueMap()
        .withNumber(":val", 5.0));
  
  System.out.println("Attempting a conditional delete...");
  try {
    table.deleteItem(deleteItemSpec);
    System.out.println("DeleteItem succeeded");
  } catch (Exception e) {
    e.printStackTrace();
    System.out.println("DeleteItem failed");
  }
}

代码示例来源:origin: aws-samples/aws-dynamodb-examples

public static void retrieveItem(String threadId, String replyDateTime) throws IOException {
  
  Table table = dynamoDB.getTable(tableName);
  
  GetItemSpec spec = new GetItemSpec()
    .withPrimaryKey("Id", threadId, "ReplyDateTime", replyDateTime)
    .withConsistentRead(true);
  Item item = table.getItem(spec);
  
  
 // Uncompress the reply message and print
  String uncompressed = uncompressString(ByteBuffer.wrap(item.getBinary("ExtendedMessage")));
  
  System.out.println("Reply message:\n"
    + " Id: " + item.getString("Id") + "\n" 
    + " ReplyDateTime: " + item.getString("ReplyDateTime") + "\n" 
    + " PostedBy: " + item.getString("PostedBy") + "\n"
    + " Message: " + item.getString("Message") + "\n"
    + " ExtendedMessage (uncompressed): " + uncompressed + "\n");
}

相关文章