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


Java AmazonDynamoDB類代碼示例

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


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

示例1: getClient

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的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;
}
 
開發者ID:Erudika,項目名稱:para,代碼行數:34,代碼來源:AWSDynamoUtils.java

示例2: getClient

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
private static AmazonDynamoDB getClient() {
    if (null != dynamodbClient) {
        return dynamodbClient;
    }

    String region = System.getProperty("DYNAMODB_REGION");
    if (null == region) {
        System.err.println("Region not set, default \"" + Regions.US_EAST_1.name() + "\" is used");
        region = Regions.US_EAST_1.name();
    }
    System.out.println("DynamoDB region: " + region);

    dynamodbClient = AmazonDynamoDBClientBuilder.standard()
            .withRegion(region)
            .build();

    return dynamodbClient;
}
 
開發者ID:arun-gupta,項目名稱:alexa-skill-java,代碼行數:19,代碼來源:DBUtil.java

示例3: getClient

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
public static final AmazonDynamoDB getClient() {
    if (null != dynamodbClient) {
        return dynamodbClient;
    }

    String region = System.getenv("DYNAMODB_REGION");
    if (null == region) {
        System.err.println("Region is null, using default \"" + Regions.US_WEST_1 + "\"");
        region = Regions.US_WEST_1.name();
    }
    System.out.println("DynamoDB region: " + region);

    dynamodbClient = AmazonDynamoDBClientBuilder.standard()
            .withRegion(region)
            .build();
    
    System.out.println("Got DynamoDB client...");

    return dynamodbClient;
}
 
開發者ID:arun-gupta,項目名稱:tweet-analysis,代碼行數:21,代碼來源:DynamoDBUtil.java

示例4: getClient

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
private static AmazonDynamoDB getClient() {
	if (null != dynamodbClient)
		return dynamodbClient;
	
	String region = System.getProperty("DYNAMODB_REGION");
	if (null == region) {
		System.err.println("Region not set, default \"" + Regions.US_WEST_1.name() + "\" is used");
		region = Regions.US_WEST_1.name();
	}
	System.out.println("DynamoDB region: " + region);
	
	dynamodbClient = AmazonDynamoDBClientBuilder.standard()
            .withRegion(region)
            .build();
	
	return dynamodbClient;
}
 
開發者ID:arun-gupta,項目名稱:dynamodb-java-helloworld,代碼行數:18,代碼來源:App.java

示例5: DefaultGroupStorage

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的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;
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:20,代碼來源:DefaultGroupStorage.java

示例6: createTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
private static void createTable(AmazonDynamoDB dynamodb, String tableName, String tableKeyFieldName) {
        List<AttributeDefinition> attributeDefinitions= new ArrayList<>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName(tableKeyFieldName).withAttributeType("S"));

        List<KeySchemaElement> keySchema = new ArrayList<>();
        keySchema.add(new KeySchemaElement().withAttributeName(tableKeyFieldName).withKeyType(KeyType.HASH));

        CreateTableRequest request = new CreateTableRequest()
                .withTableName(tableName)
                .withKeySchema(keySchema)
                .withAttributeDefinitions(attributeDefinitions)
                .withProvisionedThroughput(new ProvisionedThroughput()
                        .withReadCapacityUnits(1L)
                        .withWriteCapacityUnits(1L));

        dynamodb.createTable(request);
//TODO: just to look at the result, if needed
//        TableDescription table = dynamodb.describeTable(tableName).getTable();
    }
 
開發者ID:satr,項目名稱:aws-amazon-shopping-bot-lambda-func,代碼行數:20,代碼來源:TestRepositoryHelper.java

示例7: GenericDynamoDB

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
public GenericDynamoDB(AmazonDynamoDB client, AWSCredentialsProvider awsCredentials,
                       ClientConfiguration clientConfiguration,
                       SecretsGroupIdentifier groupIdentifier, Class<Entry> clazz, Converters converters,
                       ReadWriteLock readWriteLock) {
    this.clazz = clazz;
    buildMappings();
    this.converters = converters;
    this.awsCredentials = awsCredentials;
    this.clientConfiguration = clientConfiguration;
    this.client = client;
    this.region = RegionUtils.getRegion(groupIdentifier.region.getName());
    this.readWriteLock = readWriteLock;

    RegionLocalResourceName resourceName = new RegionLocalResourceName(groupIdentifier);
    this.tableName = resourceName.toString();
}
 
開發者ID:schibsted,項目名稱:strongbox,代碼行數:17,代碼來源:GenericDynamoDB.java

示例8: setUp

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
@Before
public void setUp() {
    dynamoDBClient = Mockito.mock(AmazonDynamoDB.class);

    GenerateDataKeyResult generateDatakeyResult = new GenerateDataKeyResult();
    generateDatakeyResult.setCiphertextBlob(Mockito.mock(ByteBuffer.class));
    generateDatakeyResult.setPlaintext(Mockito.mock(ByteBuffer.class));

    DecryptResult decryptResult = new DecryptResult();
    decryptResult.setKeyId("alias/foo");
    decryptResult.setPlaintext(Mockito.mock(ByteBuffer.class));

    awskmsClient = Mockito.mock(AWSKMS.class);
    Mockito.when(awskmsClient.generateDataKey(Mockito.any(GenerateDataKeyRequest.class))).thenReturn(generateDatakeyResult);
    Mockito.when(awskmsClient.decrypt(Mockito.any(DecryptRequest.class))).thenReturn(decryptResult);
}
 
開發者ID:jessecoyle,項目名稱:jcredstash,代碼行數:17,代碼來源:JCredStashTest.java

示例9: createItemIfNotExists

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
boolean createItemIfNotExists(String key, long currentTimeMillis, Context context) {

		LambdaLogger logger = context.getLogger();
		AmazonDynamoDB client = createDynamoDBClient(cc);
		String functionName = context.getFunctionName();

		try {
			// Create a record if it does not exist
			PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
					.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
					.addItemEntry(COL_KEY, new AttributeValue(key))
					.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
					.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
					.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
			client.putItem(req);
			return true;
		} catch (ConditionalCheckFailedException e) {
			logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
			return false;
		} finally {
			client.shutdown();
		}
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:24,代碼來源:LambdaLock.java

示例10: testProvide

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
@Test
public void testProvide() {
    Env env = new Env().register("DYNAMODB_ENDPOINT", "fakeendpoint");
    ClientConfiguration config = new ClientConfiguration();
    config.setRetryPolicy(PredefinedRetryPolicies.NO_RETRY_POLICY);

    AWSCredentialsProvider credentialsProvider = new StaticCredentialsProvider(
            new BasicAWSCredentials("fake_access_key_id", "fake_secret_access_key"));

    AmazonDynamoDBFactory factory = new AmazonDynamoDBFactory(env, credentialsProvider, config);
    AmazonDynamoDB dynamoDB = factory.provide();

    String message = "";

    try {
        dynamoDB.listTables();  
    } catch (AmazonClientException e) {
        message = e.getMessage();
    }

    assertTrue(message.startsWith("Unable to execute HTTP request: fakeendpoint"));
    
    factory.dispose(dynamoDB);
}
 
開發者ID:coding4people,項目名稱:mosquito-report-api,代碼行數:25,代碼來源:AmazonDynamoDBFactoryTest.java

示例11: scanDynamoDB

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
/**
 * Collect data for DynamoDB.
 *
 * @param stats
 *            current statistics object.
 * @param account
 *            currently used credentials object.
 * @param region
 *            currently used aws region.
 */
public static void scanDynamoDB(AwsStats stats, AwsAccount account, Regions region) {
	LOG.debug("Scan for DynamoDB in region " + region.getName() + " in account " + account.getAccountId());

	/*
	 * Amazon DynamoDB
	 */
	try {
		AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(account.getCredentials());
		dynamoDB.setRegion(Region.getRegion(region));

		List<String> list = dynamoDB.listTables().getTableNames();

		int totalItems = list.size();
		for (String tableName : list) {
			AwsResource res = new AwsResource(tableName, account.getAccountId(), AwsResourceType.DynamoDB, region);
			stats.add(res);
		}

		LOG.info(totalItems + " DynamoDB tables in region " + region.getName() + " in account " + account.getAccountId());
	} catch (AmazonServiceException ase) {
		LOG.error("Exception of DynamoDB: " + ase.getMessage());
	}
}
 
開發者ID:janloeffler,項目名稱:aws-utilization-monitor,代碼行數:34,代碼來源:AwsScan.java

示例12: KinesisShardCheckpointer

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
public KinesisShardCheckpointer(AmazonDynamoDB dynamoDBClient,
        String dynamoDBTable,
        KinesisSplit kinesisSplit,
        String logicalProcessName,
        int curIterationNumber,
        long checkpointIntervalMS,
        long dynamoReadCapacity,
        long dynamoWriteCapacity)
{
    this(new KinesisClientLeaseManager(dynamoDBTable, dynamoDBClient),
            kinesisSplit,
            logicalProcessName,
            curIterationNumber,
            checkpointIntervalMS,
            dynamoReadCapacity,
            dynamoWriteCapacity);
}
 
開發者ID:qubole,項目名稱:presto-kinesis,代碼行數:18,代碼來源:KinesisShardCheckpointer.java

示例13: shouldNotGenerateKeys_withNoSequenceConfigurations

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
@Test
public void shouldNotGenerateKeys_withNoSequenceConfigurations() throws Exception {
    // Given
    final String sequenceName = randomString(10);
    final Collection<SequenceConfiguration> sequenceConfigurations = new ArrayList<>();
    when(mockDatabaseSchemaHolder.sequenceConfigurations()).thenReturn(sequenceConfigurations);
    final AmazonDynamoDB mockAmazonDynamoDbClient = mock(AmazonDynamoDB.class);
    final SequenceKeyGenerator sequenceKeyGenerator = new SequenceKeyGenerator(sequenceName);
    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(mockDatabaseSchemaHolder);
    dynamoDbTemplate.initialize(mockAmazonDynamoDbClient);

    // When
    IllegalStateException actualException = null;
    try {
        dynamoDbTemplate.generateKeys(sequenceKeyGenerator);
    } catch (final IllegalStateException e) {
        actualException = e;
    }

    // Then
    assertNotNull(actualException);
}
 
開發者ID:travel-cloud,項目名稱:Cheddar,代碼行數:23,代碼來源:DynamoDbTemplateTest.java

示例14: safeCreateTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
/**
 * Private interface for creating tables which handles any instances of
 * Throttling of the API
 * 
 * @param dynamoClient
 * @param dynamoTable
 * @return
 * @throws Exception
 */
public static CreateTableResult safeCreateTable(
		final AmazonDynamoDB dynamoClient,
		final CreateTableRequest createTableRequest) throws Exception {
	CreateTableResult res = null;
	final int tryMax = 10;
	int tries = 0;
	while (true) {
		try {
			res = dynamoClient.createTable(createTableRequest);
			return res;
		} catch (LimitExceededException le) {
			if (tries < tryMax) {
				// back off for 1 second
				Thread.sleep(1000);
				tries++;
			} else {
				throw le;
			}
		} catch (ResourceInUseException rie) {
			// someone else is trying to create the table while we are, so
			// return ok
			return null;
		}
	}
}
 
開發者ID:awslabs,項目名稱:amazon-kinesis-aggregators,代碼行數:35,代碼來源:DynamoUtils.java

示例15: safeDescribeTable

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; //導入依賴的package包/類
/**
 * Private interface for describing tables which handles any instances of
 * Throttling of the API
 * 
 * @param dynamoClient
 * @param dynamoTable
 * @return
 * @throws Exception
 */
public static DescribeTableResult safeDescribeTable(
		final AmazonDynamoDB dynamoClient, final String dynamoTable)
		throws Exception {
	DescribeTableResult res = null;
	final int tryMax = 10;
	int tries = 0;
	while (true) {
		try {
			res = dynamoClient.describeTable(dynamoTable);

			return res;
		} catch (ResourceNotFoundException e) {
			if (tries < tryMax) {
				// sleep for a short time as this is potentially an eventual
				// consistency issue with the table having been created ms
				// ago
				Thread.sleep(10);
				tries++;
			} else {
				throw e;
			}
		}
	}
}
 
開發者ID:awslabs,項目名稱:amazon-kinesis-aggregators,代碼行數:34,代碼來源:DynamoUtils.java


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