List of usage examples for com.amazonaws.services.dynamodbv2.model ProjectionType ALL
ProjectionType ALL
To view the source code for com.amazonaws.services.dynamodbv2.model ProjectionType ALL.
Click Source Link
From source file:amazon.dynamodb.util.GeoTableUtil.java
License:Open Source License
/** * <p>//from w ww . j ava 2 s .co m * Construct a create table request object based on GeoDataManagerConfiguration. The users can update any aspect of * the request and call it. * </p> * Example: * * <pre> * AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider()); * Region usWest2 = Region.getRegion(Regions.US_WEST_2); * ddb.setRegion(usWest2); * * CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config); * CreateTableResult createTableResult = ddb.createTable(createTableRequest); * </pre> * * @return Generated create table request. */ public static CreateTableRequest getCreateTableRequest(GeoDataManagerConfiguration config) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(config.getTableName()) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L)) .withKeySchema( new KeySchemaElement().withKeyType(KeyType.HASH) .withAttributeName(config.getHashKeyAttributeName()), new KeySchemaElement().withKeyType(KeyType.RANGE) .withAttributeName(config.getRangeKeyAttributeName())) .withAttributeDefinitions( new AttributeDefinition().withAttributeType(ScalarAttributeType.N) .withAttributeName(config.getHashKeyAttributeName()), new AttributeDefinition().withAttributeType(ScalarAttributeType.S) .withAttributeName(config.getRangeKeyAttributeName()), new AttributeDefinition().withAttributeType(ScalarAttributeType.N) .withAttributeName(config.getGeohashAttributeName())) .withLocalSecondaryIndexes(new LocalSecondaryIndex().withIndexName(config.getGeohashIndexName()) .withKeySchema( new KeySchemaElement().withKeyType(KeyType.HASH) .withAttributeName(config.getHashKeyAttributeName()), new KeySchemaElement().withKeyType(KeyType.RANGE) .withAttributeName(config.getGeohashAttributeName())) .withProjection(new Projection().withProjectionType(ProjectionType.ALL))); return createTableRequest; }
From source file:com.erudika.para.persistence.AWSDynamoUtils.java
License:Apache License
/** * Creates a table in AWS DynamoDB which will be shared between apps. * @param readCapacity read capacity// w ww.ja v a 2 s.c o m * @param writeCapacity write capacity * @return true if created */ public static boolean createSharedTable(long readCapacity, long writeCapacity) { if (StringUtils.isBlank(SHARED_TABLE) || StringUtils.containsWhitespace(SHARED_TABLE) || existsTable(SHARED_TABLE)) { return false; } try { GlobalSecondaryIndex secIndex = new GlobalSecondaryIndex().withIndexName(getSharedIndexName()) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)) .withProjection(new Projection().withProjectionType(ProjectionType.ALL)).withKeySchema( new KeySchemaElement().withAttributeName(Config._APPID).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(Config._TIMESTAMP).withKeyType(KeyType.RANGE)); getClient().createTable(new CreateTableRequest().withTableName(getTableNameForAppid(SHARED_TABLE)) .withKeySchema(new KeySchemaElement(Config._KEY, KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition(Config._KEY, ScalarAttributeType.S), new AttributeDefinition(Config._APPID, ScalarAttributeType.S), new AttributeDefinition(Config._TIMESTAMP, ScalarAttributeType.S)) .withGlobalSecondaryIndexes(secIndex) .withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity))); } catch (Exception e) { logger.error(null, e); return false; } return true; }
From source file:io.venable.amazonaws.dynamo.table.builder.ProjectionBuilderImpl.java
License:Apache License
@Override public T all() { projection.setProjectionType(ProjectionType.ALL); return parent; }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
/** * Creates a GSI configuration object/*from w ww . j a v a2 s .co m*/ * * @param name name of the index object to create * @param hashKey hash key of the index * @param rangeKey range key of the index * @param nonKeyAttributes determines the projection type and top level projected attributes. * if null, ALL attributes are projected. if an empty list, KEYS_ONLY are projected. * if the list has elements, only the elements INCLUDED in the list are projected * @return a description of a global secondary index that can be used to create a table. */ protected static GlobalSecondaryIndex createGlobalSecondaryIndex(String name, String hashKey, String rangeKey, List<String> nonKeyAttributes) { Preconditions.checkArgument(false == Strings.isNullOrEmpty(hashKey)); final KeySchemaElement hks = new KeySchemaElement(hashKey, KeyType.HASH); final Projection projection; if (nonKeyAttributes == null) { projection = new Projection().withProjectionType(ProjectionType.ALL); } else if (nonKeyAttributes.isEmpty()) { projection = new Projection().withProjectionType(ProjectionType.KEYS_ONLY); } else { projection = new Projection().withProjectionType(ProjectionType.INCLUDE) .withNonKeyAttributes(nonKeyAttributes); } final GlobalSecondaryIndex result = new GlobalSecondaryIndex().withIndexName(name) .withProjection(projection); if (Strings.isNullOrEmpty(rangeKey)) { result.withKeySchema(hks); } else { result.withKeySchema(hks, new KeySchemaElement(rangeKey, KeyType.RANGE)); } return result; }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
/** * gets a full item from a GSI// ww w . ja v a 2s. co m * @param indexName name of GSI * @param spec query spec for gsi query * @return a full item keyed at keys in the GSI. If the GSI does not project all attributes, will read the item from * the base table * * TODO, ideally, return a wrapper of the last evaluated key from the query result and the list, but since we are * not filtering on the server side, do this later. */ private Chunk<E> getFromGSI(String indexName, QuerySpec spec, boolean isUnique) { Preconditions.checkNotNull(spec, "query spec was null"); Chunk<Item> chunk = getItemListForGsi(indexName, spec); //check if the index was not a unique index if (isUnique) { Preconditions.checkState(chunk.getContent().size() < 2, "the index had more than one item at spec=" + spec.toString()); } if (ProjectionType .fromValue(gsis.get(indexName).getProjection().getProjectionType()) == ProjectionType.ALL) { //the GSI had the full item so return it. return new ChunkImpl<>(chunk.getContent().parallelStream().map(i -> convertItemToDomain(i)) .collect(Collectors.toList()), chunk.getPaginationToken(), null /*chunkable*/); } //else read the item from the base table try { List<AttributeValue> pks = chunk.getContent().stream().map(i -> getPrimaryKeyFromItem(i)) .map(pk -> Iterables.getOnlyElement(pk.getComponents().stream() .filter(c -> c.getName().equals(hashKeyName)).map(Attribute::getValue) .map(InternalUtils::toAttributeValue).collect(Collectors.toList()))) .collect(Collectors.toList()); return new ChunkImpl<>(findAll(pks, true), chunk.getPaginationToken(), null /*chunkable*/); } catch (AmazonClientException e) { throw convertDynamoDBException(e, "read", null /*condition failed exception provider*/); } }
From source file:org.iternine.jeppetto.dao.dynamodb.extra.TableBuilder.java
License:Apache License
public TableBuilder withLsi(String indexKey, ScalarAttributeType indexKeyType) { if (localSecondaryIndexes == null) { localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>(); }//from w ww . ja v a2s.c om attributeDefinitions.add(new AttributeDefinition(indexKey, indexKeyType)); localSecondaryIndexes.add(new LocalSecondaryIndex().withIndexName(indexKey + "-index") .withKeySchema(new KeySchemaElement(keySchema.get(0).getAttributeName(), KeyType.HASH), new KeySchemaElement(indexKey, KeyType.RANGE)) .withProjection(new Projection().withProjectionType(ProjectionType.ALL))); return this; }
From source file:org.iternine.jeppetto.dao.dynamodb.extra.TableBuilder.java
License:Apache License
public TableBuilder withGsi(String gsiHashKeyName, ScalarAttributeType gsiHashKeyType, String gsiRangeKeyName, ScalarAttributeType gsiRangeKeyType) { if (globalSecondaryIndexes == null) { globalSecondaryIndexes = new ArrayList<GlobalSecondaryIndex>(); }//from w ww . ja v a 2s .com ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); String indexName; attributeDefinitions.add(new AttributeDefinition(gsiHashKeyName, gsiHashKeyType)); keySchema.add(new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName(gsiHashKeyName)); if (gsiRangeKeyName != null) { attributeDefinitions.add(new AttributeDefinition(gsiRangeKeyName, gsiRangeKeyType)); keySchema.add(new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName(gsiRangeKeyName)); indexName = gsiHashKeyName + "-" + gsiRangeKeyName; } else { indexName = gsiHashKeyName; } globalSecondaryIndexes.add(new GlobalSecondaryIndex().withIndexName(indexName) .withProvisionedThroughput(new ProvisionedThroughput(64L, 64L)).withKeySchema(keySchema) .withProjection(new Projection().withProjectionType(ProjectionType.ALL))); return this; }
From source file:org.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java
License:Apache License
public Entity2DynamoDBTableSynchronizer(AmazonDynamoDB amazonDynamoDB, DynamoDBMapper mapper, Entity2DDL mode) { this(amazonDynamoDB, mapper, mode.getConfigurationValue(), ProjectionType.ALL.name(), 10L, 10L); }