/** * Used to specify multiple hash-only primary keys to be deleted from the * current table. * * @param hashKeyName * hash-only key name * @param hashKeyValues * a list of hash key values */ public TableWriteItems withHashOnlyKeysToDelete(String hashKeyName, Object... hashKeyValues) { if (hashKeyName == null) throw new IllegalArgumentException(); PrimaryKey[] primaryKeys = new PrimaryKey[hashKeyValues.length]; for (int i=0; i < hashKeyValues.length; i++) primaryKeys[i] = new PrimaryKey(hashKeyName, hashKeyValues[i]); return withPrimaryKeysToDelete(primaryKeys); }
/** * Adds a hash-only primary key to be deleted in a batch write * operation. * * @param hashKeyName name of the hash key attribute name * @param hashKeyValue name of the hash key value * @return the current instance for method chaining purposes */ public TableWriteItems addHashOnlyPrimaryKeyToDelete( String hashKeyName, Object hashKeyValue) { this.addPrimaryKeyToDelete(new PrimaryKey(hashKeyName, hashKeyValue)); return this; }
int batches = 0; while (count < totalToDelete + totalToPut) { final TableWriteItems writeItems = new TableWriteItems(tableName); int numToDelete = 0; if (keysToDelete != null numToDelete = Math.min(S3GUARD_DDB_BATCH_WRITE_REQUEST_LIMIT, totalToDelete - count); writeItems.withPrimaryKeysToDelete( Arrays.copyOfRange(keysToDelete, count, count + numToDelete)); count += numToDelete; totalToDelete + totalToPut - count); final int index = count - totalToDelete; writeItems.withItemsToPut( Arrays.copyOfRange(itemsToPut, index, index + numToPut)); count += numToPut;
@Override public void putItems(String tableName, ArrayList<Item> aggregation) throws Exception { try { TableWriteItems tableWriteItems = new TableWriteItems(tableName); tableWriteItems.withItemsToPut(aggregation); BatchWriteItemOutcome outcome = dynamoDB.batchWriteItem(tableWriteItems); } catch (Exception e) { LOGGER.error("Error while putting a batch of items in the table " + tableName + ". Details=" + e.getMessage()); } // try catch } // putItems
TableWriteItems forumTableWriteItems = new TableWriteItems(forumTableName) //Forum .withItemsToPut(new Item() .withPrimaryKey("Name", "Amazon RDS") .withNumber("Threads", 0)); TableWriteItems threadTableWriteItems = new TableWriteItems(threadTableName) .withItemsToPut(new Item() .withPrimaryKey("ForumName","Amazon RDS","Subject","Amazon RDS Thread 1") .withString("Message", "ElasticCache Thread 1 message") .withStringSet("Tags", new HashSet<String>( Arrays.asList("cache", "in-memory")))) .withHashAndRangeKeysToDelete("ForumName","Subject", "Amazon S3", "S3 Thread 100");
final String rangeKeyValueType = context.getProperty(RANGE_KEY_VALUE_TYPE).getValue(); TableWriteItems tableWriteItems = new TableWriteItems(table); tableWriteItems.addHashOnlyPrimaryKeysToDelete(hashKeyName, hashKeyValue); } else { tableWriteItems.addHashAndRangePrimaryKeyToDelete(hashKeyName, hashKeyValue, rangeKeyName, rangeKeyValue);
final String charset = context.getProperty(DOCUMENT_CHARSET).evaluateAttributeExpressions().getValue(); TableWriteItems tableWriteItems = new TableWriteItems(table); tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue) .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset))); } else { tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue) .withKeyComponent(rangeKeyName, rangeKeyValue) .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset)));
final String rangeKeyValueType = context.getProperty(RANGE_KEY_VALUE_TYPE).getValue(); TableWriteItems tableWriteItems = new TableWriteItems(table); tableWriteItems.addHashOnlyPrimaryKeysToDelete(hashKeyName, hashKeyValue); } else { tableWriteItems.addHashAndRangePrimaryKeyToDelete(hashKeyName, hashKeyValue, rangeKeyName, rangeKeyValue);
final String charset = context.getProperty(DOCUMENT_CHARSET).evaluateAttributeExpressions().getValue(); TableWriteItems tableWriteItems = new TableWriteItems(table); tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue) .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset))); } else { tableWriteItems.addItemToPut(new Item().withKeyComponent(hashKeyName, hashKeyValue) .withKeyComponent(rangeKeyName, rangeKeyValue) .withJSON(jsonDocument, IOUtils.toString(baos.toByteArray(), charset)));
/** * Used to specify multiple hash-and-range primary keys to be deleted * from the current table. * * @param hashKeyName * hash key name * @param rangeKeyName * range key name * @param alternatingHashAndRangeKeyValues * a list of alternating hash key value and range key value */ public TableWriteItems withHashAndRangeKeysToDelete( String hashKeyName, String rangeKeyName, Object... alternatingHashAndRangeKeyValues) { if (hashKeyName == null) throw new IllegalArgumentException("hash key name must be specified"); if (rangeKeyName == null) throw new IllegalArgumentException("range key name must be specified"); if (alternatingHashAndRangeKeyValues.length % 2 != 0) throw new IllegalArgumentException("number of hash and range key values must be the same"); final int len = alternatingHashAndRangeKeyValues.length / 2; PrimaryKey[] primaryKeys = new PrimaryKey[len]; for (int i=0; i < alternatingHashAndRangeKeyValues.length; i += 2) { primaryKeys[i >> 1] = new PrimaryKey( hashKeyName, alternatingHashAndRangeKeyValues[i], rangeKeyName, alternatingHashAndRangeKeyValues[i+1]); } return withPrimaryKeysToDelete(primaryKeys); }
/** * Adds multiple hash-only primary keys to be deleted in a batch write * operation. * * @param hashKeyName name of the hash key attribute name * @param hashKeyValues multiple hash key values * @return the current instance for method chaining purposes */ public TableWriteItems addHashOnlyPrimaryKeysToDelete(String hashKeyName, Object ... hashKeyValues) { for (Object hashKeyValue: hashKeyValues) { this.addPrimaryKeyToDelete(new PrimaryKey(hashKeyName, hashKeyValue)); } return this; }
/** * Used to specify multiple hash-only primary keys to be deleted from the * current table. * * @param hashKeyName * hash-only key name * @param hashKeyValues * a list of hash key values */ public TableWriteItems withHashOnlyKeysToDelete(String hashKeyName, Object... hashKeyValues) { if (hashKeyName == null) throw new IllegalArgumentException(); PrimaryKey[] primaryKeys = new PrimaryKey[hashKeyValues.length]; for (int i=0; i < hashKeyValues.length; i++) primaryKeys[i] = new PrimaryKey(hashKeyName, hashKeyValues[i]); return withPrimaryKeysToDelete(primaryKeys); }
/** * Adds a primary key (that consists of a hash-key and a range-key) to be * deleted in a batch write operation. * * @param hashKeyName hash key attribute name * @param hashKeyValue hash key value * @param rangeKeyName range key attribute name * @param rangeKeyValue range key value * @return the current instance for method chaining purposes */ public TableWriteItems addHashAndRangePrimaryKeyToDelete( String hashKeyName, Object hashKeyValue, String rangeKeyName, Object rangeKeyValue) { this.addPrimaryKeyToDelete( new PrimaryKey() .addComponent(hashKeyName, hashKeyValue) .addComponent(rangeKeyName, rangeKeyValue)); return this; }
/** * Used to specify multiple hash-and-range primary keys to be deleted * from the current table. * * @param hashKeyName * hash key name * @param rangeKeyName * range key name * @param alternatingHashAndRangeKeyValues * a list of alternating hash key value and range key value */ public TableWriteItems withHashAndRangeKeysToDelete( String hashKeyName, String rangeKeyName, Object... alternatingHashAndRangeKeyValues) { if (hashKeyName == null) throw new IllegalArgumentException("hash key name must be specified"); if (rangeKeyName == null) throw new IllegalArgumentException("range key name must be specified"); if (alternatingHashAndRangeKeyValues.length % 2 != 0) throw new IllegalArgumentException("number of hash and range key values must be the same"); final int len = alternatingHashAndRangeKeyValues.length / 2; PrimaryKey[] primaryKeys = new PrimaryKey[len]; for (int i=0; i < alternatingHashAndRangeKeyValues.length; i += 2) { primaryKeys[i >> 1] = new PrimaryKey( hashKeyName, alternatingHashAndRangeKeyValues[i], rangeKeyName, alternatingHashAndRangeKeyValues[i+1]); } return withPrimaryKeysToDelete(primaryKeys); }
Object hashKeyValue = alternatingHashRangeKeyValues[i]; Object rangeKeyValue = alternatingHashRangeKeyValues[i+1]; this.addPrimaryKeyToDelete( new PrimaryKey() .addComponent(hashKeyName, hashKeyValue)
/** * Adds a hash-only primary key to be deleted in a batch write * operation. * * @param hashKeyName name of the hash key attribute name * @param hashKeyValue name of the hash key value * @return the current instance for method chaining purposes */ public TableWriteItems addHashOnlyPrimaryKeyToDelete( String hashKeyName, Object hashKeyValue) { this.addPrimaryKeyToDelete(new PrimaryKey(hashKeyName, hashKeyValue)); return this; }
/** * Adds multiple hash-only primary keys to be deleted in a batch write * operation. * * @param hashKeyName name of the hash key attribute name * @param hashKeyValues multiple hash key values * @return the current instance for method chaining purposes */ public TableWriteItems addHashOnlyPrimaryKeysToDelete(String hashKeyName, Object ... hashKeyValues) { for (Object hashKeyValue: hashKeyValues) { this.addPrimaryKeyToDelete(new PrimaryKey(hashKeyName, hashKeyValue)); } return this; }
Object hashKeyValue = alternatingHashRangeKeyValues[i]; Object rangeKeyValue = alternatingHashRangeKeyValues[i+1]; this.addPrimaryKeyToDelete( new PrimaryKey() .addComponent(hashKeyName, hashKeyValue)
/** * Adds a primary key (that consists of a hash-key and a range-key) to be * deleted in a batch write operation. * * @param hashKeyName hash key attribute name * @param hashKeyValue hash key value * @param rangeKeyName range key attribute name * @param rangeKeyValue range key value * @return the current instance for method chaining purposes */ public TableWriteItems addHashAndRangePrimaryKeyToDelete( String hashKeyName, Object hashKeyValue, String rangeKeyName, Object rangeKeyValue) { this.addPrimaryKeyToDelete( new PrimaryKey() .addComponent(hashKeyName, hashKeyValue) .addComponent(rangeKeyName, rangeKeyValue)); return this; }