@Test public void getInventoryQuantity_shouldFindQuantityForExistingItem() { Item existingItem = createItemBuilderWithBaseFields().quantity(100).build(); insertItem(existingItem); int quantity = itemDao.getInventoryQuantity(existingItem.getItemId()); assertThat(quantity, is(100)); }
public int getInventoryQuantity(final String itemId) { checkNotNull(emptyToNull(itemId), "Argument[itemId] must not be empty or null"); BasicDBObject field = new BasicDBObject("quantity", 1); BasicDBObject query = new BasicDBObject("_id", itemId); int quantity = -1; try (DBCursor cursor = collection.find(query, field)) { while (cursor.hasNext()) { DBObject quantityObj = cursor.next(); quantity = ((BasicDBObject) quantityObj).getInt("quantity"); } } logger.info("Found quantity[{}] for item id[{}]", quantity, itemId); return quantity; }
ItemDao extends AbstractBaseDao<Item, String> implements ItemMapper { public int getInventoryQuantity(final String itemId) { checkNotNull(emptyToNull(itemId), "Argument[itemId] must not be empty or null"); BasicDBObject field = new BasicDBObject("quantity", 1); BasicDBObject query = new BasicDBObject("_id", itemId); int quantity = -1; try (DBCursor cursor = collection.find(query, field)) { while (cursor.hasNext()) { DBObject quantityObj = cursor.next(); quantity = ((BasicDBObject) quantityObj).getInt("quantity"); } } logger.info("Found quantity[{}] for item id[{}]", quantity, itemId); return quantity; } }
ItemDao extends AbstractBaseDao<Item, String> implements ItemMapper { public int getInventoryQuantity(final String itemId) { checkNotNull(emptyToNull(itemId), "Argument[itemId] must not be empty or null"); BasicDBObject field = new BasicDBObject("quantity", 1); BasicDBObject query = new BasicDBObject("_id", itemId); int quantity = -1; try (DBCursor cursor = collection.find(query, field)) { while (cursor.hasNext()) { DBObject quantityObj = cursor.next(); quantity = ((BasicDBObject) quantityObj).getInt("quantity"); } } logger.info("Found quantity[{}] for item id[{}]", quantity, itemId); return quantity; } ItemDao(final String collectionName); }
ItemDao extends AbstractBaseDao<Item, String> implements ItemMapper { public int getInventoryQuantity(final String itemId) { checkNotNull(emptyToNull(itemId), "Argument[itemId] must not be empty or null"); BasicDBObject field = new BasicDBObject("quantity", 1); BasicDBObject query = new BasicDBObject("_id", itemId); int quantity = -1; try (DBCursor cursor = collection.find(query, field)) { while (cursor.hasNext()) { DBObject quantityObj = cursor.next(); quantity = ((BasicDBObject) quantityObj).getInt("quantity"); } } logger.info("Found quantity[{}] for item id[{}]", quantity, itemId); return quantity; } ItemDao(final String collectionName); void updateInventoryQuantity(final Map<NumericValueUpdateParam, Object> params); int getInventoryQuantity(final String itemId); List<Item> getItemListByProduct(final String productId); Item getItem(final String itemId); }
ItemDao extends AbstractBaseDao<Item, String> implements ItemMapper { public int getInventoryQuantity(final String itemId) { checkNotNull(emptyToNull(itemId), "Argument[itemId] must not be empty or null"); BasicDBObject field = new BasicDBObject("quantity", 1); BasicDBObject query = new BasicDBObject("_id", itemId); int quantity = -1; try (DBCursor cursor = collection.find(query, field)) { while (cursor.hasNext()) { DBObject quantityObj = cursor.next(); quantity = ((BasicDBObject) quantityObj).getInt("quantity"); } } logger.info("Found quantity[{}] for item id[{}]", quantity, itemId); return quantity; } ItemDao(final String collectionName); void updateInventoryQuantity(final Map<NumericValueUpdateParam, Object> params); int getInventoryQuantity(final String itemId); List<Item> getItemListByProduct(final String productId); Item getItem(final String itemId);  }