本文整理了Java中org.mongodb.morphia.Datastore
类的一些代码示例,展示了Datastore
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore
类的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
[英]Datastore interface to get/delete/save objects
[中]获取/删除/保存对象的数据存储接口
代码示例来源: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: querydsl/querydsl
@Override
protected DBCollection getCollection(Class<?> type) {
return datastore.getCollection(type);
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void clearWebhooks(@Nonnull ProjectId projectId) {
Query<SlackWebhook> query = datastore.createQuery(SlackWebhook.class).field(PROJECT_ID).equal(projectId);
datastore.delete(query);
}
代码示例来源:origin: protegeproject/webprotege
private Query<UserActivityRecord> queryByUserId(@Nonnull UserId userId) {
return datastore.createQuery(UserActivityRecord.class)
.field(USER_ID).equal(userId);
}
}
代码示例来源:origin: protegeproject/webprotege
public void setApplicationPreferences(@Nonnull ApplicationPreferences preferences) {
writeLock.lock();
try {
cachedPreferences = preferences;
datastore.save(checkNotNull(preferences));
} finally {
writeLock.unlock();
}
}
}
代码示例来源: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: lmco/streamflow
@Override
public T findById(ID id) {
return datastore.get(persistentClass, id);
}
代码示例来源: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
private UserActivityRecord getByUserId(UserId userId) {
UserActivityRecord record = datastore.get(UserActivityRecord.class, userId);
if (record == null) {
datastore.save(record = UserActivityRecord.get(userId));
}
return record;
}
代码示例来源: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 save(@Nonnull EntityTags tag) {
try {
writeLock.lock();
datastore.delete(tagWithProjectIdAndEntity(tag.getProjectId(), tag.getEntity()));
datastore.save(tag);
} finally {
writeLock.unlock();
}
}
代码示例来源:origin: BlackLabs/play-morphia
public static void init(String name) {
Datastore ds = MorphiaPlugin.ds();
Query<Seq> q = ds.find(Seq.class, "_id", name);
if (0 == q.countAll()) {
Seq newId = new Seq(name);
ds.save(newId);
}
return;
}
代码示例来源:origin: lmco/streamflow
@Override
public void delete(T entity) {
if (entity != null) {
datastore.delete(entity);
}
}
代码示例来源: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: 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: org.actframework/act-morphia
/**
* Returns the current number in the sequence specified. If the sequence does not
* exists then `-1` will be returned
* @param name the sequence name
* @return the current number in the sequence.
*/
public long get(String name) {
Sequence seq = ds.find(Sequence.class, "_id", name).get();
return null == seq ? -1 : seq.number;
}
代码示例来源:origin: acmeair/acmeair
@Override
public void invalidateSession(String sessionid) {
Query<CustomerSessionImpl> q = datastore.find(CustomerSessionImpl.class).field("_id").equal(sessionid);
datastore.delete(q);
}
代码示例来源:origin: protegeproject/webprotege
public boolean deleteComment(CommentId commentId) {
Query<EntityDiscussionThread> query = datastore.createQuery(EntityDiscussionThread.class)
.field(COMMENTS_ID).equal(commentId);
UpdateOperations<EntityDiscussionThread> update = getUpdateOperations()
.removeAll(COMMENTS, new BasicDBObject("_id", commentId.getId()));
UpdateResults updateResults = datastore.updateFirst(query, update);
return updateResults.getUpdatedCount() == 1;
}
代码示例来源:origin: protegeproject/webprotege
public Optional<EntityDiscussionThread> setThreadStatus(@Nonnull ThreadId threadId,
@Nonnull Status status) {
datastore.updateFirst(createQueryForThread(threadId), getUpdateOperations().set(STATUS, status));
return Optional.ofNullable(datastore.get(EntityDiscussionThread.class, threadId));
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void ensureIndexes() {
datastore.ensureIndexes(EntityTags.class);
}
内容来源于网络,如有侵权,请联系作者删除!