@Override @Cacheable.FlushAfter public void create(final String name) throws IOException { this.table.put( new Attributes() .with(DyCounters.HASH, this.owner) .with(DyCounters.RANGE, name) .with(DyCounters.ATTR_VALUE, new AttributeValue().withN("0")) ); }
@Override public boolean has(final String name) throws IOException { return this.data.iterate( this.table, new Conditions().withAttributes( this.attributes.only(this.data.keys(this.table)) ) ).iterator().next().containsKey(name.toLowerCase(Locale.ENGLISH)); }
/** * Filter out all keys except provided ones. * @param keys Keys to leave in the map * @return Attributes */ public Attributes only(final Iterable<String> keys) { final ImmutableMap.Builder<String, AttributeValue> map = new ImmutableMap.Builder<String, AttributeValue>(); final Collection<String> hash = new HashSet<String>(0); for (final String key : keys) { hash.add(key); } for (final Map.Entry<String, AttributeValue> entry : this.entrySet()) { if (hash.contains(entry.getKey())) { map.put( entry.getKey(), entry.getValue() ); } } return new Attributes(map.build()); }
/** * With this attribute. * @param name Attribute name * @param value The value * @return Attributes */ public Attributes with(final String name, final AttributeValue value) { return new Attributes(this.attrs.with(name, value)); }
/** * With this attribute. * @param name Attribute name * @param value The value * @return Attributes * @ */ public Attributes with(final String name, final Object value) { return this.with(name, new AttributeValue(value.toString())); }
new DeleteItemRequest() .withTableName(this.name) .withKey(new Attributes(item).only(this.keys)) .withReturnConsumedCapacity( ReturnConsumedCapacity.TOTAL new Attributes(item).only(this.keys).asKeys()
@Override public Map<String, AttributeValue> put( final Map<String, AttributeValueUpdate> attrs) throws IOException { final Map<String, AttributeValue> keys = new HashMap<String, AttributeValue>(0); for (final String attr : this.data.keys(this.table)) { keys.put(attr, this.attributes.get(attr)); } try { this.data.update( this.table, new Attributes(keys), new AttributeUpdates(attrs) ); } catch (final IOException ex) { throw new IllegalStateException(ex); } return Maps.transformValues( attrs, new Function<AttributeValueUpdate, AttributeValue>() { @Override public AttributeValue apply(final AttributeValueUpdate update) { return update.getValue(); } } ); }
this.frame(), this.self, new Attributes(attributes).only(this.keys()), new Array<String>(this.keys()) );
@Override public void put(final String table, final Attributes attrs) throws IOException { try { JdbcSession session = new JdbcSession(this.connection()); for (final AttributeValue value : attrs.values()) { session = session.set(H2Data.value(value)); } session.sql( String.format( "INSERT INTO %s (%s) VALUES (%s)", H2Data.encodeTableName(table), Joiner.on(',').join(attrs.keySet()), Joiner.on(',').join(Collections.nCopies(attrs.size(), "?")) ) ); session.execute(); } catch (final SQLException ex) { throw new IOException(ex); } }
@Override public void delete(final String table, final Attributes keys) throws IOException { try { JdbcSession session = new JdbcSession(this.connection()); for (final AttributeValue value : keys.values()) { session = session.set(H2Data.value(value)); } session.sql( String.format( "DELETE FROM %s WHERE %s", H2Data.encodeTableName(table), Joiner.on(H2Data.AND).join( Iterables.transform(keys.keySet(), H2Data.WHERE) ) ) ); session.execute(); } catch (final SQLException ex) { throw new IOException(ex); } }
final Map<String, AttributeValueUpdate> attrs) throws IOException { final AmazonDynamoDB aws = this.credentials.aws(); final Attributes expected = this.attributes.only(this.keys); try { final UpdateItemRequest request = new UpdateItemRequest() .withTableName(this.name) .withExpected(expected.asKeys()) .withKey(expected) .withAttributeUpdates(attrs)
/** * Makes a GetItemRequest for a given attribute. * @param attr Attribute name * @return GetItemRequest */ private GetItemRequest makeItemRequestFor(final String attr) { final GetItemRequest request = new GetItemRequest(); request.setTableName(this.name); request.setAttributesToGet(Collections.singletonList(attr)); request.setKey(this.attributes.only(this.keys)); request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); request.setConsistentRead(true); return request; }
@Override public AttributeValue get(final String attr) throws IOException { final String attrib = String.format(Locale.ENGLISH, attr); AttributeValue value = this.attributes.get(attrib); if (value == null) { final AmazonDynamoDB aws = this.credentials.aws();
@Override public boolean has(final String attr) throws IOException { final String attrib = String.format(Locale.ENGLISH, attr); boolean has = this.attributes.containsKey(attrib); if (!has) { final AmazonDynamoDB aws = this.credentials.aws();
@Override public void delete(final Map<String, AttributeValue> attributes) throws IOException { this.data.delete( this.self, new Attributes(attributes) ); } }
/** * With this attribute. * @param name Attribute name * @param value The value * @return Attributes * @ */ public Attributes with(final String name, final Object value) { return this.with(name, new AttributeValue(value.toString())); }
new DeleteItemRequest() .withTableName(this.name) .withKey(new Attributes(item).only(this.keys)) .withReturnConsumedCapacity( ReturnConsumedCapacity.TOTAL new Attributes(item).only(this.keys).asKeys()
@Override public Map<String, AttributeValue> put( final Map<String, AttributeValueUpdate> attrs) throws IOException { final Map<String, AttributeValue> keys = new HashMap<String, AttributeValue>(0); for (final String attr : this.data.keys(this.table)) { keys.put(attr, this.attributes.get(attr)); } try { this.data.update( this.table, new Attributes(keys), new AttributeUpdates(attrs) ); } catch (final IOException ex) { throw new IllegalStateException(ex); } return Maps.transformValues( attrs, new Function<AttributeValueUpdate, AttributeValue>() { @Override public AttributeValue apply(final AttributeValueUpdate update) { return update.getValue(); } } ); }
this.frame(), this.self, new Attributes(attributes).only(this.keys()), new Array<String>(this.keys()) );