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


Java PutItemRequest类代码示例

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


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

示例1: putItemResultMono

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
private Mono<Map<String, AttributeValue>> putItemResultMono(
        String seedUrl,
        EStatus status,
        String title,
        WebsiteModel websiteModel
) {

    PutItemRequest putItemRequest = new PutItemRequest();
    putItemRequest.setTableName(Utils.table.websites);

    Map<String, AttributeValue> newWebsite = new HashMap<>();

    if (Objects.nonNull(websiteModel)) newWebsite = crawlerBatchService.getNodes(websiteModel);
    newWebsite.put(Utils.params.url, new AttributeValue(seedUrl));
    newWebsite.put(Utils.params.status, new AttributeValue(status.name()));
    if (StringUtils.isNotEmpty(title)) newWebsite.put(Utils.params.title, new AttributeValue(title));

    putItemRequest.setItem(newWebsite);

    return Mono.fromFuture(
            Utils.makeCompletableFuture(
                    dynamoDBAsync.putItemAsync(putItemRequest)))
            .doOnError((throwable -> LOG.error(Utils.error.failed_dynamo_put, seedUrl)))
            .doOnSuccess((a) -> LOG.info(Utils.success.saved_dynamo, String.format("%s [%s]", seedUrl, status)))
            .map(((result) -> putItemRequest.getItem()));
}
 
开发者ID:hafidsousa,项目名称:webcrawler,代码行数:27,代码来源:CrawlerBatchTask.java

示例2: createItemIfNotExists

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
boolean createItemIfNotExists(String key, long currentTimeMillis, Context context) {

		LambdaLogger logger = context.getLogger();
		AmazonDynamoDB client = createDynamoDBClient(cc);
		String functionName = context.getFunctionName();

		try {
			// Create a record if it does not exist
			PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
					.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
					.addItemEntry(COL_KEY, new AttributeValue(key))
					.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
					.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
					.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
			client.putItem(req);
			return true;
		} catch (ConditionalCheckFailedException e) {
			logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
			return false;
		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:24,代码来源:LambdaLock.java

示例3: putItem

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
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;
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:21,代码来源:DynamoDbDelegate.java

示例4: storeUser

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
/**
 * Store the username, password combination in the Identity table. The
 * username will represent the item name and the item will contain a
 * attributes password and userid.
 * 
 * @param username
 *            Unique user identifier
 * @param password
 *            user password
 * @param uri
 *            endpoint URI
 */
protected void storeUser(String username, String password, String uri) throws DataAccessException {
    if (null == username || null == password) {
        return;
    }

    String hashedSaltedPassword = Utilities.getSaltedPassword(username, uri, password);

    Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put(ATTRIBUTE_USERNAME, new AttributeValue().withS(username));
    item.put(ATTRIBUTE_HASH_SALTED_PASSWORD, new AttributeValue().withS(hashedSaltedPassword));
    item.put(ATTRIBUTE_ENABLED, new AttributeValue().withS("true"));

    PutItemRequest putItemRequest = new PutItemRequest()
            .withTableName(USER_TABLE)
            .withItem(item);
    try {
        ddb.putItem(putItemRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to store user: " + username, e);
    }
}
 
开发者ID:awslabs,项目名称:amazon-cognito-developer-authentication-sample,代码行数:34,代码来源:UserAuthentication.java

示例5: storeDevice

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
/**
 * Store the UID, Key, username combination in the Identity table. The UID
 * will represent the item name and the item will contain attributes key and
 * username.
 * 
 * @param uid
 *            Unique device identifier
 * @param key
 *            encryption key associated with UID
 * @param username
 *            Unique user identifier
 */
protected void storeDevice(String uid, String key, String username) throws DataAccessException {
    Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put(ATTRIBUTE_UID, new AttributeValue().withS(uid));
    item.put(ATTRIBUTE_KEY, new AttributeValue().withS(key));
    item.put(ATTRIBUTE_USERNAME, new AttributeValue().withS(username));

    PutItemRequest putItemRequest = new PutItemRequest()
            .withTableName(DEVICE_TABLE)
            .withItem(item);
    try {
        ddb.putItem(putItemRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException(String.format("Failed to store device uid: %s; key: %s; username: %s", uid,
                key, username), e);
    }
}
 
开发者ID:awslabs,项目名称:amazon-cognito-developer-authentication-sample,代码行数:29,代码来源:DeviceAuthentication.java

示例6: loadRandomData

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
/**
     * 
     * Load the specific kind of data into table.
     * 
     */
    public List<Map<String, AttributeValue>> loadRandomData(String tableName, String hashKeyName, String hashKeyType, String rangeKeyName, String rangeKeyType, 
        Map<String, String> attributePairs, int randomStringLength, int loadItemCount) {
        List<Map<String, AttributeValue>> list = new ArrayList<Map<String, AttributeValue>>();
        for (int i = 0; i < loadItemCount; i++) {
            Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
            // hash-key
            item.put(hashKeyName, generateItem(hashKeyName, hashKeyType, 5));
            // range-key
            item.put(rangeKeyName, generateItem(rangeKeyName, rangeKeyType, 5));
            /** Adding random values for specific attribute type */
            for (Entry<String, String> attribute : attributePairs.entrySet()) {
                item.put(attribute.getKey(), generateItem(attribute.getKey(), attribute.getValue(), randomStringLength));
            }
            /** Put data into table */
            PutItemRequest putItemRequest = new PutItemRequest().withTableName(tableName).withItem(item);
//          printHelper.printItem(1, i + 1, item);
            client.putItem(putItemRequest);
            list.add(item);
        }
        return list;
    }
 
开发者ID:awslabs,项目名称:dynamodb-online-index-violation-detector,代码行数:27,代码来源:TableManager.java

示例7: putItem

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
/**
   * 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;
  }
 
开发者ID:dgks0n,项目名称:milton-aws,代码行数:29,代码来源:DynamoDBServiceImpl.java

示例8: insert

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
@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;
}
 
开发者ID:OADA,项目名称:oada-ref-impl-java,代码行数:24,代码来源:DynamodbDAO.java

示例9: addTask

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
public static void addTask(String taskID, String task){

		HashMap<String, AttributeValue> item = new HashMap<String, AttributeValue>();
        item.put("taskID", new AttributeValue().withS(taskID));
        item.put("Task", new AttributeValue(task));
        
        ExpectedAttributeValue notExpected = new ExpectedAttributeValue(false);
        Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>();
        expected.put("taskID", notExpected);
        
        PutItemRequest putItemRequest = new PutItemRequest()
        	.withTableName(TABLE_NAME)
        	.withItem(item)
        	.withExpected(expected);  //put item only if no taskID exists!
        
        dynamoDB.putItem(putItemRequest);
		
	}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:19,代码来源:DynamoDBService.java

示例10: putItem

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
public static void putItem(
    String issueId, String title,
    String description, 
    String createDate, String lastUpdateDate,String dueDate, 
    Integer priority, String status) {

    HashMap<String, AttributeValue> item = new HashMap<String, AttributeValue>();

    item.put("IssueId", new AttributeValue().withS(issueId));
    item.put("Title", new AttributeValue().withS(title));
    item.put("Description", new AttributeValue().withS(description));
    item.put("CreateDate", new AttributeValue().withS(createDate));
    item.put("LastUpdateDate", new AttributeValue().withS(lastUpdateDate));
    item.put("DueDate", new AttributeValue().withS(dueDate));
    item.put("Priority", new AttributeValue().withN(priority.toString()));
    item.put("Status", new AttributeValue().withS(status));

    try {
        client.putItem(new PutItemRequest()
            .withTableName(tableName)
            .withItem(item));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:26,代码来源:LowLevelGlobalSecondaryIndexExample.java

示例11: createItem

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
public static void createItem(String threadId, String replyDateTime) throws IOException {
    // 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());
    
    // Add a the reply
    Map<String, AttributeValue> replyInput = new HashMap<String, AttributeValue>();
    replyInput.put("Id", new AttributeValue().withS(threadId));
    replyInput.put("ReplyDateTime", new AttributeValue().withS(replyDateTime));
    replyInput.put("Message", new AttributeValue().withS("Long message follows"));
    replyInput.put("ExtendedMessage", new AttributeValue().withB(compressedMessage));
    replyInput.put("PostedBy", new AttributeValue().withS("User A"));
    
    PutItemRequest putReplyRequest = new PutItemRequest().withTableName(tableName).withItem(replyInput);
    
    client.putItem(putReplyRequest);
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:20,代码来源:LowLevelItemBinaryExample.java

示例12: uploadProduct

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
private static void uploadProduct(String tableName, String productIndex) {
    try {
        // Add a book.
        Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
        item.put("Id", new AttributeValue().withN(productIndex));
        item.put("Title", new AttributeValue().withS("Book " + productIndex + " Title"));
        item.put("ISBN", new AttributeValue().withS("111-1111111111"));
        item.put("Authors", new AttributeValue().withSS(Arrays.asList("Author1")));
        item.put("Price", new AttributeValue().withN("2"));
        item.put("Dimensions", new AttributeValue().withS("8.5 x 11.0 x 0.5"));
        item.put("PageCount", new AttributeValue().withN("500"));
        item.put("InPublication", new AttributeValue().withBOOL(true));
        item.put("ProductCategory", new AttributeValue().withS("Book"));
        
        PutItemRequest itemRequest = new PutItemRequest().withTableName(tableName).withItem(item);
        client.putItem(itemRequest);
        item.clear();
        
    }   catch (AmazonServiceException ase) {
        System.err.println("Failed to create item " + productIndex + " in " + tableName);
    }
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:23,代码来源:LowLevelParallelScan.java

示例13: putPoint

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
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;
}
 
开发者ID:awslabs,项目名称:dynamodb-geo,代码行数:22,代码来源:DynamoDBManager.java

示例14: put

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:DynamoDbTicketRegistryFacilitator.java

示例15: put

import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:13,代码来源:DynamoDbServiceRegistryFacilitator.java


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