當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonDynamoDBClient.putItem方法代碼示例

本文整理匯總了Java中com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.putItem方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonDynamoDBClient.putItem方法的具體用法?Java AmazonDynamoDBClient.putItem怎麽用?Java AmazonDynamoDBClient.putItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient的用法示例。


在下文中一共展示了AmazonDynamoDBClient.putItem方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: AddRegistration

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
public Boolean AddRegistration (Registration r) {

        DynamoServiceFactory dsf = new DynamoServiceFactory();
        AmazonDynamoDBClient client = dsf.createDynamoClient();

        long RegistrationDate =  System.currentTimeMillis();

        Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
        item.put(Registration.Fields.DonorUUID, new AttributeValue().withS(r.getDonorUUID()));
        item.put(Registration.Fields.OpportunityId, new AttributeValue().withS(r.getOpportunityId()));
        item.put(Registration.Fields.Category, new AttributeValue().withS(r.getCategory()));
        item.put(Registration.Fields.Timestamp, new AttributeValue().withN(String.valueOf(RegistrationDate)));

        PutItemRequest putItemRequest = new PutItemRequest()
                .withTableName(RegistrationTableName)
                .withItem(item);

        PutItemResult result = client.putItem(putItemRequest);

        return true;
    }
 
開發者ID:aws-reinvent-hackathon-2013-team,項目名稱:UnitedWayRESTBackend,代碼行數:22,代碼來源:DataAccess.java

示例2: putItem

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
public static void putItem(AmazonDynamoDBClient client, String tableName, String id, String val) {
    java.util.Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put("Id", new AttributeValue().withN(id));
    item.put("attribute-1", new AttributeValue().withS(val));

    PutItemRequest putItemRequest = new PutItemRequest()
        .withTableName(tableName)
        .withItem(item);
    client.putItem(putItemRequest);
}
 
開發者ID:gnethercutt,項目名稱:dynamodb-streams-kafka,代碼行數:11,代碼來源:StreamAdapterDemoHelper.java

示例3: putDynamo

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
public static synchronized void putDynamo(String parameter, BigInteger instCount, BigInteger basicBlocksCount,
		BigInteger fieldLoadsCount, BigInteger loadsCount, AmazonDynamoDBClient dynamoDB, boolean runningState,
		String threadID, QueryResult queryResult) 
{
	Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
	item.put("Parameter", new AttributeValue(parameter));
	item.put("Instructions", new AttributeValue().withN(instCount.toString()));
	item.put("Basic Blocks", new AttributeValue().withN(basicBlocksCount.toString()));
	item.put("Field Loads", new AttributeValue().withN(fieldLoadsCount.toString()));
	item.put("Loads Stack", new AttributeValue().withN(loadsCount.toString()));
	item.put("Running", new AttributeValue().withBOOL(runningState));

	// calculamos o valor do rank
	BigDecimal rank = (new BigDecimal(instCount).multiply(new BigDecimal("0.40")))
			.add(new BigDecimal(basicBlocksCount).multiply(new BigDecimal("0.15")))
			.add(new BigDecimal(fieldLoadsCount).multiply(new BigDecimal("0.05")))
			.add(new BigDecimal(loadsCount).multiply(new BigDecimal("0.40")));
	item.put("Rank", new AttributeValue().withN(rank.toBigInteger().toString()));

	// se o runningState vier a true, ou seja e' uma metrica intermedia que vamos atualizar no Dynamo,
	// temos que tambem introduzir o ThreadID que esta a tratar este parametro e a instancia.
	// estas duas informacoes sao necessarios para evitar o seguinte caso. Imaginando que duas instancias diferentes
	// estao a processar o mesmo pedido longo e ambos retiram metricas intermedias. Imaginando que a instancia A comecou
	// 1 minuto antes, entao nao podemos deixar que a instancia B nao faca overwrite na entrada no Dynamo pois a instancia A tem os
	// os dados mais recentes. O mesmo se aplica a threads dentro da mesma instancia que processam o mesmo pedido dai precisarmos do ThreadID
	if (runningState) {
		// tal como referido acima temos que verificar se esta e' a thread que deve atualizar as metricas intermedias
		String[] id = threadID.split(" ");

		if (queryResult != null) {
			Map<String, AttributeValue> result = queryResult.getItems().get(0);
			// vamos ver se o id desta thread corresponde ao que deve atualizar as metricas
			boolean containsID = result.values().contains(new AttributeValue().withN(id[1]));

			if (containsID) {
				// se sim temos de ver agora se correspondem 'a mesma instancia pois podem haver threads com o mesmo ID em
				// maquinas diferentes a processar o mesmo request
				boolean containsInstance = result.values().contains(new AttributeValue(checkInstanceId()));
				if (containsInstance) // se sim entao podemos atualizar as	 metricas
				{
					item.put("InstanceID", new AttributeValue(checkInstanceId()));
					item.put("ThreadID", new AttributeValue().withN((id[1])));
				} else //caso contrario nao fazemos nada, o mesmo para o else abaixo
					return;
			} else 
				return;
		} 
		else // este else e' o caso em que nao temos metricas internas deste parametro
		{
			item.put("InstanceID", new AttributeValue(checkInstanceId()));
			item.put("ThreadID", new AttributeValue().withN((id[1])));
		}
	}
	PutItemRequest putItemRequest = new PutItemRequest().withTableName("MSS").withItem(item);
	dynamoDB.putItem(putItemRequest);
}
 
開發者ID:carlosfaria94,項目名稱:CloudPrime,代碼行數:57,代碼來源:InstTool.java

示例4: addTestItems

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
private Set<String> addTestItems(AmazonDynamoDBClient dynamoDBClient, String tableName, int size) {
    Set<String> idSet = Sets.newHashSet();
    for (int p = 0; p < size; p ++) {
        Map<String, AttributeValue> item = Maps.newHashMap();
        int fields = randomIntBetween(10, 20);
        for (int i = 0; i < fields; i ++) {
            int t = randomIntBetween(1, 4);
            switch (t){
                case 1:
                    item.put(randomAsciiOfLengthBetween(1, 10), new AttributeValue().withS(randomAsciiOfLengthBetween(1, 20)));
                    break;
                case 2:
                    item.put(randomAsciiOfLengthBetween(1, 10), new AttributeValue().withN(String.valueOf(randomInt())));
                    break;
                case 3:
                    Set<String> s = Sets.newHashSet();
                    int ss = randomIntBetween(5, 20);
                    for (int a = 0; a < ss; a ++) {
                        s.add(randomAsciiOfLengthBetween(1, 20));
                    }
                    item.put(randomAsciiOfLengthBetween(1, 10), new AttributeValue().withSS(s));
                    break;
                case 4:
                    Set<String> n = Sets.newHashSet();
                    int ns = randomIntBetween(5, 20);
                    for (int a = 0; a < ns; a ++) {
                        n.add(String.valueOf(randomIntBetween(1, 1000)));
                    }
                    item.put(randomAsciiOfLengthBetween(1, 10), new AttributeValue().withNS(n));
                    break;
            }
        }
        String id = randomAsciiOfLengthBetween(1, 50);
        idSet.add(id);
        item.put("id", new AttributeValue().withS(id));
        item.put("updated", new AttributeValue().withN(String.valueOf(new Date().getTime())));
        PutItemRequest putItemRequest = new PutItemRequest()
                .withTableName(tableName)
                .withItem(item);
        dynamoDBClient.putItem(putItemRequest);
    }
    return idSet;
}
 
開發者ID:kzwang,項目名稱:elasticsearch-river-dynamodb,代碼行數:44,代碼來源:DynamoDbRiverTests.java

示例5: importDonationData

import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; //導入方法依賴的package包/類
public  void importDonationData () {
DynamoServiceFactory dsf = new DynamoServiceFactory();
AmazonDynamoDBClient client = dsf.createDynamoClient();

try {
    //TODO: it could be tat we get here while tble is creating (i.e. not active), this code will not work!!!!!
    DescribeTableResult describeTableResult = client.describeTable(new DescribeTableRequest(doantionDataTableName));
}
catch (Exception e)
{
    //create table
    CreateDonationDataTable(client);
}


 try {

        HashMap<String,String> donorIdUUidMap = new  HashMap<String,String>();
        //populate table
        BufferedReader in = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("DonationData.csv")));

        for (String line = in.readLine(); line != null; line = in.readLine()) {
            String [] fields = line.split(",");
            String donorId  = fields[0].trim();
            String Category = fields[5].trim();
            float Amount = Float.parseFloat(fields[4].trim());
            String DonorName =  fields[1].trim() + " " + fields[2].trim() ;

            SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
            Date d = f.parse(fields[3].trim());

            long DonationDate =  d.getTime();

            String uuid = UUID.randomUUID().toString();
            String existingUid = donorIdUUidMap.get(donorId);

            if (existingUid!=null) {
                uuid = existingUid;
            }
            else {
                donorIdUUidMap.put(donorId,uuid);
            }


            Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
            item.put("DonorUUID", new AttributeValue().withS(uuid));
            item.put("DonorId", new AttributeValue().withN(donorId));
            item.put("Category", new AttributeValue().withS(Category));
            item.put("Amount", new AttributeValue().withN(String.valueOf(Amount)));
            item.put("DonorName", new AttributeValue().withS(DonorName));
            item.put("DonationDate", new AttributeValue().withN(String.valueOf(DonationDate)));


            PutItemRequest putItemRequest = new PutItemRequest()
                    .withTableName(doantionDataTableName)
                    .withItem(item);

            PutItemResult result = client.putItem(putItemRequest);

        }
    }
    catch (Exception e1)
    {

    }

}
 
開發者ID:aws-reinvent-hackathon-2013-team,項目名稱:UnitedWayRESTBackend,代碼行數:68,代碼來源:DataAccess.java


注:本文中的com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.putItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。