@Override
public Attachment findAttachmentMetadataById(String attachmentId) {
if (attachmentId == null) {
return null;
}
Attachment attachment = new Attachment();
attachment.setAttachmentId(attachmentId);
ColumnQuery<String, String, String> queryFilename = HFactory.createColumnQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
HColumn<String, String> columnFilename =
queryFilename.setColumnFamily(ATTACHMENT_CF)
.setKey(attachmentId)
.setName(FILENAME)
.execute()
.get();
if (columnFilename != null && columnFilename.getValue() != null) {
attachment.setFilename(columnFilename.getValue());
} else {
return null;
}
ColumnQuery<String, String, Long> querySize = HFactory.createColumnQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), LongSerializer.get());
HColumn<String, Long> columnSize =
querySize.setColumnFamily(ATTACHMENT_CF)
.setKey(attachmentId)
.setName(SIZE)
.execute()
.get();
if (columnSize != null && columnSize.getValue() != null) {
attachment.setSize(columnSize.getValue());
} else {
return null;
}
ColumnQuery<String, String, Date> queryCreationDate = HFactory.createColumnQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), DateSerializer.get());
HColumn<String, Date> columnCreationDate =
queryCreationDate.setColumnFamily(ATTACHMENT_CF)
.setKey(attachmentId)
.setName(CREATION_DATE)
.execute()
.get();
if (columnCreationDate != null && columnCreationDate.getValue() != null) {
attachment.setCreationDate(columnCreationDate.getValue());
} else {
attachment.setCreationDate(new Date());
}
return attachment;
}