final String tableName = table.getTableName(); final String indexName = getIndexName(); retry: for (;;) {
req.setTableName(getTableName()); UpdateTableResult result = client.updateTable(req); return this.tableDescription = result.getTableDescription();
private GetItemOutcome doLoadItem(GetItemSpec spec) { String tableName = getTable().getTableName(); // Set up the key attributes GetItemRequest req = spec.getRequest() .withTableName(tableName) .withKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())) .withExpressionAttributeNames(spec.getNameMap()); GetItemResult result = getClient().getItem(req); return new GetItemOutcome(result); }
protected ItemCollection<ScanOutcome> doScan(ScanSpec spec) { // set the table name String tableName = getTable().getTableName(); ScanRequest req = spec.getRequest().withTableName(tableName); // set up the start key, if any Collection<KeyAttribute> startKey = spec.getExclusiveStartKey(); if (startKey != null) req.setExclusiveStartKey(InternalUtils.toAttributeValueMap(startKey)); // scan filters; Collection<ScanFilter> filters = spec.getScanFilters(); if (filters != null) { req.setScanFilter(InternalUtils.toAttributeConditionMap(filters)); } // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up expressions, if any req.withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; return new ScanCollection(getClient(), spec); } }
private UpdateItemOutcome doUpdateItem(UpdateItemSpec spec) { final UpdateItemRequest request = spec.getRequest(); request.setKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())); request.setTableName(table.getTableName()); final Collection<Expected> expected = spec.getExpected(); final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(expected); request.setExpected(expectedMap); request.setAttributeUpdates( InternalUtils.toAttributeValueUpdate(spec.getAttributeUpdate())); request.setExpressionAttributeNames(spec.getNameMap()); request.setExpressionAttributeValues( InternalUtils.fromSimpleMap(spec.getValueMap())); return new UpdateItemOutcome(client.updateItem(request)); }
private DeleteItemOutcome doDeleteItem(DeleteItemSpec spec) { // set the table name final String tableName = getTable().getTableName(); // set up the keys DeleteItemRequest req = spec.getRequest().withTableName(tableName) .withKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())); // set up the expected attribute map, if any final Collection<Expected> expected = spec.getExpected(); final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(expected); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; DeleteItemResult result = getClient().deleteItem(req); return new DeleteItemOutcome(result); }
private PutItemOutcome doPutItem(PutItemSpec spec) { // set the table name String tableName = getTable().getTableName(); PutItemRequest req = spec.getRequest().withTableName(tableName); // set up the item Item item = spec.getItem(); final Map<String,AttributeValue> attributes = InternalUtils.toAttributeValues(item); // set up the expected attribute map, if any final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(spec.getExpected()); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withItem(attributes) .withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; PutItemResult result = getClient().putItem(req); return new PutItemOutcome(result); } }
protected ItemCollection<QueryOutcome> doQuery(QuerySpec spec) { String tableName = getTable().getTableName(); QueryRequest req = spec.getRequest().withTableName(tableName);
@Override public void onError(Exception e) { logger.error("Cannot create DynamoDb table: " + DynamoDbMetadataStore.this.table.getTableName(), e); DynamoDbMetadataStore.this.createTableLatch.countDown(); }
@Override public void onError(Exception e) { logger.error("Cannot create DynamoDb table: " + DynamoDbMetadataStore.this.table.getTableName(), e); DynamoDbMetadataStore.this.createTableLatch.countDown(); }
private void awaitForActive() { Assert.state(this.initialized, () -> "The component has not been initialized: " + this + ".\n Is it declared as a bean?"); try { this.createTableLatch.await(this.createTableRetries * this.createTableDelay, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("The DynamoDb table " + this.table.getTableName() + " has not been created during " + this.createTableRetries * this.createTableDelay + " seconds"); } }
private void awaitForActive() { Assert.state(this.initialized, () -> "The component has not been initialized: " + this + ".\n Is it declared as a bean?"); try { this.createTableLatch.await(this.createTableRetries * this.createTableDelay, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("The DynamoDb table " + this.table.getTableName() + " has not been created during " + this.createTableRetries * this.createTableDelay + " seconds"); } }
static void listMyTables() { TableCollection<ListTablesResult> tables = dynamoDB.listTables(); Iterator<Table> iterator = tables.iterator(); System.out.println("Listing table names"); while (iterator.hasNext()) { Table table = iterator.next(); System.out.println(table.getTableName()); } }
@Override public void clear() { Loggers.DYNAMODB_LOG.trace("[DS0123] DynamoDB store: Clearing {} items", getCacheName()); if (requestFactory.appliesRangeKey()) { throw new PersistenceException("DynamoDB clear operation not supported with applied range key"); } try { DeleteTableResult result = table.delete(); int numDeleted = result.getTableDescription().getItemCount().intValue(); Loggers.DYNAMODB_LOG.info("[DS0125] DynamoDB store: Cleared {} {} items", numDeleted, table.getTableName()); table.waitForDelete(); client.createTable(requestFactory.resolveCreateTableRequest()); table.waitForActive(); } catch (Exception e) { Loggers.DYNAMODB_LOG.error("[DS0124] {}: {}", e.getMessage(), e); throw new PersistenceException(e.getMessage(), e); } }
private void updateTimeToLiveIfAny() { if (this.timeToLive != null) { UpdateTimeToLiveRequest updateTimeToLiveRequest = new UpdateTimeToLiveRequest() .withTableName(this.table.getTableName()) .withTimeToLiveSpecification( new TimeToLiveSpecification() .withAttributeName(TTL) .withEnabled(this.timeToLive > 0)); try { this.dynamoDB.updateTimeToLive(updateTimeToLiveRequest); } catch (AmazonDynamoDBException e) { if (logger.isWarnEnabled()) { logger.warn("The error during 'updateTimeToLive' request", e); } } } }
private void updateTimeToLiveIfAny() { if (this.timeToLive != null) { UpdateTimeToLiveRequest updateTimeToLiveRequest = new UpdateTimeToLiveRequest() .withTableName(this.table.getTableName()) .withTimeToLiveSpecification( new TimeToLiveSpecification() .withAttributeName(TTL) .withEnabled(this.timeToLive > 0)); try { this.dynamoDB.updateTimeToLive(updateTimeToLiveRequest); } catch (AmazonDynamoDBException e) { if (logger.isWarnEnabled()) { logger.warn("The error during 'updateTimeToLive' request", e); } } } }
private GetItemOutcome doLoadItem(GetItemSpec spec) { String tableName = getTable().getTableName(); // Set up the key attributes GetItemRequest req = spec.getRequest() .withTableName(tableName) .withKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())) .withExpressionAttributeNames(spec.getNameMap()); GetItemResult result = getClient().getItem(req); return new GetItemOutcome(result); }
private UpdateItemOutcome doUpdateItem(UpdateItemSpec spec) { final UpdateItemRequest request = spec.getRequest(); request.setKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())); request.setTableName(table.getTableName()); final Collection<Expected> expected = spec.getExpected(); final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(expected); request.setExpected(expectedMap); request.setAttributeUpdates( InternalUtils.toAttributeValueUpdate(spec.getAttributeUpdate())); request.setExpressionAttributeNames(spec.getNameMap()); request.setExpressionAttributeValues( InternalUtils.fromSimpleMap(spec.getValueMap())); return new UpdateItemOutcome(client.updateItem(request)); }
private PutItemOutcome doPutItem(PutItemSpec spec) { // set the table name String tableName = getTable().getTableName(); PutItemRequest req = spec.getRequest().withTableName(tableName); // set up the item Item item = spec.getItem(); final Map<String,AttributeValue> attributes = InternalUtils.toAttributeValues(item); // set up the expected attribute map, if any final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(spec.getExpected()); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withItem(attributes) .withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; PutItemResult result = getClient().putItem(req); return new PutItemOutcome(result); } }
private DeleteItemOutcome doDeleteItem(DeleteItemSpec spec) { // set the table name final String tableName = getTable().getTableName(); // set up the keys DeleteItemRequest req = spec.getRequest().withTableName(tableName) .withKey(InternalUtils.toAttributeValueMap(spec.getKeyComponents())); // set up the expected attribute map, if any final Collection<Expected> expected = spec.getExpected(); final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(expected); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; DeleteItemResult result = getClient().deleteItem(req); return new DeleteItemOutcome(result); }