本文整理汇总了Java中com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper类的典型用法代码示例。如果您正苦于以下问题:Java DynamoDBMapper类的具体用法?Java DynamoDBMapper怎么用?Java DynamoDBMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DynamoDBMapper类属于com.amazonaws.services.dynamodbv2.datamodeling包,在下文中一共展示了DynamoDBMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDevicePlatform
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
private Platform getDevicePlatform(DynamoDBMapper mapper,String token)
{
Dispositivo d = mapper.load(Dispositivo.class, token);
if(null==d)
return null;
if(d.getOs()==1)
return Platform.APNS_SANDBOX;
if(d.getOs()==2)
return Platform.GCM;
//Just for testing
return Platform.APNS_SANDBOX;
//return null;
}
示例2: init
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
@PostConstruct
protected void init() {
configureAWSLogAgent();
credentialsProvider = new InstanceProfileCredentialsProvider();
region = Regions.getCurrentRegion();
amazonDynamoDB.setRegion(region);
dbPrefix = AmazonConfigProvider.getDynamoDbPrefix();
DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder().withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.
withTableNamePrefix(dbPrefix)).build();
mapper = new DynamoDBMapper(amazonDynamoDB, config);
tablesWithPrefix = Arrays.stream(tables).map(s -> dbPrefix.concat(s)).collect(Collectors.toList());
if (customBucketName != null) {
customBucketName = customBucketName.toLowerCase();
}
if ((customBucketName.isEmpty() || CUSTOM_BUCKET_NAME_DEFAULT_VALUE.equals(customBucketName)) && !validateBucketName(customBucketName).isValid()) {
customBucketName = null;
}
}
示例3: 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);
}
}
示例4: FindBooksPricedLessThanSpecifiedValue
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
private static void FindBooksPricedLessThanSpecifiedValue(
DynamoDBMapper mapper,
String value) throws Exception {
System.out.println("FindBooksPricedLessThanSpecifiedValue: Scan ProductCatalog.");
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
scanExpression.addFilterCondition("Price",
new Condition()
.withComparisonOperator(ComparisonOperator.LT)
.withAttributeValueList(new AttributeValue().withN(value)));
scanExpression.addFilterCondition("ProductCategory",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS("Book")));
List<Book> scanResult = mapper.scan(Book.class, scanExpression);
for (Book book : scanResult) {
System.out.println(book);
}
}
示例5: FindBicyclesOfSpecificTypeWithMultipleThreads
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
private static void FindBicyclesOfSpecificTypeWithMultipleThreads(
DynamoDBMapper mapper,
int numberOfThreads,
String bicycleType) throws Exception {
System.out.println("FindBicyclesOfSpecificTypeWithMultipleThreads: Scan ProductCatalog With Multiple Threads.");
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
scanExpression.addFilterCondition("ProductCategory",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS("Bicycle")));
scanExpression.addFilterCondition("BicycleType",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS(bicycleType)));
List<Bicycle> scanResult = mapper.parallelScan(Bicycle.class, scanExpression, numberOfThreads);
for (Bicycle bicycle : scanResult) {
System.out.println(bicycle);
}
}
示例6: main
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
try {
DynamoDBMapper mapper = new DynamoDBMapper(client);
testBatchSave(mapper);
testBatchDelete(mapper);
testBatchWrite(mapper);
System.out.println("Example complete!");
} catch (Throwable t) {
System.err.println("Error running the ObjectPersistenceBatchWriteExample: " + t);
t.printStackTrace();
}
}
示例7: setup
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
@Before
public void setup() throws NoSuchFieldException, IllegalAccessException {
underTest = spy(new DynamoDbConfig(environment, awsKms));
when(underTest.encryptionTransformer(any(String.class))).thenReturn(transformer);
when(underTest.tableNameOverrideConfig(any(String.class))).thenReturn(mapConfigNamed);
when(underTest.getDynamoDbMapperConfig()).thenReturn(mapConfig);
mockStatic(DynamoDBMapper.class);
mockStatic(DynamoDbConfigFactory.class);
MockitoAnnotations.initMocks(DynamoDbConfigTest.class);
}
示例8: dbMapperNoAudit
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
@Test
public void dbMapperNoAudit() {
when(environment.getProperty(eq(Constants.NO_AUDIT_ENV_VARIABLE))).thenReturn("true");
when(environment.getProperty(eq(Constants.DYNAMO_TABLE_NAME_ENV_VARIABLE))).thenReturn(null);
when(environment.getProperty(eq(Constants.KMS_KEY_ENV_VARIABLE))).thenReturn(null);
DynamoDBMapper dynamoDBMapper = underTest.dynamoDbMapper(amazonDynamoDB);
assertThat(dynamoDBMapper).isNull();
}
示例9: setup
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
@Before
@Override
public void setup() {
super.setup();
final DynamoDBMapper mapper = new DynamoDBMapper(dynamodbClient);
resourceTripleDao = new DynamoDBResourceTripleDao(mapper);
addResourceData();
}
示例10: 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;
}
示例11: DBConnector
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
/**
* generate dynamo db mapper etc. to connect to database
*/
private DBConnector() {
AWSPropertiesProvider awsPropertiesProvider = new AWSPropertiesProvider("dynamoDb.properties");
AmazonDynamoDBClient dbClient = new AmazonDynamoDBClient(awsPropertiesProvider.getCredentials());
dbClient.setRegion(awsPropertiesProvider.getRegion());
dynamoDB = new DynamoDB(dbClient);
dynamoDBMapper = new DynamoDBMapper(dbClient);
}
示例12: GenericDynamoDbDao
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
public GenericDynamoDbDao(DynamoDbClientFactory clientFactory, Class<T> clazz) {
DynamoDBTableMapper<T, K, ?> tableMapper = new DynamoDBMapper(clientFactory.client()).newTableMapper(clazz);
log.info("Building table for " + clazz.getName());
boolean tableIfNotExists = tableMapper.createTableIfNotExists(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
log.info("table created?: "+tableIfNotExists);
this.tableMapper = tableMapper;
}
示例13: GenericDynamoDbRangeDao
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
public GenericDynamoDbRangeDao(DynamoDbClientFactory clientFactory, Class<T> clazz) {
DynamoDBTableMapper<T, K, R> tableMapper = new DynamoDBMapper(clientFactory.client()).newTableMapper(clazz);
log.info("Building table for " + clazz.getName());
tableMapper.deleteTableIfExists();
tableMapper.createTableIfNotExists(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
this.tableMapper = tableMapper;
}
示例14: beforeClass
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
sDynamoDB = DynamoDBEmbedded.create().amazonDynamoDB();
sDynamoDBMapper = new DynamoDBMapper(sDynamoDB);
sDynamoDBRepository = new DynamoDBRepository();
sDynamoDBRepository.setDynamoDBMapper(sDynamoDBMapper);
sDynamoDBRepository.setLockDurationMs(LOCK_DURATION_MS);
}
示例15: 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";
}