List of usage examples for com.amazonaws.services.simpledb.model Attribute setName
public void setName(String name)
From source file:squash.booking.lambdas.core.BookingManager.java
License:Apache License
@Override public List<Booking> deleteBooking(Booking bookingToDelete, boolean isSquashServiceUserCall) throws Exception { if (!initialised) { throw new IllegalStateException("The booking manager has not been initialised"); }//from w w w.j a v a 2 s .c o m getLifecycleManager().throwIfOperationInvalidForCurrentLifecycleState(false, isSquashServiceUserCall); logger.log("About to delete booking from database: " + bookingToDelete.toString()); Attribute attribute = new Attribute(); attribute.setName(getAttributeNameFromBooking(bookingToDelete)); attribute.setValue(bookingToDelete.getName()); getOptimisticPersister().delete(bookingToDelete.getDate(), attribute); logger.log("Deleted booking from database"); return getVersionedBookings(bookingToDelete.getDate()).right; }
From source file:squash.booking.lambdas.core.OptimisticPersister.java
License:Apache License
@Override public void delete(String itemName, Attribute attribute) throws Exception { if (!initialised) { throw new IllegalStateException("The optimistic persister has not been initialised"); }//from w w w . j a va2s. c om logger.log("About to delete attribute from simpledb item: " + itemName); AmazonSimpleDB client = getSimpleDBClient(); // We retry the delete if necessary if we get a // ConditionalCheckFailed exception, i.e. if someone else modifies the // database between us reading and writing it. RetryHelper.DoWithRetries(() -> { try { // Get existing attributes (and version number), via consistent // read: ImmutablePair<Optional<Integer>, Set<Attribute>> versionedAttributes = get(itemName); if (!versionedAttributes.left.isPresent()) { logger.log( "A version number attribute did not exist - this means no attributes exist, so we have nothing to delete."); return null; } if (!versionedAttributes.right.contains(attribute)) { logger.log("The attribute did not exist - so we have nothing to delete."); return null; } // Since it seems impossible to update the version number while // deleting an attribute, we first mark the attribute as inactive, // and then delete it. ReplaceableAttribute inactiveAttribute = new ReplaceableAttribute(); inactiveAttribute.setName(attribute.getName()); inactiveAttribute.setValue("Inactive" + attribute.getValue()); inactiveAttribute.setReplace(true); put(itemName, versionedAttributes.left, inactiveAttribute); // Now we can safely delete the attribute, as other readers will now // ignore it. UpdateCondition updateCondition = new UpdateCondition(); updateCondition.setName(inactiveAttribute.getName()); updateCondition.setValue(inactiveAttribute.getValue()); // Update will proceed unless the attribute no longer exists updateCondition.setExists(true); Attribute attributeToDelete = new Attribute(); attributeToDelete.setName(inactiveAttribute.getName()); attributeToDelete.setValue(inactiveAttribute.getValue()); List<Attribute> attributesToDelete = new ArrayList<>(); attributesToDelete.add(attributeToDelete); DeleteAttributesRequest simpleDBDeleteRequest = new DeleteAttributesRequest(simpleDbDomainName, itemName, attributesToDelete, updateCondition); client.deleteAttributes(simpleDBDeleteRequest); logger.log("Deleted attribute from simpledb"); return null; } catch (AmazonServiceException ase) { if (ase.getErrorCode().contains("AttributeDoesNotExist")) { // Case of trying to delete an attribute that no longer exists - // that's ok - it probably just means more than one person was // trying to delete the attribute at once. So swallow this // exception logger.log( "Caught AmazonServiceException for AttributeDoesNotExist whilst deleting attribute so" + " swallowing and continuing"); return null; } else { throw ase; } } }, Exception.class, Optional.of("Database put failed - conditional check failed"), logger); }
From source file:squash.booking.lambdas.core.RuleManager.java
License:Apache License
@Override public void deleteRule(BookingRule bookingRuleToDelete, boolean isSquashServiceUserCall) throws Exception { if (!initialised) { throw new IllegalStateException("The rule manager has not been initialised"); }/*from w w w .j a va 2 s. com*/ lifecycleManager.throwIfOperationInvalidForCurrentLifecycleState(false, isSquashServiceUserCall); logger.log("About to delete booking rule from simpledb: " + bookingRuleToDelete.toString()); String attributeName = getAttributeNameFromBookingRule(bookingRuleToDelete); String attributeValue = StringUtils.join(bookingRuleToDelete.getDatesToExclude(), ","); logger.log("Booking rule attribute name is: " + attributeName); logger.log("Booking rule attribute value is: " + attributeValue); Attribute attribute = new Attribute(); attribute.setName(attributeName); attribute.setValue(attributeValue); optimisticPersister.delete(ruleItemName, attribute); logger.log("Deleted booking rule."); return; }