Example usage for com.amazonaws.services.dynamodbv2.document.spec GetItemSpec GetItemSpec

List of usage examples for com.amazonaws.services.dynamodbv2.document.spec GetItemSpec GetItemSpec

Introduction

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

Prototype

public GetItemSpec() 

Source Link

Usage

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

License:Apache License

@Override
public <T extends Item> T read(final ItemId itemId, final Class<T> itemClass) throws NonExistentItemException {
    final ItemConfiguration itemConfiguration = getItemConfiguration(itemClass);
    final String tableName = databaseSchemaHolder.schemaName() + "." + itemConfiguration.tableName();

    final GetItemSpec itemSpec = new GetItemSpec().withPrimaryKey(getPrimaryKey(itemId, itemConfiguration));

    T item = null;/*ww w. j  ava  2 s  . co m*/

    final Table table = dynamoDBClient.getTable(tableName);

    final com.amazonaws.services.dynamodbv2.document.Item tableItem = table.getItem(itemSpec);
    if (tableItem != null) {
        final String tableText = tableItem.toJSON();
        if (tableText.isEmpty()) {
            throw new NonExistentItemException(String.format(
                    "The document of type [%s] with id [%s] does not exist", itemClass.getName(), itemId));
        }
        item = stringToItem(tableText, itemClass);
    } else {
        throw new NonExistentItemException(String
                .format("The document of type [%s] with id [%s] does not exist", itemClass.getName(), itemId));
    }
    return item;
}

From source file:com.exorath.service.lastserver.dynamodb.DynamoDBService.java

License:Apache License

@Override
public GetResult getLastServer(UUID playerId) {
    GetItemSpec spec = new GetItemSpec().withPrimaryKey(PRIM_KEY, playerId.toString());
    Item item = table.getItem(spec);//  w  w  w.ja v  a 2s .  c  o  m
    logger.info("Retrieved the following last server data for player " + playerId + ": " + item);
    if (item == null || !item.hasAttribute(GAMEID_ATTR)) {
        return new GetResult(null, null, null);
    } else {
        String gameId = null;
        String mapId = null;
        String flavorId = null;
        if (item.hasAttribute(GAMEID_ATTR)) {
            gameId = item.getString(GAMEID_ATTR);
        }
        if (item.hasAttribute(MAPID_ATTR)) {
            mapId = item.getString(MAPID_ATTR);
        }
        if (item.hasAttribute(FLAVORID_ATTR)) {
            flavorId = item.getString(FLAVORID_ATTR);
        }
        return new GetResult(gameId, mapId, flavorId);
    }
}

From source file:com.exorath.service.lobbymsg.impl.DynamoDBService.java

License:Apache License

public static GetItemSpec getMapMessagesSpec() {
    return new GetItemSpec().withPrimaryKey(getPrimaryKey());
}

From source file:com.exorath.service.treasurehunt.dynamodb.DynamoDBService.java

License:Apache License

@Override
public GetResult getTreasures(UUID playerId) {
    GetItemSpec spec = new GetItemSpec().withPrimaryKey(PRIM_KEY, playerId.toString());
    Item item = table.getItem(spec);/*from  ww  w . j  ava 2s.  co m*/
    logger.info("Retrieved the following treasures for player " + playerId + ": " + item);
    if (item == null || !item.hasAttribute(TREASURES_FIELD)) {
        return new GetResult(new Treasure[0]);
    } else {
        List list = item.getList(TREASURES_FIELD);
        Treasure[] treasures = new Treasure[list.size()];
        int i = 0;
        for (Object treasure : list) {
            treasures[i++] = new Treasure(treasure.toString());
        }
        return new GetResult(treasures);
    }
}

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

License:Open Source License

@Override
public E findOne(K keys) {
    //interface specifies throw IllegalArgumentException so use checkArgument instead
    Preconditions.checkArgument(keys != null, "keys must not be null");
    //just read the item and return it
    final Item item;
    final PrimaryKey pk = createKeys(keys);
    GetItemSpec spec = new GetItemSpec().withPrimaryKey(pk);
    try {//ww  w. j  a  va2s .c o  m
        //TODO add projection expression for keys
        item = table.getItem(spec);
        return item == null ? null : convertItemToDomain(item);
    } catch (AmazonClientException e) {
        throw convertDynamoDBException(e, "read",
                null /* conditionMessage is null because GetItem doesnt take a condition */);
    }
}

From source file:org.xmlsh.aws.util.AWSDDBCommand.java

License:BSD License

protected GetItemSpec parseGetItemSpec(Options opts) throws InvalidArgumentException, XPathException,
        UnexpectedException, UnimplementedException, IOException {
    GetItemSpec spec = new GetItemSpec().withPrimaryKey(getPrimaryKey(opts))
            .withConsistentRead(opts.hasOpt("consistant")).withNameMap(parseAttrNameExprs(opts));
    if (opts.hasRemainingArgs())
        spec.withProjectionExpression(Util.stringJoin(Util.toStringList(opts.getRemainingArgs()), ","));
    return spec;/*from ww w  .java  2 s  .c  o m*/

}

From source file:tr.com.serkanozal.samba.cache.impl.SambaGlobalCache.java

License:Open Source License

@Override
public <V> V get(String key) {
    V value;/*from  w ww.j  a  v a  2 s  .  co m*/
    Item item = DYNAMO_DB_TABLE.getItem(new GetItemSpec().withPrimaryKey("id", key).withConsistentRead(true));
    if (item == null) {
        value = null;
    } else {
        byte[] data = item.getBinary("data");
        if (data == null) {
            value = null;
        } else {
            value = deserialize(data);
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Value %s has been retrieved from global cache with key %s", key, value));
    }
    return value;
}