本文整理汇总了Java中org.mongodb.morphia.query.FindOptions类的典型用法代码示例。如果您正苦于以下问题:Java FindOptions类的具体用法?Java FindOptions怎么用?Java FindOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FindOptions类属于org.mongodb.morphia.query包,在下文中一共展示了FindOptions类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAll
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T extends BaseEntity> List<T> findAll(Class<T> tClass, FindOptions findOptions) {
return (Objects.nonNull(findOptions)) ?
this.datastore.find(tClass).asList(findOptions) :
this.datastore.find(tClass).asList();
}
示例2: findOne
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T extends BaseEntity> T findOne(Class<T> tClass, FindOptions findOptions) {
return (Objects.nonNull(findOptions)) ?
this.datastore.find(tClass).get(findOptions) :
this.datastore.find(tClass).get();
}
示例3: setUp
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
@Override
public void setUp() {
super.setUp();
getMorphia().map(Address.class);
if (getDs().getCount(Address.class) == 0) {
for (int i = 0; i < nbOfAddresses; i++) {
final Address address = new Address(i);
getDs().save(address);
}
getDs().find(Address.class).filter("name", "random")
.fetch(new FindOptions()
.limit(-1));
}
}
示例4: findWorlds
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
public List<World> findWorlds(int limit) {
return this.mongoDB.getDatastore().find(World.class).asList(new FindOptions().limit(limit));
}
示例5: exists
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
@Override
public boolean exists(final Query<T> query) {
return query.get(new FindOptions().limit(1)) != null;
}
示例6: testDAO
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
@Test
public void testDAO() throws Exception {
getMorphia().map(Hotel.class);
final Hotel borg = new Hotel();
borg.setName("Hotel Borg");
borg.setStars(4);
borg.setTakesCreditCards(true);
borg.setStartDate(new Date());
borg.setType(Hotel.Type.LEISURE);
final Address address = new Address();
address.setStreet("Posthusstraeti 11");
address.setPostCode("101");
address.setSecretWord("philodendron");
borg.setAddress(address);
final HotelDAO hotelDAO = new HotelDAO(getMorphia(), getMongoClient());
hotelDAO.save(borg);
assertEquals(1, hotelDAO.count());
assertNotNull(borg.getId());
final Hotel hotelLoaded = hotelDAO.get(borg.getId());
assertEquals(borg.getName(), hotelLoaded.getName());
assertEquals(borg.getAddress().getPostCode(), hotelLoaded.getAddress().getPostCode());
final DBObject dbObject = getMorphia().toDBObject(borg);
assertNull(((DBObject) dbObject.get("address")).get("secretWord"));
Assert.assertNull(hotelLoaded.getAddress().getSecretWord());
final Hotel hotelByValue = hotelDAO.findOne("name", "Hotel Borg");
assertNotNull(hotelByValue);
assertEquals(borg.getStartDate(), hotelByValue.getStartDate());
assertTrue(hotelDAO.exists("stars", 4));
final Hotel hilton = new Hotel();
hilton.setName("Hilton Hotel");
hilton.setStars(4);
hilton.setTakesCreditCards(true);
hilton.setStartDate(new Date());
hilton.setType(Hotel.Type.BUSINESS);
final Address hiltonAddress = new Address();
hiltonAddress.setStreet("Some street 44");
hiltonAddress.setPostCode("101");
hilton.setAddress(hiltonAddress);
hotelDAO.save(hilton);
final List<Hotel> allHotels = hotelDAO.find().asList();
assertEquals(2, allHotels.size());
assertEquals(1, hotelDAO.createQuery()
.asList(new FindOptions()
.skip(1)
.limit(10))
.size());
assertEquals(1, hotelDAO.createQuery()
.asList(new FindOptions()
.limit(1))
.size());
assertTrue(hotelDAO.exists("type", Hotel.Type.BUSINESS));
assertNotNull(hotelDAO.findOne("type", Hotel.Type.LEISURE));
// try updating
final 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());
}
示例7: findAll
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
/**
* Returns {@link List} of entities present in database.
* <p>
* If {@link FindOptions} ifd provided then it will be used
* to fetch data from database other wise all entities will be returned.
*
* @param tClass entity class
* @param findOptions {@link FindOptions} to fetch data from database
* @param <T>
*
* @return {@link List<T>} list of entity
*/
<T extends BaseEntity>List<T> findAll(Class<T> tClass, FindOptions findOptions);
示例8: findOne
import org.mongodb.morphia.query.FindOptions; //导入依赖的package包/类
/**
* Returns a document entity found in database.
* <p>
* If {@link FindOptions} ifd provided then it will be used to fetch data
* from database other wise this first one will be returned.
*
* @param tClass entity type class
* @param findOptions {@link FindOptions} find options for query
* @param <T>
*
* @return T entity
*/
<T extends BaseEntity> T findOne(Class<T> tClass, FindOptions findOptions);