Example usage for com.amazonaws.services.dynamodbv2.document PrimaryKey PrimaryKey

List of usage examples for com.amazonaws.services.dynamodbv2.document PrimaryKey PrimaryKey

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document PrimaryKey PrimaryKey.

Prototype

public PrimaryKey(String hashKeyName, Object hashKeyValue) 

Source Link

Document

Constructs with a hash key.

Usage

From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.DynamoDocumentStoreTemplate.java

License:Apache License

private PrimaryKey getPrimaryKey(final ItemId itemId, final ItemConfiguration itemConfiguration) {
    final PrimaryKeyDefinition primaryKeyDefinition = itemConfiguration.primaryKeyDefinition();
    final PrimaryKey key = new PrimaryKey(primaryKeyDefinition.propertyName(), itemId.value());
    if (CompoundPrimaryKeyDefinition.class.isAssignableFrom(primaryKeyDefinition.getClass())) {
        final CompoundPrimaryKeyDefinition compoundPrimaryKeyDefinition = (CompoundPrimaryKeyDefinition) primaryKeyDefinition;
        key.addComponent(compoundPrimaryKeyDefinition.supportingPropertyName(), itemId.supportingValue());
    }// www .  j  a v a 2s  .  c o  m
    return key;
}

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

License:Open Source License

@Override
public Chunk<E> findAll(Chunkable chunkable) {
    Preconditions.checkNotNull(chunkable);
    Preconditions.checkArgument(Sort.Direction.DESC != chunkable.getDirection(),
            "DynamoDB only supports scanning forwards");
    ScanSpec spec = new ScanSpec();
    if (false == Strings.isNullOrEmpty(chunkable.getPaginationToken())) {
        spec.withExclusiveStartKey(new PrimaryKey(hashKeyName, chunkable.getPaginationToken()));
    }//from   w  w w  .  ja v a2 s .  c om
    spec.withMaxPageSize(chunkable.getMaxPageSize()).withMaxResultSize(chunkable.getMaxPageSize());

    final ItemCollection<ScanOutcome> results = table.scan(spec);

    final List<Item> itemList;
    try {
        itemList = Lists.newArrayList(results.iterator());
    } catch (AmazonClientException e) {
        throw convertDynamoDBException(e, "scan", null /* conditionMessage */);
    }
    final List<E> entities = itemList.stream().map(this::convertItemToDomain) //O(n)
            .collect(Collectors.toList()); //O(n)
    final Map<String, AttributeValue> lastEvaluatedKey = results.getLastLowLevelResult() == null ? null
            : results.getLastLowLevelResult().getScanResult().getLastEvaluatedKey();
    final String paginationToken = lastEvaluatedKey == null ? null : lastEvaluatedKey.get(hashKeyName).getS();
    return new ChunkImpl<>(entities, paginationToken, chunkable);
}

From source file:org.chodavarapu.jgitaws.repositories.ConfigurationRepository.java

License:Eclipse Distribution License

public Observable<String> getConfiguration(String repositoryName) {
    return configuration.getDynamoClient()
            .getItem(configuration.getConfigurationsTableName(),
                    new PrimaryKey(REPOSITORY_NAME_ATTRIBUTE, repositoryName))
            .map(item -> item == null ? null : item.getString(TEXT_ATTRIBUTE));
}

From source file:org.chodavarapu.jgitaws.repositories.PackDescriptionRepository.java

License:Eclipse Distribution License

private List<PrimaryKey> createKeysToDeleteList(List<PackDescriptionOperation> portion) {
    return operationsOfType(portion, Operation.REMOVAL).map(removal -> new PrimaryKey(
            new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, removal.getRepositoryDescription().getRepositoryName()),
            new KeyAttribute(NAME_ATTRIBUTE, packName(removal)))).collect(Collectors.toList());
}

From source file:org.chodavarapu.jgitaws.repositories.PackDescriptionRepository.java

License:Eclipse Distribution License

private List<Item> createItemsToPutList(List<PackDescriptionOperation> portion) {
    return operationsOfType(portion, Operation.ADDITION).map(addition -> new Item()
            .withPrimaryKey(new PrimaryKey(
                    new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE,
                            addition.getRepositoryDescription().getRepositoryName()),
                    new KeyAttribute(NAME_ATTRIBUTE, packName(addition))))
            .withString(DESCRIPTION_ATTRIBUTE, toJson(addition))).collect(Collectors.toList());
}

From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java

License:Eclipse Distribution License

public Observable<Boolean> compareAndPut(String repositoryName, Ref oldRef, Ref newRef) {
    boolean isSymbolic = newRef.isSymbolic();
    boolean isPeeled = newRef.isPeeled();
    String target = newRef.isSymbolic() ? newRef.getTarget().getName() : newRef.getObjectId().name();

    logger.debug("Saving ref {} -> {} in repository {}", newRef.getName(), target, repositoryName);

    UpdateItemSpec updateSpec = new UpdateItemSpec()
            .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName),
                    new KeyAttribute(NAME_ATTRIBUTE, newRef.getName())));

    StringBuilder updateExpression = new StringBuilder(COMPARE_AND_PUT_EXPRESSION);
    ValueMap valueMap = new ValueMap().withString(":target", target).withBoolean(":isSymbolic", isSymbolic)
            .withBoolean(":isPeeled", isPeeled);

    if (isPeeled && newRef.getPeeledObjectId() != null) {
        updateExpression.append(", ");
        updateExpression.append(PEELED_TARGET_ATTRIBUTE);
        updateExpression.append(" = :peeledTarget");
        valueMap = valueMap.withString(":peeledTarget", newRef.getPeeledObjectId().name());
    }/*from  www .  ja va  2s  . c o  m*/

    if (oldRef != null && oldRef.getStorage() != Ref.Storage.NEW) {
        String expected = oldRef.isSymbolic() ? oldRef.getTarget().getName() : oldRef.getObjectId().name();
        updateSpec = updateSpec.withConditionExpression("#target = :expected")
                .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE));
        valueMap = valueMap.withString(":expected", expected);
    }

    updateSpec = updateSpec.withUpdateExpression(updateExpression.toString()).withValueMap(valueMap);

    return configuration.getDynamoClient()
            .updateItem(configuration.getRefsTableName(), updateSpec, tableCreator).map(v -> true)
            .doOnNext(v -> logger.debug("Saved ref {} in repository {}", newRef.getName(), repositoryName))
            .onErrorReturn(t -> false);
}

From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java

License:Eclipse Distribution License

public Observable<Boolean> compareAndRemove(String repositoryName, Ref ref) {
    String expected = ref.isSymbolic() ? ref.getTarget().getName() : ref.getObjectId().name();
    logger.debug("Removing ref {} -> {} from repository {}", ref.getName(), expected, repositoryName);

    return configuration.getDynamoClient()
            .deleteItem(configuration.getRefsTableName(), new DeleteItemSpec()
                    .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName),
                            new KeyAttribute(NAME_ATTRIBUTE, ref.getName())))
                    .withConditionExpression("#target = :expected")
                    .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE))
                    .withValueMap(new ValueMap().with(":expected", expected)))
            .map(v -> true).doOnNext(v -> logger.debug("Removed ref {} -> {} from repository {}", ref.getName(),
                    expected, repositoryName))
            .onErrorReturn(t -> false);
}

From source file:org.eluder.logback.ext.dynamodb.appender.DynamoDbAppender.java

License:Open Source License

protected PrimaryKey createEventId(ILoggingEvent event) {
    return new PrimaryKey(primaryKey, UUID.randomUUID().toString());
}