本文整理了Java中org.mongodb.morphia.Datastore.find()
方法的一些代码示例,展示了Datastore.find()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.find()
方法的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
方法名:find
[英]Find all instances by type
[中]按类型查找所有实例
代码示例来源:origin: jooby-project/jooby
@Override
public void prePersist(final Object entity, final DBObject dbObj, final Mapper mapper) {
MappedClass mclass = mapper.getMappedClass(entity);
Field id = mclass.getIdField();
if (id != null && id.getAnnotation(GeneratedValue.class) != null) {
try {
id.setAccessible(true);
final String collName = gen.value(mclass.getClazz());
final Query<StoredId> q = db.find(StoredId.class, "_id", collName);
final UpdateOperations<StoredId> uOps = db.createUpdateOperations(StoredId.class)
.inc("value");
StoredId newId = db.findAndModify(q, uOps);
if (newId == null) {
newId = new StoredId(collName);
db.save(newId);
}
id.set(entity, newId.value);
} catch (Exception ex) {
throw new IllegalStateException("Can't generate ID on " + mclass, ex);
}
}
}
代码示例来源:origin: com.github.sogyf/goja-mvt
/**
* query mongod entity
*
* @param cls entity class
* @param <T> paramter object cls
* @return Query https://github.com/mongodb/morphia/wiki/Query
*/
public static <T> Query<T> query(Class<T> cls) {
return _datastore.find(cls);
}
代码示例来源:origin: acmeair/acmeair
@Override
public Long count() {
return datastore.find(BookingImpl.class).countAll();
}
}
代码示例来源:origin: BlackLabs/play-morphia
public static Seq next(String name) {
Datastore ds = MorphiaPlugin.ds();
Query<Seq> q = ds.find(Seq.class, "_id", name);
UpdateOperations<Seq> o = ds.createUpdateOperations(Seq.class).inc("value");
Seq newId = ds.findAndModify(q, o);
if (null == newId) {
newId = new Seq(name);
ds.save(newId);
}
return newId;
}
代码示例来源:origin: acmeair/acmeair
@Override
public Long count() {
return datastore.find(CustomerImpl.class).countAll();
}
代码示例来源:origin: groupon/DotCi
public int assignNextBuildNumber(final DynamicProject project) {
final Datastore datastore = getDatastore();
BuildNumberCounter seq = datastore.findAndModify(
datastore.find(BuildNumberCounter.class, "key = ", project.getFullName()), // query
datastore.createUpdateOperations(BuildNumberCounter.class).inc("counter") // update
);
if (seq == null) {
seq = new BuildNumberCounter(project.getFullName(), 1);
datastore.save(seq);
}
return seq.getCounter();
}
代码示例来源:origin: stackoverflow.com
Datastore ds = ...;
//get/change/save
Settings s = ds.find(Settings.class).get(); //like findOne in the shell/driver
s.showFriendsList = true;
ds.save(s);
//or update
ds.updateFirst(ds.find(Settings.class), ds.creatUpdateOperations(Settings.class).set("showFiendsList", true));
代码示例来源:origin: protegeproject/webprotege
public Optional<EntityDiscussionThread> getThread(@Nonnull ThreadId id) {
return Optional.ofNullable(datastore.find(EntityDiscussionThread.class)
.field("_id").equal(id)
.get());
}
代码示例来源:origin: stackoverflow.com
MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost"));
Morphia morphia = new Morphia();
morphia.map(LookupData.class);
//lookupdata collection is under my local db "tutorials" in this case
Datastore datastore = morphia.createDatastore(mongoClient, "tutorials");
Map<String,ArrayList> categotyLookUpMap = new HashMap<String,ArrayList>();
LookupData lookupData = datastore.find(LookupData.class).get();
categotyLookUpMap.put(lookupData.getKey(), lookupData.getValue());
代码示例来源:origin: acmeair/acmeair
@Override
public Booking getBooking(String user, String bookingId) {
try{
Query<BookingImpl> q = datastore.find(BookingImpl.class).field("_id").equal(bookingId);
Booking booking = q.get();
return booking;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: protegeproject/webprotege
@Override
public List<SlackWebhook> getWebhooks(@Nonnull ProjectId projectId) {
return datastore.find(SlackWebhook.class).field(PROJECT_ID).equal(projectId).asList();
}
代码示例来源:origin: protegeproject/webprotege
@Nonnull
public PrefixDeclarations find(@Nonnull ProjectId projectId) {
PrefixDeclarations prefixDeclarations = datastore.find(PrefixDeclarations.class)
.field(PROJECT_ID).equal(projectId)
.get();
if(prefixDeclarations == null) {
return PrefixDeclarations.get(projectId);
}
else {
return prefixDeclarations;
}
}
}
代码示例来源:origin: acmeair/acmeair
@Override
public void invalidateSession(String sessionid) {
Query<CustomerSessionImpl> q = datastore.find(CustomerSessionImpl.class).field("_id").equal(sessionid);
datastore.delete(q);
}
代码示例来源:origin: acmeair/acmeair
@Override
protected CustomerSession getSession(String sessionid){
Query<CustomerSessionImpl> q = datastore.find(CustomerSessionImpl.class).field("_id").equal(sessionid);
return q.get();
}
代码示例来源:origin: BlackLabs/play-morphia
@Override
public Model findById(Object id) {
if (id == null)
return null;
try {
return ds().find(clazz, keyName(), Binder.directBind(id.toString(), keyType())).get();
} catch (Exception e) {
// Key is invalid, thus nothing was found
warn(e, "cannot find entity[%s] with id: %s", clazz.getName(), id);
return null;
}
}
代码示例来源:origin: protegeproject/webprotege
@Override
public List<ProjectWebhook> getProjectWebhooks(@Nonnull ProjectId projectId, ProjectWebhookEventType event) {
return datastore.find(ProjectWebhook.class)
.field(PROJECT_ID).equal(projectId)
.field(SUBSCRIBED_TO_EVENTS).equal(event)
.asList();
}
}
代码示例来源:origin: acmeair/acmeair
@Override
public Customer getCustomerByUsername(String username) {
Query<CustomerImpl> q = datastore.find(CustomerImpl.class).field("_id").equal(username);
Customer customer = q.get();
if (customer != null) {
customer.setPassword(null);
}
return customer;
}
代码示例来源:origin: protegeproject/webprotege
public List<EntityDiscussionThread> findThreads(@Nonnull ProjectId projectId,
@Nonnull OWLEntity entity) {
datastore.createQuery(EntityDiscussionThread.class);
return datastore.find(EntityDiscussionThread.class)
.disableValidation()
.field(PROJECT_ID).equal(projectId)
.field(ENTITY).equal(entity)
.order("-comments.0.createdAt")
.asList();
}
代码示例来源:origin: acmeair/acmeair
@Override
protected FlightSegment getFlightSegment(String fromAirport, String toAirport){
Query<FlightSegmentImpl> q = datastore.find(FlightSegmentImpl.class).field("originPort").equal(fromAirport).field("destPort").equal(toAirport);
FlightSegment segment = q.get();
if (segment == null) {
segment = new FlightSegmentImpl(); // put a sentinel value of a non-populated flightsegment
}
return segment;
}
代码示例来源:origin: protegeproject/webprotege
public void replaceEntity(ProjectId projectId, OWLEntity entity, OWLEntity withEntity) {
Query<EntityDiscussionThread> query = datastore.find(EntityDiscussionThread.class)
.field(PROJECT_ID).equal(projectId)
.field(ENTITY).equal(entity);
UpdateOperations<EntityDiscussionThread> updateOperations = datastore.createUpdateOperations(EntityDiscussionThread.class);
updateOperations.set("entity", withEntity);
datastore.update(query, updateOperations);
}
内容来源于网络,如有侵权,请联系作者删除!