Package com.michelboudreau.alternator.models

Examples of com.michelboudreau.alternator.models.Table


            com.amazonaws.services.dynamodbv2.model.BatchGetItemRequest v2Request,
            Map<String, Table> tables) {

        Map<String, KeysAndAttributes> v1RequestItems = new HashMap<String, KeysAndAttributes>();
        for (String tableName : v2Request.getRequestItems().keySet()) {
            Table table = tables.get(tableName);
            KeysAndAttributes v1RequestItem = MapV2KeysAndAttributesToV1(v2Request.getRequestItems().get(tableName), table);
            v1RequestItems.put(tableName, v1RequestItem);
        }

        BatchGetItemRequest request =
View Full Code Here


        Map<String, com.amazonaws.services.dynamodbv2.model.KeysAndAttributes> v2UnprocessedKeys = null;
        Map<String, KeysAndAttributes> v1UnprocessedKeys = result.getUnprocessedKeys();
        if (v1UnprocessedKeys != null) {
            v2UnprocessedKeys = new HashMap<String, com.amazonaws.services.dynamodbv2.model.KeysAndAttributes>();
            for (String tableName : v1UnprocessedKeys.keySet()) {
                Table table = tables.get(tableName);
                KeysAndAttributes v1KeysAndAttr = result.getUnprocessedKeys().get(tableName);
                v2UnprocessedKeys.put(tableName, MapV1KeysAndAttributesToV2(
                        v1KeysAndAttr, table));
            }
        }
View Full Code Here

    if (this.tables.containsKey(tableName)) {
      throw new ResourceInUseException("The table you're currently trying to create (" + tableName + ") is already available.");
    }

    // Add table to map, array
    Table table = new Table(tableName, request.getKeySchema(), request.getProvisionedThroughput());
    this.tables.put(tableName, table);
    this.tableList.add(table);

    return new CreateTableResult().withTableDescription(table.getTableDescription());
  }
View Full Code Here

    String tableName = request.getTableName();
    DescribeTableResult result = null;

    // Check to make sure table with same name doesn't exist
    if (this.tables.containsKey(tableName)) {
      Table table = this.tables.get(tableName);
      result = new DescribeTableResult().withTable(table.getTableDescription());
    } else {
      throw new ResourceNotFoundException("The table '" + tableName + "' does not exist.");
    }
    return result;
  }
View Full Code Here

    if (!this.tables.containsKey(request.getTableName())) {
      throw new ResourceNotFoundException("The table you want to delete '" + request.getTableName() + "' doesn't exist.");
    }

    // Delete Table
    Table table = tables.remove(request.getTableName());
    tableList.remove(table);

    return new DeleteTableResult().withTableDescription(table.getTableDescription().withTableStatus(TableStatus.DELETING));
  }
View Full Code Here

    if (!this.tables.containsKey(request.getTableName())) {
      throw new ResourceNotFoundException("The table '" + request.getTableName() + "' doesn't exist.");
    }

    // Update Table
    Table table = this.tables.get(request.getTableName());
    table.setProvisionedThroughput(request.getProvisionedThroughput());

    return new UpdateTableResult().withTableDescription(table.getTableDescription());
  }
View Full Code Here

      throw new AmazonServiceException(errors.toString());

    }

    // Check existence of table
    Table table = this.tables.get(request.getTableName());
    if (table == null) {
      throw new ResourceNotFoundException("The table '" + request.getTableName() + "' doesn't exist.");
    }

    // Make sure that item specifies hash key and range key (if in schema)
    KeySchemaElement hashKey = table.getKeySchema().getHashKeyElement();
    KeySchemaElement rangeKey = table.getKeySchema().getRangeKeyElement();
    AttributeValue hashItem = request.getItem().get(hashKey.getAttributeName());
    AttributeValueType hashItemType = getAttributeValueType(hashItem);
    if (hashItem == null || hashItemType != AttributeValueType.fromString(hashKey.getAttributeType())) {
      throw new InternalServerErrorException("Missing hash key (" + hashKey.getAttributeName() + ") from item: " + request.getItem());
    }
    if (rangeKey != null) {
      AttributeValue rangeItem = request.getItem().get(rangeKey.getAttributeName());
      AttributeValueType rangeItemType = getAttributeValueType(rangeItem);
      if (rangeItem == null || rangeItemType != AttributeValueType.fromString(rangeKey.getAttributeType())) {
        throw new InternalServerErrorException("Missing range key (" + rangeKey.getAttributeName() + ") from item: " + request.getItem());
      }
    }

    // Get current item if it exists
//    Map<String, AttributeValue> item = table.getItem(getKeyValue(request.getItem().get(table.getHashKeyName())));
        Map<String, AttributeValue> requestItem = request.getItem();
        String hashKeyValue = getKeyValue(requestItem.get(table.getHashKeyName()));
        String rangeKeyValue = getKeyValue(requestItem.get(table.getRangeKeyName()));
    Map<String, AttributeValue> item = table.getItem(hashKeyValue, rangeKeyValue);

    // Check conditional put
    validateExpected(request.getExpected(), item);

    PutItemResult result = new PutItemResult().withConsumedCapacityUnits(1D);
    if (item != null && request.getReturnValues() != null && ReturnValue.fromValue(request.getReturnValues()) == ReturnValue.ALL_OLD) {
      result.setAttributes(item);
    }

    // put the item in the table
    table.putItem(request.getItem());

    return result;
  }
View Full Code Here

    }
    return result;
  }

  public com.amazonaws.services.dynamodbv2.model.GetItemResult getItemV2(com.amazonaws.services.dynamodbv2.model.GetItemRequest v2Request) throws InternalServerErrorException, ResourceNotFoundException {
        Table table = this.tables.get(v2Request.getTableName());
        GetItemRequest request = AlternatorDBApiVersion2Mapper.MapV2GetItemRequestToV1(v2Request, table);
        GetItemResult result = getItem(request);
        return AlternatorDBApiVersion2Mapper.MapV1GetItemResultToV2(result, v2Request.getTableName());
  }
View Full Code Here

    if (errors.size() != 0) {
      throw new AmazonServiceException(errors.toString());
    }

    // Check existence of table
    Table table = this.tables.get(request.getTableName());
    if (table == null) {
      throw new ResourceNotFoundException("The table '" + request.getTableName() + "' doesn't exist.");
    }

    // Get hash and range key
    String hashKey = getKeyValue(request.getKey().getHashKeyElement());
    String rangeKey = getKeyValue(request.getKey().getRangeKeyElement());

    // Get current item if exist
    Map<String, AttributeValue> item = table.getItem(hashKey, rangeKey);

    if (item == null) {
            if (rangeKey == null) {
                throw new ResourceNotFoundException("The item with hash key '" + hashKey + "' doesn't exist in table '" + table.getName() + "'");
            } else {
                throw new ResourceNotFoundException("The item with hash key '" + hashKey + "' and range key '" + rangeKey + "' doesn't exist in table '" + table.getName() + "'");
            }
    }

    // Check conditional put
    validateExpected(request.getExpected(), item);

    DeleteItemResult result = new DeleteItemResult().withConsumedCapacityUnits(1D);
    if (item != null && request.getReturnValues() != null && ReturnValue.fromValue(request.getReturnValues()) == ReturnValue.ALL_OLD) {
      result.setAttributes(item);
    }

    // remove the item from the table
    table.removeItem(hashKey, rangeKey);
    return result;
  }
View Full Code Here

    table.removeItem(hashKey, rangeKey);
    return result;
  }

  public com.amazonaws.services.dynamodbv2.model.DeleteItemResult deleteItemV2(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest v2Request) {
        Table table = this.tables.get(v2Request.getTableName());
        DeleteItemRequest request = AlternatorDBApiVersion2Mapper.MapV2DeleteItemRequestToV1(v2Request, table);
        DeleteItemResult result = deleteItem(request);
        return AlternatorDBApiVersion2Mapper.MapV1DeleteItemResultToV2(result, v2Request.getTableName());
  }
View Full Code Here

TOP

Related Classes of com.michelboudreau.alternator.models.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.