本文整理了Java中org.mongodb.morphia.Datastore.findAndModify()
方法的一些代码示例,展示了Datastore.findAndModify()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.findAndModify()
方法的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
方法名:findAndModify
[英]Find the first Entity from the Query, and modify it.
[中]从查询中找到第一个实体,并对其进行修改。
代码示例来源: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: de.mhus.lib/mhu-lib-persistence
public <T> T findAndModify(Query<T> query, UpdateOperations<T> operations, FindAndModifyOptions options) {
return datastore.findAndModify(query, operations, options);
}
代码示例来源:origin: de.mhus.lib/mhu-lib-persistence
public <T> T findAndModify(Query<T> query, UpdateOperations<T> operations) {
return datastore.findAndModify(query, operations);
}
代码示例来源:origin: BlackLabs/play-morphia
public <T> T findAndModify(MorphiaQuery q, boolean oldVersion) {
return (T)ds().findAndModify((Query)q.getMorphiaQuery(), (UpdateOperations)u_, oldVersion);
}
代码示例来源:origin: BlackLabs/play-morphia
public <T> T findAndModify(MorphiaQuery q, boolean oldVersion, boolean createIfMissing) {
return (T)ds().findAndModify((Query)q.getMorphiaQuery(), (UpdateOperations)u_, oldVersion, createIfMissing);
}
代码示例来源:origin: BlackLabs/play-morphia
public <T> T findAndModify(MorphiaQuery q) {
return (T)ds().findAndModify((Query)q.getMorphiaQuery(), (UpdateOperations)u_);
}
代码示例来源:origin: org.jooby/jooby-morphia
@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: org.actframework/act-morphia
/**
* Returns the next number in the sequence specified . If sequence does not exists
* then it will be created
* @param name the sequence name
* @return the next number in the sequence
*/
public long next(String name) {
UpdateOperations<Sequence> op = ds.createUpdateOperations(Sequence.class);
op.inc("number");
Query<Sequence> q = ds.createQuery(Sequence.class).field("_id").equal(name);
Sequence seq = ds.findAndModify(q, op, false, true);
return seq.number;
}
代码示例来源: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: 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();
}
内容来源于网络,如有侵权,请联系作者删除!