本文整理了Java中org.mongodb.morphia.Datastore.save()
方法的一些代码示例,展示了Datastore.save()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Datastore.save()
方法的具体详情如下:
包路径:org.mongodb.morphia.Datastore
类名称:Datastore
方法名:save
[英]Saves the entities (Objects) and updates the @Id field
[中]保存实体(对象)并更新@Id字段
代码示例来源: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
public void setApplicationPreferences(@Nonnull ApplicationPreferences preferences) {
writeLock.lock();
try {
cachedPreferences = preferences;
datastore.save(checkNotNull(preferences));
} finally {
writeLock.unlock();
}
}
}
代码示例来源:origin: getheimdall/heimdall
@Override
public <T> T save(T object) {
try {
this.datastore().save(object);
return object;
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
代码示例来源:origin: getheimdall/heimdall
@Override
public <T> T save(T object) {
try {
this.datastore().save(object);
return object;
} catch (Exception e) {
return null;
}
}
代码示例来源:origin: lmco/streamflow
@Override
public T save(T entity) {
Key<T> key = datastore.save(entity);
return datastore.getByKey(persistentClass, key);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
/**
* @param LGAdapterURLs LGAdapterURLs
*/
public void savelgAdapterURLs(LGAdapterURLs LGAdapterURLs) {
getDatastore().save(LGAdapterURLs);
}
代码示例来源:origin: de.mhus.lib/mhu-lib-persistence
public void save(Object obj) {
datastore.save(obj);
if (obj instanceof DbComfortableObject)
((DbComfortableObject)obj).doInit(this, null, true);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
/**
* @param LGdbValue LGdbValue
*/
public void saveDbValues(LGdbValue LGdbValue) {
getDatastore().save(LGdbValue);
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void addWebhooks(@Nonnull List<SlackWebhook> webhooks) {
try {
datastore.save(webhooks, new InsertOptions().continueOnError(true));
} catch (DuplicateKeyException e) {
logger.debug("Ignored duplicate webhook", e);
}
}
}
代码示例来源:origin: protegeproject/webprotege
@Override
public void create(CollectionId collectionId, List<CollectionItem> items) {
List<CollectionItemData> data = items.stream()
.map(item -> new CollectionItemData(collectionId, item))
.collect(toList());
datastore.save(data, new InsertOptions().continueOnError(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
public void save(UserActivityRecord record) {
if(record.getUserId().isGuest()) {
return;
}
datastore.save(record);
}
代码示例来源:origin: groupon/DotCi
public ObjectId saveOrUpdate(final DbBackedProject project) {
getDatastore().save(project);
return project.getId();
}
代码示例来源: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: stackoverflow.com
Morphia morphia = new Morphia();
Datastore datastore = morphia.createDatastore(new MongoClient(), "test");
Person johnDoe = new Person("John", "Doe");
//saves John Doe on DB
datastore.save(johnDoe);
//retrieves all people whose first name is John
List<Person> people = datastore.createQuery(Person.class).filter("firstName", "John").asList();
System.out.println(people.size()); //prints 1
Person person = people.get(0);
System.out.println(person); //prints John Doe
代码示例来源:origin: acmeair/acmeair
public String bookFlight(String customerId, String flightId) {
try{
Flight f = flightService.getFlightByFlightId(flightId, null);
Customer c = customerService.getCustomerByUsername(customerId);
Booking newBooking = new BookingImpl(keyGenerator.generate().toString(), new Date(), c, f);
datastore.save(newBooking);
return newBooking.getBookingId();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源: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: 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: NationalSecurityAgency/lemongrenade
public void deleteTaskFromJob(LGJob jobIn, LGTask task) {
LGJob job = getByJobId(jobIn.getJobId());
// Need to remove the reference first!
job.delTask(task.getTaskId());
getDatastore().save(job);
taskDAO.delete(task);
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!