public CompletableFuture<Stream<Username>> retrieveOwners(AttachmentId attachmentId) { return executor.execute( selectStatement.bind() .setUUID(ID, attachmentId.asUUID())) .thenApply(cassandraUtils::convertToStream) .thenApply(this::toOwners); }
public CompletableFuture<Optional<DAOAttachment>> getAttachment(AttachmentId attachmentId) { Preconditions.checkArgument(attachmentId != null); return cassandraAsyncExecutor.executeSingleRow( selectStatement.bind() .setUUID(ID_AS_UUID, attachmentId.asUUID())) .thenApply(rowOptional -> rowOptional.map(row -> CassandraAttachmentDAOV2.fromRow(row, blobIdFactory))); }
public CompletableFuture<Collection<MessageId>> getOwnerMessageIds(AttachmentId attachmentId) { Preconditions.checkArgument(attachmentId != null); return cassandraAsyncExecutor.execute( selectStatement.bind() .setUUID(ATTACHMENT_ID_AS_UUID, attachmentId.asUUID())) .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet) .map(this::rowToMessageId) .collect(Guavate.toImmutableSet())); }
@Test public void asUUIDShouldReturnAValidUUID() { AttachmentId attachmentId = AttachmentId.from("magic"); assertThat(attachmentId.asUUID()) .isEqualTo(UUID.fromString("2f3a4fcc-ca64-36e3-9bcf-33e92dd93135")); } }
public CompletableFuture<Void> addOwner(AttachmentId attachmentId, Username owner) { return executor.executeVoid( addStatement.bind() .setUUID(ID, attachmentId.asUUID()) .setString(OWNER, owner.getValue())); }
public CompletableFuture<Void> storeAttachmentForMessageId(AttachmentId attachmentId, MessageId ownerMessageId) { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setUUID(ATTACHMENT_ID_AS_UUID, attachmentId.asUUID()) .setString(ATTACHMENT_ID, attachmentId.getId()) .setString(MESSAGE_ID, ownerMessageId.serialize())); } }
public CompletableFuture<Void> storeAttachment(DAOAttachment attachment) { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setUUID(ID_AS_UUID, attachment.getAttachmentId().asUUID()) .setString(ID, attachment.getAttachmentId().getId()) .setLong(SIZE, attachment.getSize()) .setString(TYPE, attachment.getType()) .setString(BLOB_ID, attachment.getBlobId().asString())); }