本文整理了Java中org.mongodb.morphia.Datastore.createUpdateOperations()
方法的一些代码示例,展示了Datastore.createUpdateOperations()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.createUpdateOperations()
方法的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
方法名:createUpdateOperations
[英]The builder for all update operations
[中]所有更新操作的生成器
代码示例来源: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: protegeproject/webprotege
@Override
public void addTag(@Nonnull OWLEntity entity, @Nonnull TagId tagId) {
try {
writeLock.lock();
Query<EntityTags> query = tagWithProjectIdAndEntity(projectId, entity);
UpdateOperations<EntityTags> updateOps = datastore.createUpdateOperations(EntityTags.class);
updateOps.addToSet(TAGS, tagId);
datastore.update(query, updateOps);
} finally {
writeLock.unlock();
}
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void removeTag(@Nonnull OWLEntity entity, @Nonnull TagId tagId) {
try {
writeLock.lock();
Query<EntityTags> query = tagWithProjectIdAndEntity(projectId, entity);
UpdateOperations<EntityTags> updateOps = datastore.createUpdateOperations(EntityTags.class);
updateOps.removeAll(TAGS, tagId);
datastore.update(query, updateOps);
} finally {
writeLock.unlock();
}
}
代码示例来源:origin: stackoverflow.com
public boolean checkIfExistsAndInsertOtherwise(short id){
Datastore datastore = getDatastore();
Query<OrganizationId> updateQuery = datastore.createQuery(OrganizationId.class).field("identificationNumber").equal(id);
//Bogus operation, just set id to itself
UpdateOperations<OrganizationId> ops = datastore.createUpdateOperations(OrganizationId.class).set("identificationNumber", id);
UpdateResults<OrganizationId> result = datastore.updateFirst(updateQuery, ops, true,WriteConcern.SAFE);
return result.getInsertedCount() == 0;
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void setApiKeys(@Nonnull UserId userId, List<ApiKeyRecord> records) {
Set<ApiKeyId> ids = new HashSet<>();
List<ApiKeyRecord> nonDuplicates = records.stream()
.filter(r -> ids.add(r.getApiKeyId()))
.collect(Collectors.toList());
UpdateOperations<UserApiKeys> ops = datastore.createUpdateOperations(UserApiKeys.class)
.set(API_KEYS, nonDuplicates);
Query<UserApiKeys> query = datastore.createQuery(UserApiKeys.class)
.field(USER_ID).equal(userId);
datastore.update(query, ops, new UpdateOptions().upsert(true));
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void removeTag(@Nonnull TagId tagId) {
try {
writeLock.lock();
Query<EntityTags> query = datastore.createQuery(EntityTags.class)
.field(PROJECT_ID).equal(projectId);
UpdateOperations<EntityTags> updateOps = datastore.createUpdateOperations(EntityTags.class);
updateOps.removeAll(TAGS, tagId);
datastore.update(query, updateOps);
} finally {
writeLock.unlock();
}
}
代码示例来源:origin: protegeproject/webprotege
public void setLastLogin(@Nonnull UserId userId, long lastLogin) {
if(userId.isGuest()) {
return;
}
getByUserId(userId);
Query<UserActivityRecord> query = queryByUserId(userId);
UpdateOperations<UserActivityRecord> operations = datastore.createUpdateOperations(UserActivityRecord.class)
.set(LAST_LOGIN, new Date(lastLogin));
datastore.update(query, operations);
}
代码示例来源:origin: protegeproject/webprotege
public void setLastLogout(@Nonnull UserId userId, long lastLogout) {
if(userId.isGuest()) {
return;
}
getByUserId(userId);
Query<UserActivityRecord> query = queryByUserId(userId);
UpdateOperations<UserActivityRecord> operations = datastore.createUpdateOperations(UserActivityRecord.class)
.set(LAST_LOGOUT, new Date(lastLogout));
datastore.update(query, operations);
}
代码示例来源: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: 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);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void updatePush(String jobId, String var, String value) {
Query<LGJob> query = createQuery().field("_id").equal(jobId);
UpdateOperations<LGJob> ops = getDatastore().createUpdateOperations(LGJob.class).add(var, value);
getDatastore().update(query, ops);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void update(String taskId, String var, String value) {
Query<LGTask> query = createQuery().field("_id").equal(taskId);
UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
getDatastore().update(query, ops);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void update(String taskId, String var, long value) {
Query<LGTask> query = createQuery().field("_id").equal(taskId);
UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
getDatastore().update(query, ops);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void update(String jobId, String var, String value) {
Query<LGJob> query = createQuery().field("_id").equal(jobId);
UpdateOperations<LGJob> ops = getDatastore().createUpdateOperations(LGJob.class).set(var, value);
getDatastore().update(query, ops);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void updateInt(String jobId, String var, int value) {
Query<LGJob> query = createQuery().field("_id").equal(jobId);
UpdateOperations<LGJob> ops = getDatastore().createUpdateOperations(LGJob.class).set(var, value);
getDatastore().update(query, ops);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void update(String taskId, String var, boolean value) {
Query<LGTask> query = createQuery().field("_id").equal(taskId);
UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
getDatastore().update(query, ops);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public void updateInt(String taskId, String var, int value) {
Query<LGTask> query = createQuery().field("_id").equal(taskId);
UpdateOperations<LGTask> ops = getDatastore().createUpdateOperations(LGTask.class).set(var, value);
getDatastore().update(query.disableValidation(), ops);
}
代码示例来源: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: protegeproject/webprotege
public void store(ProjectId projectId, CollectionId collectionId, FormId formId, OWLEntity entity, FormData formData) {
Query<FormDataRecord> query = datastore.createQuery(FormDataRecord.class)
.field("projectId").equal(projectId)
.field("collectionId").equal(collectionId)
.field("formId").equal(formId)
.field("subjectId").equal(entity.toString());
UpdateOperations<FormDataRecord> update = datastore.createUpdateOperations(FormDataRecord.class);
update.set("data", formData);
datastore.update(query, update, new UpdateOptions().upsert(true));
}
内容来源于网络,如有侵权,请联系作者删除!