本文整理汇总了Java中com.amazonaws.services.dynamodbv2.document.DynamoDB.getTable方法的典型用法代码示例。如果您正苦于以下问题:Java DynamoDB.getTable方法的具体用法?Java DynamoDB.getTable怎么用?Java DynamoDB.getTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.document.DynamoDB
的用法示例。
在下文中一共展示了DynamoDB.getTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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
示例3: 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");
}
}
示例4: 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());
}
}
示例5: 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();
}
}
示例6: MAVLinkMessagesTable
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
public MAVLinkMessagesTable() {
if (System.getenv(SPL_DYNAMODB_TABLE) != null) {
tableName = System.getenv(SPL_DYNAMODB_TABLE);
}
AmazonDynamoDB dynamoDBClient = AmazonDynamoDBClientBuilder.defaultClient();
DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
table = dynamoDB.getTable(tableName);
}
示例7: updateItem
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
boolean updateItem(String key, long currentTimeMillis, int expiredIntervalMillis, Context context) {
AmazonDynamoDB client = createDynamoDBClient(cc);
String functionName = context.getFunctionName();
try {
long sec = currentTimeMillis - expiredIntervalMillis;
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable(TABLE_NAME);
Map<String, String> expressionAttributeNames = new HashMap<>();
expressionAttributeNames.put("#created_time", COL_CREATED_TIME);
Map<String, Object> expressionAttributeValues = new HashMap<>();
expressionAttributeValues.put(":now", currentTimeMillis);
expressionAttributeValues.put(":expired", sec);
table.updateItem(new PrimaryKey(COL_FUNCTION_NAME, functionName, COL_KEY, key), "set #created_time = :now", // UpdateExpression
"#created_time < :expired", // ConditionExpression
expressionAttributeNames, expressionAttributeValues);
return true;
} catch (ConditionalCheckFailedException e) {
return false;
} finally {
client.shutdown();
}
}
示例8: dynamoInsertHl7Json
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
public static void dynamoInsertHl7Json(String hl7Json, String mirthTable, String mirthId, String mirthDate) {
String firstName = "NONE";
String lastName = "NONE";
String dob = "NONE";
String docType = "hl7";
String messageType = "NONE";
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.withRegion(Regions.US_WEST_2);
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable(mirthTable);
try {
JSONObject obj = new JSONObject(hl7Json);
firstName = obj.getJSONObject("HL7Message").getJSONObject("PID").getJSONObject("PID.5").getString("PID.5.2");
lastName = obj.getJSONObject("HL7Message").getJSONObject("PID").getJSONObject("PID.5").getString("PID.5.1");
dob = obj.getJSONObject("HL7Message").getJSONObject("PID").getJSONObject("PID.7").getString("PID.7.1");
messageType = obj.getJSONObject("HL7Message").getJSONObject("MSH").getJSONObject("MSH.9").getString("MSH.9.1");
} catch (org.json.JSONException e) { System.out.println("HL7 JSON ERROR"); }
//replace empyty string with value representing blank
hl7Json = hl7Json.replaceAll("\"\"","\"NONE\"");
Item item =
new Item()
.withPrimaryKey("mirthid", mirthId)
.withString("mirthdate", mirthDate)
.withString("type", docType)
.withString("FirstName", firstName)
.withString("LastName", lastName)
.withString("DOB", dob)
.withString("HL7Type", messageType)
.withString("Processed", "N")
.withJSON("document", hl7Json);
table.putItem(item);
}
示例9: dynamoInsertJson
import com.amazonaws.services.dynamodbv2.document.DynamoDB; //导入方法依赖的package包/类
public static void dynamoInsertJson(String ccdJson, String mirthTable, String mirthId, String mirthDate) {
System.out.println( "Performing insert into DynamoDB" );
String firstName = "NONE";
String lastName = "NONE";
String dob = "NONE";
String docType = "ccda";
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.withRegion(Regions.US_WEST_2);
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable(mirthTable);
//System.out.println(ccdJson);
try {
JSONObject obj = new JSONObject(ccdJson);
firstName = obj.getJSONObject("data").getJSONObject("demographics").getJSONObject("name").getString("first");
lastName = obj.getJSONObject("data").getJSONObject("demographics").getJSONObject("name").getString("last");
dob = obj.getJSONObject("data").getJSONObject("demographics").getJSONObject("dob").getJSONObject("point").getString("date");
//System.out.println(firstName);
} catch (org.json.JSONException e) { System.out.println("JSON ERROR"); }
ccdJson = ccdJson.replaceAll("\"\"","\"NONE\"");
Item item =
new Item()
.withPrimaryKey("mirthid", mirthId)
.withString("mirthdate", mirthDate)
.withString("type", docType)
.withString("FirstName", firstName)
.withString("LastName", lastName)
.withString("DOB", dob)
.withString("Processed", "N")
.withJSON("document", ccdJson);
table.putItem(item);
}
示例10: 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";
final Map<String, Object> infoMap = new HashMap<String, Object>();
infoMap.put("plot", "Nothing happens at all.");
infoMap.put("rating", 0.0);
Item item = new Item()
.withPrimaryKey(new PrimaryKey("year", year, "title", title))
.withMap("info", infoMap);
// Attempt a conditional write. We expect this to fail.
PutItemSpec putItemSpec = new PutItemSpec()
.withItem(item)
.withConditionExpression("attribute_not_exists(#yr) and attribute_not_exists(title)")
.withNameMap(new NameMap()
.with("#yr", "year"));
System.out.println("Attempting a conditional write...");
try {
table.putItem(putItemSpec);
System.out.println("PutItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
} catch (ConditionalCheckFailedException e) {
e.printStackTrace(System.err);
System.out.println("PutItem failed");
}
}
示例11: 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";
// Conditional update (will fail)
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey(new PrimaryKey("year", 2015, "title", "The Big New Movie"))
.withUpdateExpression("remove info.actors[0]")
.withConditionExpression("size(info.actors) > :num")
.withValueMap(new ValueMap().withNumber(":num", 3));
System.out.println("Attempting a conditional update...");
try {
table.updateItem(updateItemSpec);
System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
} catch (ConditionalCheckFailedException e) {
e.printStackTrace();
System.out.println("UpdateItem failed");
}
}
示例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");
table.delete();
System.out.println("Table is being deleted");
}
示例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");
int year = 2015;
String title = "The Big New Movie";
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("year", year, "title", title)
.withUpdateExpression("set info.rating = info.rating + :val")
.withValueMap(new ValueMap()
.withNumber(":val", 1));
System.out.println("Incrementing an atomic counter...");
try {
table.updateItem(updateItemSpec);
System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
} catch (Exception e) {
System.out.println("UpdateItem failed");
e.printStackTrace();
}
}
示例14: 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);
Table table = dynamoDB.getTable("Movies");
JsonParser parser = new JsonFactory()
.createParser(new File("moviedata.json"));
Iterator<JsonNode> iter = getRootNode(parser).iterator();
ObjectNode currentNode;
while (iter.hasNext()) {
currentNode = (ObjectNode) iter.next();
int year = getYear(currentNode);
String title = getTitle(currentNode);
System.out.println("Adding movie: " + year + " " + title);
table.putItem(new Item()
.withPrimaryKey("year", year, "title", title)
.withJSON("info", getInfo(currentNode)));
}
parser.close();
}
示例15: 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";
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("year", year, "title", title)
.withUpdateExpression("set info.rating = :r, info.plot=:p, info.actors=:a")
.withValueMap(new ValueMap()
.withNumber(":r", 5.5)
.withString(":p", "Everything happens all at once.")
.withList(":a", Arrays.asList("Larry","Moe","Curly")));
System.out.println("Updating the item...");
try {
table.updateItem(updateItemSpec);
System.out.println("UpdateItem succeeded: " + table.getItem("year", year, "title", title).toJSONPretty());
} catch (Exception e) {
System.out.println("UpdateItem failed");
e.printStackTrace();
}
}