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


Java Table.putItem方法代码示例

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


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

示例1: create

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Override public Void create(Group group) {
  Item item = preparePutItem(group);

  PutItemSpec putItemSpec = new PutItemSpec()
      .withItem(item)
      .withConditionExpression("attribute_not_exists(#ns_key)")
      .withNameMap(new NameMap().with("#ns_key", HASH_KEY));

  Table table = dynamoDB.getTable(groupTableName);
  final Supplier<PutItemOutcome> putItemOutcomeSupplier = () -> {
    try {
      return table.putItem(putItemSpec);
    } catch (ConditionalCheckFailedException e) {
      throwConflictAlreadyExists(group);
      return null;
    }
  };
  return putItem(group, putItemOutcomeSupplier);
}
 
开发者ID:dehora,项目名称:outland,代码行数:20,代码来源:DefaultGroupStorage.java

示例2: tryAddMissingPartition

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
private boolean tryAddMissingPartition(String dyanmoDBTaableName,DynamoDB dynamoDBClient, Partition partition){

        Table ddbTable= dynamoDBClient.getTable(dyanmoDBTaableName);

        Item item=new Item()
                .withPrimaryKey("PartitionSpec",partition.spec())
                .withString("PartitionPath",partition.path())
                .withString("PartitionName", partition.name());

        PutItemSpec itemSpec=new PutItemSpec()
                .withItem(item)
                .withConditionExpression("attribute_not_exists(#ps)")
                .withNameMap(new NameMap()
                        .with("#ps","PartitionSpec"));

        try{
            ddbTable.putItem(itemSpec);
            System.out.println("Item was added to the table.PartitionSpec="+partition.spec()+"; Path="+partition.path());
            return true;
        }
        catch(ConditionalCheckFailedException e){
            System.out.println(e.toString());
            System.out.println("Item already exists. PartitionSpec="+partition.spec()+"; Path="+partition.path());
            return false;
        }
    }
 
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:27,代码来源:CreateAthenaPartitionsBasedOnS3EventWithDDB.java

示例3: testPrimaryAndSortKeySpecification

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Test
public void testPrimaryAndSortKeySpecification() throws Exception {
  String pk = "pk", sort = "sort";
  Table table = createHashAndSortTable(pk, sort);
  Item item = new Item();
  item.with(pk, "p1");
  item.with(sort, "s1");
  item.with(COL1, "1");
  table.putItem(item);

  Item item2 = new Item();
  item2.with(pk, "p1");
  item2.with(sort, "s0");
  item2.with(COL1, "2");
  table.putItem(item2);
  // should create a get
  String query = selectStarWithPK("p1", "t", table) + " AND sort = 's1'";
  verify(runAndReadResults(query), item);
  validatePlanWithGets(query,
    pkEquals("p1").and(create("equal", "sort", "s1")));
  // should create a query
  query = selectStarWithPK("p1", "t", table) + " AND sort >= 's1'";
  verify(runAndReadResults(query), item);
  validatePlanWithQueries(query, of(pkEquals("p1").and(
    DynamoPlanValidationUtils.gte("sort", "s1")), null));
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:27,代码来源:TestDynamoFilterPushdown.java

示例4: testSimpleScan

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Test
public void testSimpleScan() throws Exception {
  Item item = item();
  item.with(COL1, 1);
  Table table = createTableWithItems(item);
  String select = "SELECT *" + from(table) + "t WHERE t." + COL1 + " = 1";
  verify(runAndReadResults(select), item);
  DynamoFilterSpec spec = DynamoPlanValidationUtils.equals(COL1, 1);
  validatePlanWithScan(select, spec);

  Item item2 = new Item();
  item2.with(PK, "pk2");
  item2.with(COL1, 2);
  table.putItem(item2);
  verify(runAndReadResults(select), item);
  // plan doesn't change as the table gets larger
  validatePlanWithScan(select, spec);
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:19,代码来源:TestDynamoFilterPushdown.java

示例5: testMultiRangeQuery

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Test
  public void testMultiRangeQuery() throws Exception {
    Table table = createHashAndSortTable(PK, COL1);
    Item item = item();
    item.with(COL1, "1");
    table.putItem(item);
    Item i2 = item();
    i2.with(COL1, "2");
    table.putItem(i2);
    String query = "SELECT *" + from(table) + "t WHERE " +
                   "t." + PK + " = 'pk'" + " AND (" +
                   "t." + COL1 + " = '1'" +
                   " AND " +
                   "t." + COL1 + " >= '2')";
    verify(runAndReadResults(query));
    validatePlanWithQueries(query, of(
      pkEquals("pk").and(DynamoPlanValidationUtils.equals(COL1, "1")),
      null),
      of(pkEquals("pk").and(DynamoPlanValidationUtils.gte(COL1, "2")),
        null));
//    verify(runAndReadResults("SELECT *" + from(table) + "t WHERE " +
//                             "t." + PK + " = 'pk'" + " AND (" +
//                             "t." + COL1 + " = '1'" +
//                             " OR " +
//                             "t." + COL1 + " >= '2')"), item, i2);
  }
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:27,代码来源:TestDynamoFilterPushdown.java

示例6: unlock

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
/**
 * Release a distributed lock, by setting its expiry to 0
 *
 * This always succeeds. There should be no legitimate contention between processes for lock release, as long as
 * this is only called when you're *certain* that the process already holds the lock.
 */
@Override
public void unlock(String lockKey) {
    lockKey = getEnvironmentSpecificLockKey(lockKey);

    logger.info("Releasing lock [{}]", lockKey);

    Table table = dynamoDb.getTable(tableName);

    try {
        Item item = new Item()
            .withPrimaryKey(TABLE_KEY, lockKey)
            .withLong(LOCK, 0) // setting an expiry of 0 means the lock is always expired, therefore released
            .withString(TABLE_CREATED_AT, OffsetDateTime.now(clock).toString());

        table.putItem(item);
        logger.info("Released lock [{}]", lockKey);
    } catch (Exception ex) {
        logger.error("Failed to release lock [{}]", lockKey);
    }
}
 
开发者ID:vvondra,项目名称:fleet-cron,代码行数:27,代码来源:DynamoDbLocker.java

示例7: loadSampleForums

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

        Table table = dynamoDB.getTable(tableName);

        try {

            System.out.println("Adding data to " + tableName);

            Item item = new Item().withPrimaryKey("Name", "Amazon DynamoDB")
                .withString("Category", "Amazon Web Services")
                .withNumber("Threads", 2).withNumber("Messages", 4)
                .withNumber("Views", 1000);
            table.putItem(item);

            item = new Item().withPrimaryKey("Name", "Amazon S3")
                .withString("Category", "Amazon Web Services")
                .withNumber("Threads", 0);
            table.putItem(item);

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

示例8: loadSampleForums

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

        Table table = dynamoDB.getTable(tableName);

        try {

            System.out.println("Adding data to " + tableName);

            Item item = new Item().withPrimaryKey("Name", "Amazon DynamoDB")
                .withString("Category", "Amazon Web Services")
                .withNumber("Threads", 2)
                .withNumber("Messages", 4)
                .withNumber("Views", 1000);
            table.putItem(item);

            item = new Item().withPrimaryKey("Name", "Amazon S3")
                .withString("Category", "Amazon Web Services")
                .withNumber("Threads", 0);
            table.putItem(item);

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

示例9: 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";

        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();
        }       
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:24,代码来源:MoviesItemOps01.java

示例10: createItem

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
public static void createItem(String threadId, String replyDateTime) throws IOException {
    
    Table table = dynamoDB.getTable(tableName);

    // Craft a long message
    String messageInput = "Long message to be compressed in a lengthy forum reply";
    
    // Compress the long message
    ByteBuffer compressedMessage = compressString(messageInput.toString());
    
    table.putItem(new Item()
        .withPrimaryKey("Id", threadId)
        .withString("ReplyDateTime", replyDateTime)
        .withString("Message", "Long message follows")
        .withBinary("ExtendedMessage", compressedMessage)
        .withString("PostedBy", "User A"));
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:18,代码来源:DocumentAPIItemBinaryExample.java

示例11: uploadProduct

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
private static void uploadProduct(String tableName, int productIndex) {

        Table table = dynamoDB.getTable(tableName);

        try {
            System.out.println("Processing record #" + productIndex);

            Item item = new Item()
                .withPrimaryKey("Id", productIndex)
                .withString("Title", "Book " + productIndex + " Title")
                .withString("ISBN", "111-1111111111")
                .withStringSet(
                    "Authors",
                    new HashSet<String>(Arrays.asList("Author1")))
                .withNumber("Price", 2)
                .withString("Dimensions", "8.5 x 11.0 x 0.5")
                .withNumber("PageCount", 500)
                .withBoolean("InPublication", true)
                .withString("ProductCategory", "Book");
            table.putItem(item);

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

示例12: putItem

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
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);
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:21,代码来源:DocumentAPIGlobalSecondaryIndexExample.java

示例13: writePacket

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Override
public void writePacket(String deviceId, Date time, MAVLinkPacket packet) throws IOException {
    if (deviceId == null || deviceId.isEmpty() || time == null || packet == null) {
        return;
    }

    Table table = dynamoDB.getTable(tableName);

    table.putItem(new Item().withPrimaryKey(ATTR_DEVICE_ID, deviceId, ATTR_TIME, time.getTime())
            .withNumber(ATTR_MSG_ID, packet.msgid)
            .withJSON(ATTR_MESSAGE, toJSON(packet)));
}
 
开发者ID:envirover,项目名称:SPLGroundControl,代码行数:13,代码来源:DynamoDBOutputStream.java

示例14: saveRelation

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
@Override public Void saveRelation(Group group, String relationHashKey, String relationRangeKey) {

    Item item = new Item()
        .withString(GroupStorage.SUBJECT_KEY, relationHashKey)
        .withString(GroupStorage.OBJECT_RELATION_KEY, relationRangeKey);

    Table table = dynamoDB.getTable(groupGraphTableName);

    DynamoDbCommand<PutItemOutcome> cmd = new DynamoDbCommand<>("saveRelation",
        () -> table.putItem(item),
        () -> {
          throw new RuntimeException("saveRelation");
        },
        dynamodbGraphWriteHystrix,
        metrics);

    PutItemOutcome outcome = cmd.execute();

    logger.info("{} /dynamodb_put_item_result=[{}]",
        kvp("op", "saveRelation",
            "appkey", group.getKey(),
            "hash_key", relationHashKey,
            "range_key", relationRangeKey,
            "result", "ok"),

        outcome.getPutItemResult().toString());

    return null;
  }
 
开发者ID:dehora,项目名称:outland,代码行数:30,代码来源:DefaultGroupStorage.java

示例15: putAndSelectStar

import com.amazonaws.services.dynamodbv2.document.Table; //导入方法依赖的package包/类
protected Table putAndSelectStar(Item... items) throws Exception {
  Table table = createHashTable();
  for (Item item : items) {
    table.putItem(item);
  }
  selectStar(table, items);
  return table;
}
 
开发者ID:fineoio,项目名称:drill-dynamo-adapter,代码行数:9,代码来源:BaseDynamoTest.java


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