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


Java DynamoDBMapper.save方法代码示例

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


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

示例1: put

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
/**
 * Puts an object identified by a key
 *
 * @param key
 * @param obj
 */
@Override
public void put(K key, T obj) {
  try {
    Object hashKey = getHashKey(key, obj);
    Object rangeKey = getRangeKey(key, obj);
    if (hashKey != null) {
      DynamoDBMapper mapper = new DynamoDBMapper(
          dynamoDBStoreHandler.getDynamoDbClient());
      if (rangeKey != null) {
        mapper.load(persistentClass, hashKey, rangeKey);
      } else {
        mapper.load(persistentClass, hashKey);
      }
      mapper.save(obj);
    } else
      throw new GoraException("No HashKey found in Key nor in Object.");
  } catch (NullPointerException npe) {
    LOG.error("Error while putting an item. " + npe.toString());
    throw new NullArgumentException(npe.getMessage());
  } catch (Exception e) {
    LOG.error("Error while putting an item. " + obj.toString());
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:31,代码来源:DynamoDBNativeStore.java

示例2: addUser

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
public static User addUser(DynamoDBMapper dbMapper, String firstName, String lastName, String address, String facebookId) {
    User user = new User();
    user.setUserId(UUID.randomUUID().toString());
    user.setFirstName(firstName);
    user.setLastName(lastName);
    if(address != null)
        user.setAddress(address);
    if(facebookId != null)
        user.setFacebookId(facebookId);
    dbMapper.save(user);
    return user;
}
 
开发者ID:satr,项目名称:aws-amazon-shopping-bot-lambda-func,代码行数:13,代码来源:TestRepositoryHelper.java

示例3: handleRequest

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
@Override
public String handleRequest(Book request, Context context) {
	DynamoDBMapper mapper = new DynamoDBMapper(DynamoDBUtil.getClient());
	mapper.save(request);

	return "success";
}
 
开发者ID:arun-gupta,项目名称:serverless,代码行数:8,代码来源:BookPost.java

示例4: handleRequest

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
@Override
public GatewayResponse handleRequest(GatewayRequest request, Context context) {
	DynamoDBMapper mapper = new DynamoDBMapper(DynamoDBUtil.getClient());
	mapper.save(request.getBody());

    return new GatewayResponse(200, request.getBody(), GatewayResponse.HEADERS_JSON);
}
 
开发者ID:arun-gupta,项目名称:serverless,代码行数:8,代码来源:BucketPost.java

示例5: init

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
@PostConstruct
private void init() {
    DynamoDBMapper mapper = new DynamoDBMapper(amazonDynamoDB, dynamoDBMapperConfig);
    Configuration configuration = getDevConf();
    mapper.save(configuration);

    User user = new User("[email protected]", DigestUtils.sha512Hex("admin"), "admin", "dev", "dev");
    user.setId("DEV");
    mapper.save(user);
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:11,代码来源:CreateAppConfigurationDev.java

示例6: FandomDAO

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
public FandomDAO() {
	client = new AmazonDynamoDBClient(
			new ClasspathPropertiesFileCredentialsProvider());
	mapper = new DynamoDBMapper(client);

	Fandom test = mapper.load(Fandom.class, "fandoms");
	if (test == null) {
		test = new Fandom();
		test.setId("fandoms");
		mapper.save(test);
	}
}
 
开发者ID:Moliholy,项目名称:Fancraft,代码行数:13,代码来源:FandomDAO.java

示例7: CraftDAO

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
public CraftDAO(){
	client = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
	mapper = new DynamoDBMapper(client);
	
	Craft test = mapper.load(Craft.class, "crafts");
	if(test == null){
		test = new Craft();
		test.setId("crafts");
		mapper.save(test);
	}
}
 
开发者ID:Moliholy,项目名称:Fancraft,代码行数:12,代码来源:CraftDAO.java

示例8: testCRUDOperations

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private static void testCRUDOperations() {

        CatalogItem item = new CatalogItem();
        item.setId(601);
        item.setTitle("Book 601");
        item.setISBN("611-1111111111");
        item.setBookAuthors(new HashSet<String>(Arrays.asList("Author1", "Author2")));
        
        // Save the item (book).
        DynamoDBMapper mapper = new DynamoDBMapper(client);
        mapper.save(item);
        
        // Retrieve the item.
        CatalogItem itemRetrieved = mapper.load(CatalogItem.class, 601);
        System.out.println("Item retrieved:");
        System.out.println(itemRetrieved);

        // Update the item.
        itemRetrieved.setISBN("622-2222222222");
        itemRetrieved.setBookAuthors(new HashSet<String>(Arrays.asList("Author1", "Author3")));
        mapper.save(itemRetrieved);
        System.out.println("Item updated:");
        System.out.println(itemRetrieved);
        
        // Retrieve the updated item.
        DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.ConsistentReads.CONSISTENT);
        CatalogItem updatedItem = mapper.load(CatalogItem.class, 601, config);
        System.out.println("Retrieved the previously updated item:");
        System.out.println(updatedItem);
        
        // Delete the item.
        mapper.delete(updatedItem);
        
        // Try to retrieve deleted item.
        CatalogItem deletedItem = mapper.load(CatalogItem.class, updatedItem.getId(), config);
        if (deletedItem == null) {
            System.out.println("Done - Sample item is deleted.");
        }
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:40,代码来源:ObjectPersistenceCRUDExample.java

示例9: store

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void store(Item item, String alias) {
    if (item.getState() instanceof UnDefType) {
        logger.debug("Undefined item state received. Not storing item.");
        return;
    }
    if (!isProperlyConfigured) {
        logger.warn("Configuration for dynamodb not yet loaded or broken. Not storing item.");
        return;
    }
    if (!maybeConnectAndCheckConnection()) {
        logger.warn("DynamoDB not connected. Not storing item.");
        return;
    }
    String realName = item.getName();
    String name = (alias != null) ? alias : realName;
    Date time = new Date(System.currentTimeMillis());

    State state = item.getState();
    logger.trace("Tried to get item from item class {}, state is {}", item.getClass(), state.toString());
    DynamoDBItem<?> dynamoItem = AbstractDynamoDBItem.fromState(name, state, time);
    DynamoDBMapper mapper = getDBMapper(tableNameResolver.fromItem(dynamoItem));

    if (!createTable(mapper, dynamoItem.getClass())) {
        logger.warn("Table creation failed. Not storing item");
        return;
    }

    try {
        logger.debug("storing {} in dynamo. Serialized value {}. Original Item: {}", name, state, item);
        mapper.save(dynamoItem);
        logger.debug("Sucessfully stored item {}", item);
    } catch (AmazonClientException e) {
        logger.error("Error storing object to dynamo: {}", e.getMessage());
    }

}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:41,代码来源:DynamoDBPersistenceService.java

示例10: createBook

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private void createBook() {
	DynamoDBMapper mapper = new DynamoDBMapper(getClient());
	Book book = new Book("1", "Minecraft Modding with Forge", "1234", "29.99");
	mapper.save(book);
}
 
开发者ID:arun-gupta,项目名称:dynamodb-java-helloworld,代码行数:6,代码来源:App.java

示例11: saveDenunciaHistory

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private void saveDenunciaHistory(DynamoDBMapper mapper, DenunciaHistory d)
{
	mapper.save(d);
}
 
开发者ID:krito19,项目名称:DenunciaMXBackEnd,代码行数:5,代码来源:SecretariaService.java

示例12: updateDenuncia

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private Denuncia updateDenuncia(DynamoDBMapper mapper,String idDenuncia, String folio,int estatusDenuncia)
{
	Denuncia d = mapper.load(Denuncia.class, idDenuncia);
	
	
	if(DENUNCIA_RECIBIDA_SPF==estatusDenuncia)
		d.setIdDenunciaSPF(folio);
	
	d.setIdEstadoDenuncia(estatusDenuncia);
	
	mapper.save(d);
	
	return d;
	
		
}
 
开发者ID:krito19,项目名称:DenunciaMXBackEnd,代码行数:17,代码来源:SecretariaService.java

示例13: main

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
    
    DimensionType dimType = new DimensionType();
    dimType.setHeight("8.00");
    dimType.setLength("11.0");
    dimType.setThickness("1.0");
    
    Book book = new Book();
    book.setId(502);
    book.setTitle("Book 502");
    book.setISBN("555-5555555555");
    book.setBookAuthors(new HashSet<String>(Arrays.asList("Author1", "Author2")));
    book.setDimensions(dimType);
    
    System.out.println(book);
    
    DynamoDBMapper mapper = new DynamoDBMapper(client);
    mapper.save(book);
    
    Book bookRetrieved = mapper.load(Book.class, 502);
    
    System.out.println(bookRetrieved);
    
    bookRetrieved.getDimensions().setHeight("9.0");
    bookRetrieved.getDimensions().setLength("12.0");
    bookRetrieved.getDimensions().setThickness("2.0");
    
    mapper.save(bookRetrieved);

    bookRetrieved = mapper.load(Book.class, 502);        
    System.out.println(bookRetrieved);

}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:37,代码来源:ObjectPersistenceMappingExample.java

示例14: saveDocument

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
/**
 * Save a document to a DynamoDB table
 * <p/>
 * {@sample.xml ../../../doc/DynamoDB-connector.xml.sample dynamodb:save-document}
 *
 * @param tableName
 *         the table to update
 * @param document
 *         the object to save to the table as a document.  If not explicitly provided, it defaults to PAYLOAD.
 *
 * @return Object the place that was stored
 */
@Processor
public Object saveDocument(final String tableName, @Optional @Default(PAYLOAD) final Object document) {
    DynamoDBMapper mapper = getDbObjectMapper(tableName);
    mapper.save(document);
    // the document is automatically updated with the data that was stored in DynamoDB
    return document;
}
 
开发者ID:sporcina,项目名称:dynamodb-connector,代码行数:20,代码来源:DynamoDBConnector.java

示例15: updateDocument

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
/**
 * Update document processor
 * <p/>
 * {@sample.xml ../../../doc/DynamoDB-connector.xml.sample dynamodb:update-document}
 *
 * @param tableName
 *         the table to update
 * @param document
 *         the object to save to the table as a document.  If not explicitly provided, it defaults to PAYLOAD.
 *
 * @return Object the place that was stored
 */
@Processor
public Object updateDocument(final String tableName, @Optional @Default(PAYLOAD) final Object document) {
    DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.SaveBehavior.UPDATE);
    DynamoDBMapper mapper = getDbObjectMapper(tableName);
    mapper.save(document, config);

    // save does not return the modified document.  Just return the original.
    return document;
}
 
开发者ID:sporcina,项目名称:dynamodb-connector,代码行数:22,代码来源:DynamoDBConnector.java


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