List of usage examples for com.amazonaws.services.dynamodbv2.model ProjectionType KEYS_ONLY
ProjectionType KEYS_ONLY
To view the source code for com.amazonaws.services.dynamodbv2.model ProjectionType KEYS_ONLY.
Click Source Link
From source file:com.makariev.dynamodb.data.tables.creators.ReplyCreator.java
License:Apache License
@Override public CreateTableRequest getCreateTableRequest() { final String tableName = Reply.TABLE_NAME; final String hashKeyName = "Id"; final ScalarAttributeType hashKeyType = ScalarAttributeType.S; final Long readCapacityUnits = 10L; final Long writeCapacityUnits = 10L; final String rangeKeyName = "ReplyDateTime"; final ScalarAttributeType rangeKeyType = ScalarAttributeType.S; //////////////// final CreateTableRequest request = basicTable(tableName, readCapacityUnits, writeCapacityUnits, hashKeyName, hashKeyType);//from www . j av a 2 s. c o m /////////////////////// //defining range key request.getKeySchema() .add(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE)); //defining range key request.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName(rangeKeyName).withAttributeType(rangeKeyType)); ////////////////////// //follows defininig of a local secondary index request.getAttributeDefinitions().add( new AttributeDefinition().withAttributeName("PostedBy").withAttributeType(ScalarAttributeType.S)); final List<KeySchemaElement> iks = new ArrayList<>(); iks.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH)); iks.add(new KeySchemaElement().withAttributeName("PostedBy").withKeyType(KeyType.RANGE)); final LocalSecondaryIndex localSecondaryIndex = new LocalSecondaryIndex().withIndexName("PostedByIndex") .withKeySchema(iks).withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY)); final List<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<>(); localSecondaryIndexes.add(localSecondaryIndex); request.setLocalSecondaryIndexes(localSecondaryIndexes); return request; }
From source file:com.vivastream.security.oauth2.common.util.DynamoDBInitializationHelper.java
License:Apache License
public static void createTokenTables(AmazonDynamoDBClient client, DynamoDBTokenSchema schema) { GlobalSecondaryIndex gsiAuthenticationIdToken = new GlobalSecondaryIndex() // .withIndexName(schema.getAccessIndexAuthenticationId()) // .withKeySchema(new KeySchemaElement(schema.getAccessColumnAuthenticationId(), KeyType.HASH)) // .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) // .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY)); GlobalSecondaryIndex gsiRefreshToken = new GlobalSecondaryIndex() // .withIndexName(schema.getAccessIndexRefreshToken()) // .withKeySchema(new KeySchemaElement(schema.getAccessColumnRefreshToken(), KeyType.HASH)) // .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) // .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY)); GlobalSecondaryIndex gsiClientIdAndUserName = new GlobalSecondaryIndex() // .withIndexName(schema.getAccessIndexClientIdAndUserName()) // .withKeySchema( // new KeySchemaElement(schema.getAccessColumnClientId(), KeyType.HASH), // new KeySchemaElement(schema.getAccessColumnUserName(), KeyType.RANGE) // ) //// ww w . j av a 2s. com .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) // .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY)); CreateTableRequest accessTableRequest = new CreateTableRequest() // .withTableName(schema.getAccessTableName()) // .withKeySchema(new KeySchemaElement(schema.getAccessColumnTokenId(), KeyType.HASH)) // .withGlobalSecondaryIndexes(gsiAuthenticationIdToken, gsiRefreshToken, gsiClientIdAndUserName) // .withAttributeDefinitions( new AttributeDefinition(schema.getAccessColumnTokenId(), ScalarAttributeType.S), // new AttributeDefinition(schema.getAccessColumnAuthenticationId(), ScalarAttributeType.S), // new AttributeDefinition(schema.getAccessColumnRefreshToken(), ScalarAttributeType.S), // new AttributeDefinition(schema.getAccessColumnClientId(), ScalarAttributeType.S), // new AttributeDefinition(schema.getAccessColumnUserName(), ScalarAttributeType.S) // ) // .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) // ; CreateTableResult accessTableresponse = client.createTable(accessTableRequest); CreateTableRequest refreshTableRequest = new CreateTableRequest() // .withTableName(schema.getRefreshTableName()) // .withKeySchema(new KeySchemaElement(schema.getRefreshColumnTokenId(), KeyType.HASH)) // .withAttributeDefinitions( new AttributeDefinition(schema.getRefreshColumnTokenId(), ScalarAttributeType.S) // ) // .withProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) // ; CreateTableResult refreshTableresponse = client.createTable(refreshTableRequest); }
From source file:DynamoDB.sample.CreateTablesLoadData.java
License:Open Source License
private static void createTable(String tableName, long readCapacityUnits, long writeCapacityUnits, String partitionKeyName, String partitionKeyType, String sortKeyName, String sortKeyType) { try {// ww w .j a v a 2 s. co m ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH)); //Partition key ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName) .withAttributeType(partitionKeyType)); if (sortKeyName != null) { keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName).withKeyType(KeyType.RANGE)); //Sort key attributeDefinitions.add( new AttributeDefinition().withAttributeName(sortKeyName).withAttributeType(sortKeyType)); } CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); // If this is the Reply table, define a local secondary index if (replyTableName.equals(tableName)) { attributeDefinitions .add(new AttributeDefinition().withAttributeName("PostedBy").withAttributeType("S")); ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>(); localSecondaryIndexes.add(new LocalSecondaryIndex().withIndexName("PostedBy-Index") .withKeySchema( new KeySchemaElement().withAttributeName(partitionKeyName) .withKeyType(KeyType.HASH), //Partition key new KeySchemaElement().withAttributeName("PostedBy").withKeyType(KeyType.RANGE)) //Sort key .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); request.setLocalSecondaryIndexes(localSecondaryIndexes); } request.setAttributeDefinitions(attributeDefinitions); System.out.println("Issuing CreateTable request for " + tableName); Table table = dynamoDB.createTable(request); System.out.println("Waiting for " + tableName + " to be created...this may take a while..."); table.waitForActive(); } catch (Exception e) { System.err.println("CreateTable request failed for " + tableName); System.err.println(e.getMessage()); } }
From source file:io.venable.amazonaws.dynamo.table.builder.ProjectionBuilderImpl.java
License:Apache License
@Override public T keys() { projection.setProjectionType(ProjectionType.KEYS_ONLY); return parent; }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
/** * Creates a GSI configuration object//from ww w. j a v a 2 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:org.diksha.common.dyutils.SchedulerDynamoTable.java
License:Apache License
public void createDynamoTable(DynamoDB dynamoDB) { try {// ww w. j a va2s .c om System.out.println(toString()); ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH)); ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions .add(new AttributeDefinition().withAttributeName(hashKeyName).withAttributeType(hashKeyType)); if (rangeKeyType != null) { if (!rangeKeyType.isEmpty()) { attributeDefinitions.add(new AttributeDefinition().withAttributeName(rangeKeyName) .withAttributeType(rangeKeyType)); } } if (additionalAttributes.size() > 0) { for (int cnt = 0; cnt < additionalAttributes.size(); cnt++) { String[] args = (additionalAttributes.get(cnt).toString()).split(":"); if (args.length == 2) { attributeDefinitions.add( new AttributeDefinition().withAttributeName(args[0]).withAttributeType(args[1])); } } } CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>(); ArrayList<GlobalSecondaryIndex> globalSecondaryIndexes = new ArrayList<GlobalSecondaryIndex>(); if (rangeKeyType != null) { if (!rangeKeyType.isEmpty()) { if (rangeKeyTypeGlobalOrLocal.equals("L")) { localSecondaryIndexes .add(new LocalSecondaryIndex().withIndexName(rangeKeyName + "-Index") .withKeySchema( new KeySchemaElement().withAttributeName(hashKeyName) .withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyName) .withKeyType(KeyType.RANGE)) .withProjection( new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); } else { globalSecondaryIndexes .add(new GlobalSecondaryIndex().withIndexName(rangeKeyName + "-Index") .withKeySchema( new KeySchemaElement().withAttributeName(hashKeyName) .withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyName) .withKeyType(KeyType.RANGE)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(indexReadCapacityUnits) .withWriteCapacityUnits(indexWriteCapacityUnits)) .withProjection( new Projection().withProjectionType(ProjectionType.KEYS_ONLY))); } } } if (indices.size() > 0) { for (int cnt = 0; cnt < indices.size(); cnt++) { SchedulerDynamoTableIndex schedulerDynamoTableIndex = indices.get(cnt); if (schedulerDynamoTableIndex.isGlobal()) { // System.out.println("IS GLOBAL"); globalSecondaryIndexes.add(schedulerDynamoTableIndex.getGlobalSecondaryIndex()); // System.out.println("size = " + globalSecondaryIndexes.size()); } } } if (localSecondaryIndexes.size() > 0) request.setLocalSecondaryIndexes(localSecondaryIndexes); if (globalSecondaryIndexes.size() > 0) request.setGlobalSecondaryIndexes(globalSecondaryIndexes); request.setAttributeDefinitions(attributeDefinitions); System.out.println("Issuing CreateTable request for " + tableName); Table table = dynamoDB.createTable(request); System.out.println("Waiting for " + tableName + " to be created...this may take a while..."); table.waitForActive(); } catch (Exception e) { System.err.println("CreateTable request failed for " + tableName); System.err.println(e.getMessage()); } }