本文整理汇总了Java中com.amazonaws.services.dynamodbv2.document.DynamoDB类的典型用法代码示例。如果您正苦于以下问题:Java DynamoDB类的具体用法?Java DynamoDB怎么用?Java DynamoDB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DynamoDB类属于com.amazonaws.services.dynamodbv2.document包,在下文中一共展示了DynamoDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClient
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
/**
* Returns a client instance for AWS DynamoDB.
* @return a client that talks to DynamoDB
*/
public static AmazonDynamoDB getClient() {
if (ddbClient != null) {
return ddbClient;
}
if (Config.IN_PRODUCTION) {
ddbClient = AmazonDynamoDBClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY))).
withRegion(Config.AWS_REGION).build();
} else {
ddbClient = AmazonDynamoDBClientBuilder.standard().
withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("local", "null"))).
withEndpointConfiguration(new EndpointConfiguration(LOCAL_ENDPOINT, "")).build();
}
if (!existsTable(Config.getRootAppIdentifier())) {
createTable(Config.getRootAppIdentifier());
}
ddb = new DynamoDB(ddbClient);
Para.addDestroyListener(new DestroyListener() {
public void onDestroy() {
shutdownClient();
}
});
return ddbClient;
}
示例2: transform
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@Override
public void transform(Item scoreItem, DynamoDB dynamodb) {
String playerName = scoreItem.getString(PLAYER_NAME);
int score = scoreItem.getInt(SCORE);
int gameLength = scoreItem.getInt(GAME_LENGTH);
/*
* The XSpec API allows you to use DynamoDB's expression language
* to execute expressions on the service-side.
*
* https://java.awsblog.com/post/TxBG87QOQZRZJF/-DynamoDB-XSpec-API
*/
Table viewTable = dynamodb.getTable(PLAYER_STATS_TABLE_NAME);
UpdateItemExpressionSpec incrementTotalOrder = new ExpressionSpecBuilder()
.addUpdate(N(TOTAL_SCORE).add(score))
.addUpdate(N(TOTAL_GAMEPLAY).add(gameLength))
.addUpdate(N(TOTAL_GAMES).add(1))
.buildForUpdate();
viewTable.updateItem(PLAYER_NAME, playerName, incrementTotalOrder);
}
示例3: DefaultGroupStorage
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@Inject
public DefaultGroupStorage(
AmazonDynamoDB amazonDynamoDB,
TableConfiguration tableConfiguration,
@Named("dynamodbGroupWriteHystrix") HystrixConfiguration dynamodbGroupWriteHystrix,
@Named("dynamodbGraphWriteHystrix") HystrixConfiguration dynamodbGraphWriteHystrix,
@Named("dynamodbNamespaceGraphQueryHystrix")
HystrixConfiguration dynamodbNamespaceGraphQueryHystrix,
MetricRegistry metrics
) {
this.amazonDynamoDB = amazonDynamoDB;
this.dynamoDB = new DynamoDB(this.amazonDynamoDB);
this.groupTableName = tableConfiguration.outlandGroupsTable;
this.groupGraphTableName = tableConfiguration.outlandAppGraphTable;
this.dynamodbGroupWriteHystrix = dynamodbGroupWriteHystrix;
this.dynamodbGraphWriteHystrix = dynamodbGraphWriteHystrix;
this.dynamodbNamespaceGraphQueryHystrix = dynamodbNamespaceGraphQueryHystrix;
this.metrics = metrics;
}
示例4: handleRequest
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context){
Collection<Partition>requiredPartitions = new HashSet<>();
TableService tableService = new TableService();
DynamoDB dynamoDBClient=new DynamoDB(new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider()));
for(S3EventNotification.S3EventNotificationRecord record:s3Event.getRecords()){
String bucket=record.getS3().getBucket().getName();
String key=record.getS3().getObject().getKey();
System.out.printf("S3event[Event:%s,Bucket:%s,Key:%s]%n",record.getEventName(),bucket,key);
S3Object s3Object=new S3Object(bucket,key);
if(s3Object.hasDateTimeKey()){
Partition partition = partitionConfig.createPartitionFor(s3Object);
//Check if the partition exists in DynamoDBtable, if not add the partition details to the table, skip otherwise
if (tryAddMissingPartition(partitionConfig.dynamoDBTableName(), dynamoDBClient, partition)) {
requiredPartitions.add(partition);
}
}
}
if(!requiredPartitions.isEmpty()){
tableService.addPartitions(partitionConfig.tableName(),requiredPartitions, true);
}
return null;
}
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:33,代码来源:CreateAthenaPartitionsBasedOnS3EventWithDDB.java
示例5: tryAddMissingPartition
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
private boolean tryAddMissingPartition(String dyanmoDBTaableName,DynamoDB dynamoDBClient, Partition partition){
Table ddbTable= dynamoDBClient.getTable(dyanmoDBTaableName);
Item item=new Item()
.withPrimaryKey("PartitionSpec",partition.spec())
.withString("PartitionPath",partition.path())
.withString("PartitionName", partition.name());
PutItemSpec itemSpec=new PutItemSpec()
.withItem(item)
.withConditionExpression("attribute_not_exists(#ps)")
.withNameMap(new NameMap()
.with("#ps","PartitionSpec"));
try{
ddbTable.putItem(itemSpec);
System.out.println("Item was added to the table.PartitionSpec="+partition.spec()+"; Path="+partition.path());
return true;
}
catch(ConditionalCheckFailedException e){
System.out.println(e.toString());
System.out.println("Item already exists. PartitionSpec="+partition.spec()+"; Path="+partition.path());
return false;
}
}
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:27,代码来源:CreateAthenaPartitionsBasedOnS3EventWithDDB.java
示例6: createTable
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
protected Table createTable(CreateTableRequest request) throws InterruptedException {
DynamoDB dynamoDB = new DynamoDB(tables.getAsyncClient());
request.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(5L)
.withWriteCapacityUnits(6L));
if (request.getTableName() == null) {
String tableName = tables.getTestTableName();
tableName = tableName.replace('-', '_');
request.setTableName(tableName);
}
Table table = dynamoDB.createTable(request);
table.waitForActive();
return table;
}
示例7: DdbSchema
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@Inject
protected DdbSchema(@Assisted SchemaBuilder builder,
AmazonWebServiceClients amazonWebServiceClients,
ClientConfigurations clientConfigurations,
AWSCredentialsProviderFactory awsCredentialsProviderFactory)
{
_tableNameFormat = builder.getTableNameFormat();
AmazonDynamoDBClient client = amazonWebServiceClients.withEndpoint(
new AmazonDynamoDBClient(
awsCredentialsProviderFactory.create(builder.getCredProvider()),
clientConfigurations.withProxy(
new ClientConfiguration(),
builder.getProxyEndpoint())),
builder.getEndpoint());
_dynamodb = new DynamoDB(client);
}
示例8: setUp
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@Before
public void setUp() {
// Unique table for each run
tableName = "table" + String.valueOf(tableCount++);
dynamoDB.getDynamoDbClient().createTable(
new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(new KeySchemaElement("id", "HASH"))
.withAttributeDefinitions(
new AttributeDefinition("id", "S")
)
.withProvisionedThroughput(
new ProvisionedThroughput(1L, 1L)
)
);
locker = new DynamoDbLocker(
new DynamoDB(dynamoDB.getDynamoDbClient()),
tableName,
Clock.systemUTC()
);
}
示例9: createTable
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
private void createTable(Class tableClass) {
CreateTableRequest createTableRequest = mapper.generateCreateTableRequest(tableClass);
createTableRequest.setProvisionedThroughput(new ProvisionedThroughput(dbReadCapacity, dbWriteCapacity));
if (tableExists(createTableRequest.getTableName())) {
LOG.info("Table {} already exists", createTableRequest.getTableName());
return;
}
try {
DynamoDB dynamoDB = new DynamoDB(amazonDynamoDB);
Table table = dynamoDB.createTable(createTableRequest);
LOG.info("Creating table {} ... ", createTableRequest.getTableName());
table.waitForActive();
LOG.info("Table {} was created successfully.", createTableRequest.getTableName());
} catch (Exception e) {
LOG.error("Failed to create table {}. ", createTableRequest.getTableName());
LOG.error(e);
throw new ConfigurationException("Failed to create table" + createTableRequest.getTableName(), e);
}
}
示例10: init
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@PostConstruct
private void init() {
configurationId = SystemUtils.getSystemId();
dynamoDB = new DynamoDB(db);
switch (SystemUtils.getSystemMode()) {
case CLUSTER:
dropConfiguration(removeS3Bucket);
clusterConfigurationService.removeClusterInfrastructure();
break;
case STANDALONE:
dropConfiguration(removeS3Bucket);
LOG.info("Terminating instance");
terminateInstance();
break;
}
}
示例11: handleRequest
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
@Override
public Object handleRequest(DynamodbEvent input, Context context) {
context.getLogger().log("Input: " + input);
DynamoDB dynamodb = new DynamoDB(Regions.US_WEST_2);
for (DynamodbStreamRecord record : input.getRecords()) {
Map<String, AttributeValue> newData = record.getDynamodb().getNewImage();
if (newData == null) continue; // ignore deletes
Item item = Item.fromMap(InternalCalls.toSimpleMapValue(newData));
DataTransformer.PLAYER_STATS_TRANSFORMER.transform(item, dynamodb);
}
return true;
}
示例12: main
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
public static void main(String[] args) {
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.setEndpoint("http://localhost:8000");
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
// Conditional delete (will fail)
DeleteItemSpec deleteItemSpec = new DeleteItemSpec()
.withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie"))
.withConditionExpression("info.rating <= :val")
.withValueMap(new ValueMap()
.withNumber(":val", 5.0));
System.out.println("Attempting a conditional delete...");
try {
table.deleteItem(deleteItemSpec);
System.out.println("DeleteItem succeeded");
} catch (Exception e) {
e.printStackTrace();
System.out.println("DeleteItem failed");
}
}
示例13: main
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
public static void main(String[] args) {
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.setEndpoint("http://localhost:8000");
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
ScanSpec scanSpec = new ScanSpec()
.withProjectionExpression("#yr, title, info.rating")
.withFilterExpression("#yr between :start_yr and :end_yr")
.withNameMap(new NameMap().with("#yr", "year"))
.withValueMap(new ValueMap().withNumber(":start_yr", 1950).withNumber(":end_yr", 1959));
ItemCollection<ScanOutcome> items = table.scan(scanSpec);
Iterator<Item> iter = items.iterator();
while (iter.hasNext()) {
Item item = iter.next();
System.out.println(item.toString());
}
}
示例14: main
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
public static void main(String[] args) {
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.setEndpoint("http://localhost:8000");
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
int year = 2015;
String title = "The Big New Movie";
try {
table.putItem(new Item()
.withPrimaryKey("year", year, "title", title)
.withJSON("info", "{\"plot\" : \"Something happens.\"}"));
System.out.println("PutItem succeeded: " +
table.getItem("year", year, "title", title).toJSONPretty());
} catch (Exception e) {
System.out.println("PutItem failed");
e.printStackTrace();
}
}
示例15: main
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.setEndpoint("http://localhost:8000");
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "Movies";
Table table = dynamoDB.createTable(tableName,
Arrays.asList(
new KeySchemaElement("year", KeyType.HASH),
new KeySchemaElement("title", KeyType.RANGE)),
Arrays.asList(
new AttributeDefinition("year", ScalarAttributeType.N),
new AttributeDefinition("title", ScalarAttributeType.S)),
new ProvisionedThroughput(10L, 10L));
try {
TableUtils.waitUntilActive(client, tableName);
System.out.println("Table status: " + table.getDescription().getTableStatus());
} catch (AmazonClientException e) {
e.printStackTrace();
System.exit(1);
}
}