本文整理汇总了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);
}
}
示例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;
}
示例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";
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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.");
}
}
示例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());
}
}
示例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);
}
示例11: saveDenunciaHistory
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private void saveDenunciaHistory(DynamoDBMapper mapper, DenunciaHistory d)
{
mapper.save(d);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}