Java 类com.amazonaws.services.dynamodbv2.model.PutItemResult 实例源码

项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbDelegate.java   
public PutItemResult putItem(final PutItemRequest request) throws BackendException {
    setUserAgent(request);
    PutItemResult result;
    final int bytes = calculateItemSizeInBytes(request.getItem());
    getBytesHistogram(PUT_ITEM, request.getTableName()).update(bytes);
    final int wcu = computeWcu(bytes);
    timedWriteThrottle(PUT_ITEM, request.getTableName(), wcu);

    final Timer.Context apiTimerContext = getTimerContext(PUT_ITEM, request.getTableName());
    try {
        result = client.putItem(request);
    } catch (Exception e) {
        throw processDynamoDbApiException(e, PUT_ITEM, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    meterConsumedCapacity(PUT_ITEM, result.getConsumedCapacity());

    return result;
}
项目:milton-aws    文件:DynamoDBServiceImpl.java   
/**
   * Put given item into the table. If the item exists, it replaces the entire
   * item. Instead of replacing the entire item, if you want to update only
   * specific attributes, you can use the updateItem method.
   * 
   * @param item
   */
  @Override
  public PutItemResult putItem(String tableName, Map<String, AttributeValue> item) {
    if (item == null || item.isEmpty()) {
        LOG.warn("Does not support store null or empty entity in table " + tableName);
        return null;
    }

    LOG.info("Successfully putted item " + item.toString() + " into " + tableName);

      try {
          PutItemRequest putItemRequest = new PutItemRequest(tableName, item);
          PutItemResult putItemResult = dynamoDBClient.putItem(putItemRequest);
    LOG.info("Putted status: " + putItemResult);
          return putItemResult;
      } catch (AmazonServiceException ase) {
          LOG.error("Failed to put given item into the " + tableName, ase);
      } catch (AmazonClientException ace) {
        LOG.error("Failed to put given item into the " + tableName, ace);
}
      return null;
  }
项目:oada-ref-impl-java    文件:DynamodbDAO.java   
@Override
public boolean insert(LandUnit lu) {
    boolean retval = false;
    Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put(LandUnit.ID_ATTR_NAME, new AttributeValue(Long.toString(lu.getUnitId())));
    item.put(LandUnit.USER_ID_ATTR_NAME, new AttributeValue(Long.toString(lu.getUserId())));
    item.put(LandUnit.NAME_ATTR_NAME, new AttributeValue(lu.getName()));
    item.put(LandUnit.FARM_NAME_ATTR_NAME, new AttributeValue(lu.getFarmName()));
    item.put(LandUnit.CLIENT_NAME_ATTR_NAME, new AttributeValue(lu.getClientName()));
    item.put(LandUnit.ACRES_ATTR_NAME, new AttributeValue(Float.toString(lu.getAcres())));
    item.put(LandUnit.SOURCE_ATTR_NAME, new AttributeValue(lu.getSource()));
    item.put(LandUnit.OTHER_PROPS_ATTR_NAME, new AttributeValue(lu.getOtherProps()));
    item.put(LandUnit.GEOM_ATTR_NAME, new AttributeValue(lu.getWktBoundary()));
    PutItemRequest putItemRequest = new PutItemRequest(LANDUNIT_DYNAMO_DB_TABLE_NAME, item);
    try {
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        LOG.debug("DDB Insert Result: " + putItemResult);
        retval = true;
    } catch (Exception e) {
        LOG.error("DDB Insert failed " + e.getMessage());
    }
    return retval;
}
项目:tcc-oada    文件:DynamodbDAO.java   
@Override
public boolean insert(LandUnit lu) {
    boolean retval = false;
    Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put(LandUnit.ID_ATTR_NAME, new AttributeValue(Long.toString(lu.getUnitId())));
    item.put(LandUnit.USER_ID_ATTR_NAME, new AttributeValue(Long.toString(lu.getUserId())));
    item.put(LandUnit.NAME_ATTR_NAME, new AttributeValue(lu.getName()));
    item.put(LandUnit.FARM_NAME_ATTR_NAME, new AttributeValue(lu.getFarmName()));
    item.put(LandUnit.CLIENT_NAME_ATTR_NAME, new AttributeValue(lu.getClientName()));
    item.put(LandUnit.ACRES_ATTR_NAME, new AttributeValue(Float.toString(lu.getAcres())));
    item.put(LandUnit.SOURCE_ATTR_NAME, new AttributeValue(lu.getSource()));
    item.put(LandUnit.OTHER_PROPS_ATTR_NAME, new AttributeValue(lu.getOtherProps()));
    item.put(LandUnit.GEOM_ATTR_NAME, new AttributeValue(lu.getWktBoundary()));
    PutItemRequest putItemRequest = new PutItemRequest(LANDUNIT_DYNAMO_DB_TABLE_NAME, item);
    try {
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        LOG.debug("DDB Insert Result: " + putItemResult);
        retval = true;
    } catch (Exception e) {
        LOG.error("DDB Insert failed " + e.getMessage());
    }
    return retval;
}
项目:dynamodb-geo    文件:DynamoDBManager.java   
public PutPointResult putPoint(PutPointRequest putPointRequest) {
    long geohash = S2Manager.generateGeohash(putPointRequest.getGeoPoint());
    long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());
    String geoJson = GeoJsonMapper.stringFromGeoObject(putPointRequest.getGeoPoint());

    PutItemRequest putItemRequest = putPointRequest.getPutItemRequest();
    putItemRequest.setTableName(config.getTableName());

    AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
    putItemRequest.getItem().put(config.getHashKeyAttributeName(), hashKeyValue);
    putItemRequest.getItem().put(config.getRangeKeyAttributeName(), putPointRequest.getRangeKeyValue());
    AttributeValue geohashValue = new AttributeValue().withN(Long.toString(geohash));
    putItemRequest.getItem().put(config.getGeohashAttributeName(), geohashValue);
    AttributeValue geoJsonValue = new AttributeValue().withS(geoJson);
    putItemRequest.getItem().put(config.getGeoJsonAttributeName(), geoJsonValue);

    PutItemResult putItemResult = config.getDynamoDBClient().putItem(putItemRequest);
    PutPointResult putPointResult = new PutPointResult(putItemResult);

    return putPointResult;
}
项目:cas-5.1.0    文件:DynamoDbTicketRegistryFacilitator.java   
/**
 * Put ticket.
 *
 * @param ticket        the ticket
 * @param encodedTicket the encoded ticket
 */
public void put(final Ticket ticket, final Ticket encodedTicket) {
    final TicketDefinition metadata = this.ticketCatalog.find(ticket);
    final Map<String, AttributeValue> values = buildTableAttributeValuesMapFromTicket(ticket, encodedTicket);
    LOGGER.debug("Adding ticket id [{}] with attribute values [{}]", encodedTicket.getId(), values);
    final PutItemRequest putItemRequest = new PutItemRequest(metadata.getProperties().getStorageName(), values);
    LOGGER.debug("Submitting put request [{}] for ticket id [{}]", putItemRequest, encodedTicket.getId());
    final PutItemResult putItemResult = amazonDynamoDBClient.putItem(putItemRequest);
    LOGGER.debug("Ticket added with result [{}]", putItemResult);
    getAll();
}
项目:cas-5.1.0    文件:DynamoDbServiceRegistryFacilitator.java   
/**
 * Put.
 *
 * @param service the service
 */
public void put(final RegisteredService service) {
    final Map<String, AttributeValue> values = buildTableAttributeValuesMapFromService(service);
    final PutItemRequest putItemRequest = new PutItemRequest(TABLE_NAME, values);
    LOGGER.debug("Submitting put request [{}] for service id [{}]", putItemRequest, service.getServiceId());
    final PutItemResult putItemResult = amazonDynamoDBClient.putItem(putItemRequest);
    LOGGER.debug("Service added with result [{}]", putItemResult);
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public CompletableFuture<PutItemResult> putItem(final String tableName, final Map<String, AttributeValue> item) {
    return asyncExecutor.execute(new Callable<PutItemResult>() {
        @Override
        public PutItemResult call() throws Exception {
            return dbExecutor.putItem(tableName, item);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public CompletableFuture<PutItemResult> putItem(final String tableName, final Map<String, AttributeValue> item, final String returnValues) {
    return asyncExecutor.execute(new Callable<PutItemResult>() {
        @Override
        public PutItemResult call() throws Exception {
            return dbExecutor.putItem(tableName, item, returnValues);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
public CompletableFuture<PutItemResult> putItem(final PutItemRequest putItemRequest) {
    return asyncExecutor.execute(new Callable<PutItemResult>() {
        @Override
        public PutItemResult call() throws Exception {
            return dbExecutor.putItem(putItemRequest);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
CompletableFuture<PutItemResult> putItem(final String tableName, final Object entity) {
    return asyncExecutor.execute(new Callable<PutItemResult>() {
        @Override
        public PutItemResult call() throws Exception {
            return dbExecutor.putItem(tableName, entity);
        }
    });
}
项目:AbacusUtil    文件:AsyncDynamoDBExecutor.java   
CompletableFuture<PutItemResult> putItem(final String tableName, final Object entity, final String returnValues) {
    return asyncExecutor.execute(new Callable<PutItemResult>() {
        @Override
        public PutItemResult call() throws Exception {
            return dbExecutor.putItem(tableName, entity, returnValues);
        }
    });
}
项目:Camel    文件:PutItemCommand.java   
@Override
public void execute() {
    PutItemResult result = ddbClient.putItem(new PutItemRequest()
            .withTableName(determineTableName())
            .withItem(determineItem())
            .withExpected(determineUpdateCondition())
            .withReturnValues(determineReturnValues()));

    addAttributesToResult(result.getAttributes());
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
@Test
public void test_putItem_WithAllParameters() throws Exception {
  createTable();

  PutItemResult result = putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);
  Double units = result.getConsumedCapacity().getCapacityUnits();

  assertThat(units.doubleValue(), equalTo(1.0));
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
private PutItemResult putItem(String attributeName, String attributeValue) throws Exception {
  Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
  item.put(attributeName, new AttributeValue()
    .withS(attributeValue));
  String returnValues = "";

  PutItemResult result = dynamoDb.putItem(TEST_TABLE_NAME, item, returnValues);

  return result;
}
项目:milton-aws    文件:DynamoDBManagerImpl.java   
/**
 * The putEntity method stores an item in a table
 * 
 * @param entity
 * @return
 */
@Override
public boolean putEntity(String tableName, Entity entity) {
    Map<String, AttributeValue> newItem = dynamoDBService.newItem(entity);
    PutItemResult putItemResult = dynamoDBService.putItem(tableName, newItem);
    if (putItemResult != null) {
        return true;
    }

    return false;
}
项目:awsbigdata    文件:Loader.java   
public void put(String user, long timestamp, double x, double y) {
    if (tableName != null) {
        Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
        item.put("user", new AttributeValue().withS(user));
        item.put("timestamp", new AttributeValue().withS(Long.toString(timestamp)));
        item.put("latitude", new AttributeValue().withS(Double.toString(x)));
        item.put("longitude", new AttributeValue().withS(Double.toString(y)));

        PutItemRequest putItemRequest = new PutItemRequest()
        .withTableName(tableName)
        .withItem(item);
        PutItemResult result = client.putItem(putItemRequest);
    }
}
项目:logback-ext    文件:DynamoDbAppender.java   
@Override
protected void handle(final ILoggingEvent event, final String encoded) throws Exception {
    Item item = Item.fromJSON(encoded).withPrimaryKey(createEventId(event));
    Map<String, AttributeValue> attributes = InternalUtils.toAttributeValues(item);
    PutItemRequest request = new PutItemRequest(table, attributes);
    String errorMessage = format("Appender '%s' failed to send logging event '%s' to DynamoDB table '%s'", getName(), event, table);
    CountDownLatch latch = new CountDownLatch(isAsyncParent() ? 0 : 1);
    dynamoDb.putItemAsync(request, new LoggingEventHandler<PutItemRequest, PutItemResult>(this, latch, errorMessage));
    AppenderExecutors.awaitLatch(this, latch, getMaxFlushTime());
}
项目:aws-dynamodb-examples    文件:DynamoDBDynamicFaultInjection.java   
private static void putItem(Map<String, AttributeValue> item)
{

    try
    {

        PutItemRequest putItemRequest = new PutItemRequest(TABLENAME, item);
        PutItemResult putItemResult = dynamoDBClient.putItem(putItemRequest);
        logger.info("Result: " + putItemResult);
    }
    catch (Exception e)
    {
        // TODO: handle exception
    }
}
项目:jcabi-dynamo    文件:AwsTable.java   
@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();
    }
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
public PutItemResult putItem(final String tableName, final Map<String, AttributeValue> item) {
    return dynamoDB.putItem(tableName, item);
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
public PutItemResult putItem(final String tableName, final Map<String, AttributeValue> item, final String returnValues) {
    return dynamoDB.putItem(tableName, item, returnValues);
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
public PutItemResult putItem(final PutItemRequest putItemRequest) {
    return dynamoDB.putItem(putItemRequest);
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
PutItemResult putItem(final String tableName, final Object entity) {
    return putItem(tableName, toItem(entity));
}
项目:AbacusUtil    文件:DynamoDBExecutor.java   
PutItemResult putItem(final String tableName, final Object entity, final String returnValues) {
    return putItem(tableName, toItem(entity), returnValues);
}
项目:Camel    文件:AmazonDDBClientMock.java   
@Override
public PutItemResult putItem(PutItemRequest putItemRequest) {
    this.putItemRequest = putItemRequest;
    return new PutItemResult().withAttributes(getAttributes());
}
项目:widow    文件:IndexWorker.java   
private void writeToDynamo() throws RetryFailedException, InterruptedException {
    Map<String, AttributeValue> attributeValueMap = indexInput.getAttributes().entrySet()
            .stream()
            .filter((entry) -> entry.getValue() != null)
            .filter((entry) -> StringUtils.isNotBlank(entry.getValue().toString()))
            .collect(Collectors.toMap(
                    e -> e.getKey().toString(),
                    e -> {
                        try {
                            switch (e.getKey().getType()) {
                                case LONG:
                                case DOUBLE:
                                    return new AttributeValue().withN(e.getValue().toString());

                                default:
                                    String serializedData = null;

                                    // use objectMapper for everything but strings because it
                                    // adds quotes to raw strings
                                    if (e.getValue().getClass() != String.class) {
                                        serializedData = objectMapper.writeValueAsString(e.getValue());
                                    } else {
                                        serializedData = (String) e.getValue();
                                    }

                                    return new AttributeValue().withS(serializedData);
                            }
                        } catch (Exception ex) {
                            logger.error("Couldn't serialize data to index.", ex);
                            return null;
                        }
                    }
            ));

    String tableName = config.getString(TABLE_NAME_CONFIG_KEY);

    PutItemRequest putItemRequest = new PutItemRequest()
            .withTableName(tableName)
            .withItem(attributeValueMap)
            .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

    final PutItemResult putItemResult = retry(() -> dynamoDBClient.putItem(putItemRequest));

    logger.info("Consumed table capacity: " + putItemResult.getConsumedCapacity().getCapacityUnits());
}
项目:jcabi-dynamo    文件:AwsTableTest.java   
/**
 * AwsTable can save an item.
 * @throws Exception If some problem inside
 */
@Test
public void savesItemToDynamo() throws Exception {
    final Credentials credentials = Mockito.mock(Credentials.class);
    final AmazonDynamoDB aws = Mockito.mock(AmazonDynamoDB.class);
    Mockito.doReturn(aws).when(credentials).aws();
    Mockito.doReturn(
        new PutItemResult().withConsumedCapacity(
            new ConsumedCapacity().withCapacityUnits(1.0d)
        )
    ).when(aws).putItem(Mockito.any(PutItemRequest.class));
    Mockito.doReturn(
        new DescribeTableResult().withTable(
            new TableDescription().withKeySchema(
                new KeySchemaElement().withAttributeName(AwsTableTest.KEY)
            )
        )
    ).when(aws).describeTable(Mockito.any(DescribeTableRequest.class));
    final String attr = "attribute-1";
    final AttributeValue value = new AttributeValue("value-1");
    final String name = "table-name";
    final Table table = new AwsTable(
        credentials, Mockito.mock(Region.class), name
    );
    table.put(new Attributes().with(attr, value));
    Mockito.verify(aws).putItem(
        PutItemRequest.class.cast(
            MockitoHamcrest.argThat(
                Matchers.allOf(
                    Matchers.hasProperty(
                        AwsTableTest.TABLE_NAME,
                        Matchers.equalTo(name)
                    ),
                    Matchers.hasProperty(
                        "item",
                        Matchers.hasEntry(
                            Matchers.equalTo(attr),
                            Matchers.equalTo(value)
                        )
                    )
                )
            )
        )
    );
}
项目:dynamodb-geo    文件:PutPointResult.java   
public PutPointResult(PutItemResult putItemResult) {
    this.putItemResult = putItemResult;
}
项目:dynamodb-geo    文件:PutPointResult.java   
public PutItemResult getPutItemResult() {
    return putItemResult;
}
项目:milton-aws    文件:DynamoDBService.java   
PutItemResult putItem(String tableName, Map<String, AttributeValue> item);