本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.ProjectionType类的典型用法代码示例。如果您正苦于以下问题:Java ProjectionType类的具体用法?Java ProjectionType怎么用?Java ProjectionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectionType类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了ProjectionType类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
private CreateTableResult createTable() {
final List<AttributeDefinition> attributeDefinitions = new ArrayList<>();
attributeDefinitions.add(new AttributeDefinition(RESOURCE_NAME_ATT, ScalarAttributeType.S));
attributeDefinitions.add(new AttributeDefinition(RDF_TRIPLE_ATT, ScalarAttributeType.S));
attributeDefinitions.add(new AttributeDefinition(RDF_PREDICATE_ATT, ScalarAttributeType.S));
attributeDefinitions.add(new AttributeDefinition(RDF_OBJECT_ATT, ScalarAttributeType.S));
final List<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(new KeySchemaElement(RESOURCE_NAME_ATT, KeyType.HASH));
keySchema.add(new KeySchemaElement(RDF_TRIPLE_ATT, KeyType.RANGE));
final ProvisionedThroughput provisionedthroughput =
new ProvisionedThroughput(10L, 10L);
final LocalSecondaryIndex predicateIndex = new LocalSecondaryIndex()
.withIndexName(PREDICATE_INDEX_NAME)
.withKeySchema(new KeySchemaElement(RESOURCE_NAME_ATT, KeyType.HASH))
.withKeySchema(new KeySchemaElement(RDF_PREDICATE_ATT, KeyType.RANGE))
.withProjection(new Projection().withNonKeyAttributes(RDF_SUBJECT_ATT, RDF_OBJECT_ATT)
.withProjectionType(ProjectionType.INCLUDE));
final GlobalSecondaryIndex objectIndex = new GlobalSecondaryIndex()
.withIndexName(OBJECT_INDEX_NAME)
.withKeySchema(new KeySchemaElement(RDF_OBJECT_ATT, KeyType.HASH))
.withKeySchema(new KeySchemaElement(RDF_PREDICATE_ATT, KeyType.RANGE))
.withProjection(new Projection().withNonKeyAttributes(RDF_SUBJECT_ATT)
.withProjectionType(ProjectionType.INCLUDE))
.withProvisionedThroughput(new ProvisionedThroughput(10L, 10L));
final CreateTableRequest request =
new CreateTableRequest()
.withTableName(TABLE_NAME)
.withAttributeDefinitions(attributeDefinitions)
.withKeySchema(keySchema)
.withProvisionedThroughput(provisionedthroughput)
.withLocalSecondaryIndexes(predicateIndex)
.withGlobalSecondaryIndexes(objectIndex);
return dynamodbClient.createTable(request);
}
示例2: createIndex
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
@Override
protected void createIndex(String tableName, IndexDescription index) {
// We ALWAYS create these as GSI's, since you can't add a LSI:
CreateGlobalSecondaryIndexAction createAction = new CreateGlobalSecondaryIndexAction()
.withIndexName(index.getIndexName())
.withKeySchema(toKeySchema(tableName, index))
.withProvisionedThroughput(
new ProvisionedThroughput()
.withReadCapacityUnits(index.getReadCapacity())
.withWriteCapacityUnits(index.getWriteCapacity()))
.withProjection(new Projection().withProjectionType(ProjectionType.ALL));
AttributeDefinition hashKey = new AttributeDefinition()
.withAttributeName(index.getHashKey().getAttrName())
.withAttributeType(toScalarAttributeType(index.getHashKey().getAttrType()));
if ( null == index.getRangeKey() ) {
_dynamodb.getTable(getTableName(tableName))
.createGSI(createAction, hashKey);
} else {
AttributeDefinition rangeKey = new AttributeDefinition()
.withAttributeName(index.getRangeKey().getAttrName())
.withAttributeType(toScalarAttributeType(index.getRangeKey().getAttrType()));
_dynamodb.getTable(getTableName(tableName))
.createGSI(createAction, hashKey, rangeKey);
}
}
示例3: createSharedTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
/**
* Creates a table in AWS DynamoDB which will be shared between apps.
* @param readCapacity read capacity
* @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._ID).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._ID, ScalarAttributeType.S)).
withGlobalSecondaryIndexes(secIndex).
withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity)));
} catch (Exception e) {
logger.error(null, e);
return false;
}
return true;
}
示例4: getCreateTableRequest
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
/**
* <p>
* 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;
}
示例5: createTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
public void createTable() {
final AttributeDefinition nsKey =
new AttributeDefinition().withAttributeName(HASH_KEY).withAttributeType(
ScalarAttributeType.S);
final AttributeDefinition featureKey =
new AttributeDefinition().withAttributeName(RANGE_KEY)
.withAttributeType(ScalarAttributeType.S);
final AttributeDefinition id =
new AttributeDefinition().withAttributeName(ATTR_ID)
.withAttributeType(ScalarAttributeType.S);
final ArrayList<AttributeDefinition>
tableAttributeDefinitions = Lists.newArrayList(nsKey, featureKey, id);
final ArrayList<KeySchemaElement> tableKeySchema = Lists.newArrayList();
tableKeySchema.add(
new KeySchemaElement().withAttributeName(HASH_KEY).withKeyType(KeyType.HASH));
tableKeySchema.add(
new KeySchemaElement().withAttributeName(RANGE_KEY).withKeyType(KeyType.RANGE));
final ProvisionedThroughput tableProvisionedThroughput =
new ProvisionedThroughput()
.withReadCapacityUnits(10L)
.withWriteCapacityUnits(10L);
final ArrayList<KeySchemaElement> indexKeySchema = new ArrayList<>();
indexKeySchema.add(
new KeySchemaElement().withAttributeName(HASH_KEY).withKeyType(KeyType.HASH));
indexKeySchema.add(
new KeySchemaElement().withAttributeName(ATTR_ID).withKeyType(KeyType.RANGE));
final Projection projection = new Projection().withProjectionType(ProjectionType.INCLUDE);
final ArrayList<String> indexColumns = new ArrayList<>();
indexColumns.add("json");
indexColumns.add("v");
projection.setNonKeyAttributes(indexColumns);
final LocalSecondaryIndex localSecondaryIndex = new LocalSecondaryIndex()
.withIndexName("feature_by_ns_key_and_id_lsi_idx")
.withKeySchema(indexKeySchema)
.withProjection(projection);
final ArrayList<LocalSecondaryIndex> secondaryIndices = new ArrayList<>();
secondaryIndices.add(localSecondaryIndex);
final CreateTableRequest createTableRequest =
new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(tableKeySchema)
.withAttributeDefinitions(tableAttributeDefinitions)
.withProvisionedThroughput(tableProvisionedThroughput)
.withLocalSecondaryIndexes(secondaryIndices);
final TableDescription tableDescription =
amazonDynamoDB.createTable(createTableRequest).getTableDescription();
logger.info("created_table {}", tableDescription);
final DescribeTableRequest describeTableRequest =
new DescribeTableRequest().withTableName(tableName);
final TableDescription description =
amazonDynamoDB.describeTable(describeTableRequest).getTable();
logger.info("table_description: " + description);
}
示例6: createTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
private void createTable() {
try {
final ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
keySchema.add(new KeySchemaElement()
.withAttributeName("id")
.withKeyType(KeyType.HASH));
final ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName("id")
.withAttributeType("S"));
final ArrayList<GlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>();
if (secondaryIndexNames != null) {
for (final String indexName : secondaryIndexNames) {
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName(indexName)
.withAttributeType("S"));
globalSecondaryIndices.add(new GlobalSecondaryIndex()
.withIndexName(indexName + "-index")
.withKeySchema(new KeySchemaElement().withAttributeName(indexName).withKeyType(KeyType.HASH))
.withProjection(new Projection().withProjectionType(ProjectionType.ALL))
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(readCapacityUnits)
.withWriteCapacityUnits(writeCapacityUnits)));
}
}
final CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withKeySchema(keySchema)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(readCapacityUnits)
.withWriteCapacityUnits(writeCapacityUnits));
if (!globalSecondaryIndices.isEmpty()) {
request.withGlobalSecondaryIndexes(globalSecondaryIndices);
}
request.setAttributeDefinitions(attributeDefinitions);
logger.debug("Issuing CreateTable request for " + tableName);
final Table table = DynamoCommons.getInstance().getDb().createTable(request);
logger.debug("Waiting for table to be created...");
table.waitForActive();
} catch (final Exception e) {
logger.error("CreateTable request failed: " + e.getMessage());
}
}
示例7: createTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
@Override
protected void createTable(TableDescription table) {
List<GlobalSecondaryIndex> gsis = new ArrayList<>();
List<LocalSecondaryIndex> lsis = new ArrayList<>();
ProvisionedThroughput mainThroughtput = null;
List<KeySchemaElement> mainKeySchema = null;
Map<String, AttrType> attrTypes = new HashMap<>();
for ( IndexDescription index : table.getIndexes() ) {
addAttrType(table.getTableName(), index.getIndexName(), attrTypes, index.getHashKey());
addAttrType(table.getTableName(), index.getIndexName(), attrTypes, index.getRangeKey());
ProvisionedThroughput throughput = new ProvisionedThroughput()
.withReadCapacityUnits(index.getReadCapacity())
.withWriteCapacityUnits(index.getWriteCapacity());
switch ( index.getIndexType() ) {
case MAIN_INDEX:
mainThroughtput = throughput;
mainKeySchema = toKeySchema(table.getTableName(), index);
break;
case LOCAL_SECONDARY_INDEX:
lsis.add(
new LocalSecondaryIndex()
.withProjection(
new Projection().withProjectionType(ProjectionType.ALL))
.withIndexName(index.getIndexName())
.withKeySchema(toKeySchema(table.getTableName(), index)));
break;
case GLOBAL_SECONDARY_INDEX:
gsis.add(
new GlobalSecondaryIndex()
.withIndexName(index.getIndexName())
.withKeySchema(toKeySchema(table.getTableName(), index))
.withProjection(
new Projection().withProjectionType(ProjectionType.ALL))
.withProvisionedThroughput(throughput));
break;
default:
throw new UnsupportedOperationException(
"Unsupported indexType="+index.getIndexType()+" for table name "+
table.getTableName()+" index="+index.getIndexName());
}
}
String tableName = getTableName(table.getTableName());
for ( int retry=0;; retry++ ) {
try {
_dynamodb.createTable(
new CreateTableRequest()
.withKeySchema(mainKeySchema)
.withProvisionedThroughput(mainThroughtput)
.withAttributeDefinitions(toAttributeDefinitions(attrTypes))
.withLocalSecondaryIndexes(lsis.size() == 0 ? null : lsis)
.withGlobalSecondaryIndexes(gsis.size() == 0 ? null : gsis)
.withTableName(tableName));
break;
} catch ( LimitExceededException ex ) {
long secs = (retry < 6) ? (long)Math.pow(2, retry) : 60L;
LOG.info("Waiting {} seconds to create {} due to: {}", secs, tableName, ex.getMessage());
try {
Thread.sleep(1000*secs);
} catch ( InterruptedException interruptedEx ) {
Thread.currentThread().interrupt();
return;
}
}
}
}
示例8: initAggTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
public void initAggTable(final String keyColumn, final String dateColumnName,
final long readCapacity, final long writeCapacity) throws Exception {
final String setDateColumn = dateColumnName == null ? StreamAggregator.DEFAULT_DATE_VALUE
: dateColumnName;
long setReadCapacity = readCapacity == -1 ? DEFAULT_READ_CAPACITY : readCapacity;
long setWriteCapacity = writeCapacity == -1 ? DEFAULT_WRITE_CAPACITY : writeCapacity;
// we have to add this attribute list so that we can project the key
// into the GSI
List<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>() {
{
add(new AttributeDefinition().withAttributeName(keyColumn).withAttributeType("S"));
add(new AttributeDefinition().withAttributeName(setDateColumn).withAttributeType(
"S"));
}
};
Collection<GlobalSecondaryIndex> gsi = new ArrayList<>();
// Global Secondary Index for accessing the table by date item
gsi.add(new GlobalSecondaryIndex().withIndexName(
StreamAggregatorUtils.getDateDimensionIndexName(tableName, setDateColumn)).withKeySchema(
new KeySchemaElement().withAttributeName(SCATTER_PREFIX_ATTRIBUTE).withKeyType(
KeyType.HASH),
new KeySchemaElement().withAttributeName(setDateColumn).withKeyType(KeyType.RANGE)).withProjection(
new Projection().withProjectionType(ProjectionType.KEYS_ONLY)).withProvisionedThroughput(
new ProvisionedThroughput().withReadCapacityUnits(setReadCapacity).withWriteCapacityUnits(
setWriteCapacity)));
attributes.add(new AttributeDefinition().withAttributeName(SCATTER_PREFIX_ATTRIBUTE).withAttributeType(
"N"));
// table is hash/range on value and date
List<KeySchemaElement> key = new ArrayList<KeySchemaElement>() {
{
add(new KeySchemaElement().withAttributeName(keyColumn).withKeyType(KeyType.HASH));
add(new KeySchemaElement().withAttributeName(setDateColumn).withKeyType(
KeyType.RANGE));
}
};
// initialise the table
DynamoUtils.initTable(this.dynamoClient, this.tableName, setReadCapacity, setWriteCapacity,
attributes, key, gsi);
}
示例9: createTokenTables
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
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) //
) //
.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);
}
开发者ID:Vivastream,项目名称:spring-security-oauth2-dynamodb,代码行数:48,代码来源:DynamoDBInitializationHelper.java
示例10: createTable
import com.amazonaws.services.dynamodbv2.model.ProjectionType; //导入依赖的package包/类
private static void createTable(
String tableName, long readCapacityUnits, long writeCapacityUnits,
String hashKeyName, String hashKeyType,
String rangeKeyName, String rangeKeyType) {
try {
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 (rangeKeyName != null) {
keySchema.add(new KeySchemaElement()
.withAttributeName(rangeKeyName)
.withKeyType(KeyType.RANGE));
attributeDefinitions.add(new AttributeDefinition()
.withAttributeName(rangeKeyName)
.withAttributeType(rangeKeyType));
}
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(hashKeyName).withKeyType(KeyType.HASH),
new KeySchemaElement() .withAttributeName("PostedBy") .withKeyType(KeyType.RANGE))
.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());
}
}