DAO extends BasicDAO<T, K> { public DAO(Class<T> entityClass, Mongo mongo, Morphia morphia, String dbName) { super(entityClass, mongo, morphia, dbName); } DAO(Class<T> entityClass, Mongo mongo, Morphia morphia, String dbName);  DAO(Class<T> entityClass, Datastore ds);   }
@Test public void testDAO() throws Exception { morphia.map(Hotel.class); Hotel borg = Hotel.create(); borg.setName("Hotel Borg"); borg.setStars(4); borg.setTakesCreditCards(true); borg.setStartDate(new Date()); borg.setType(Hotel.Type.LEISURE); Address borgAddr = new Address(); borgAddr.setStreet("Posthusstraeti 11"); borgAddr.setPostCode("101"); borg.setAddress(borgAddr); HotelDAO hotelDAO = new HotelDAO(morphia, mongo); hotelDAO.save(borg); assertEquals(1, hotelDAO.count()); assertNotNull(borg.getId()); Hotel hotelLoaded = hotelDAO.get(borg.getId()); assertEquals(borg.getName(), hotelLoaded.getName()); assertEquals(borg.getAddress().getPostCode(), hotelLoaded.getAddress().getPostCode()); Hotel hotelByValue = hotelDAO.findOne("name", "Hotel Borg"); assertNotNull(hotelByValue); assertEquals(borg.getStartDate(), hotelByValue.getStartDate()); assertTrue(hotelDAO.exists("stars", 4)); Hotel hilton = Hotel.create(); hilton.setName("Hilton Hotel"); hilton.setStars(4); hilton.setTakesCreditCards(true); hilton.setStartDate(new Date()); hilton.setType(Hotel.Type.BUSINESS); Address hiltonAddr = new Address(); hiltonAddr.setStreet("Some street 44"); hiltonAddr.setPostCode("101"); hilton.setAddress(hiltonAddr); hotelDAO.save(hilton); List<Hotel> allHotels = hotelDAO.find().asList(); assertEquals(2, allHotels.size()); assertEquals(1, hotelDAO.find(hotelDAO.createQuery().offset(1).limit(10)).asList().size()); assertEquals(1, hotelDAO.find(hotelDAO.createQuery().limit(1)).asList().size()); assertTrue(hotelDAO.exists("type", Hotel.Type.BUSINESS)); assertNotNull(hotelDAO.findOne("type", Hotel.Type.LEISURE)); UpdateOperations<Hotel> mods = hotelDAO.createUpdateOperations().inc("stars", 1); hotelDAO.update(hotelDAO.createQuery().filter("stars", 4), mods); assertEquals(2, hotelDAO.count(hotelDAO.createQuery().filter("stars", 5))); hotelDAO.deleteById(borg.getId()); assertEquals(1, hotelDAO.count()); hotelDAO.getCollection().drop(); assertEquals(0, hotelDAO.count()); }