本文整理了Java中com.googlecode.objectify.Objectify.save()
方法的一些代码示例,展示了Objectify.save()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Objectify.save()
方法的具体详情如下:
包路径:com.googlecode.objectify.Objectify
类名称:Objectify
方法名:save
[英]Start a save command chain. Allows you to save (or re-save) entity objects. Note that all command chain objects are immutable.
Saves do NOT cascade; if you wish to save an object graph, you must save each individual entity.
A quick example: ofy().save().entities(e1, e2, e3).now();
All command objects are immutable; this method returns a new object rather than modifying the current command object.
[中]启动保存命令链。允许您保存(或重新保存)实体对象。请注意,所有命令链对象都是不可变的。
储蓄不会层叠;如果要保存对象图,必须保存每个实体。
一个简单的例子:ofy()。save()。实体(e1、e2、e3)。现在();
所有命令对象都是不可变的;此方法返回一个新对象,而不是修改当前命令对象。
代码示例来源:origin: objectify/objectify
public void flush() {
final List<Result<?>> futures = new ArrayList<>();
// Need to do this in a loop because @OnSave methods can enlist more deferred operations. Execution
// of save or delete will undefer() all the relevant items, so both lists empty mean we're done.
while (!operations.isEmpty() || !autogeneratedIdSaves.isEmpty()) {
// Sort into two batch operations: one for save, one for delete.
final List<Object> saves = new ArrayList<>();
final List<Key<?>> deletes = new ArrayList<>();
for (final Map.Entry<Key<?>, Object> entry : operations.entrySet()) {
if (entry.getValue() == null)
deletes.add(entry.getKey());
else
saves.add(entry.getValue());
}
saves.addAll(autogeneratedIdSaves);
if (!saves.isEmpty())
futures.add(ofy.save().entities(saves));
if (!deletes.isEmpty())
futures.add(ofy.delete().keys(deletes));
}
// Complete any pending operations
for (final Result<?> future : futures) {
future.now();
}
}
代码示例来源:origin: TEAMMATES/teammates
@Override
protected void migrateEntity(Key<FeedbackResponseComment> entity) {
FeedbackResponseComment comment = ofy().load().key(entity).now();
comment.setCommentGiverType(FeedbackParticipantType.INSTRUCTORS);
comment.setIsCommentFromFeedbackParticipant(false);
ofy().save().entity(comment).now();
}
}
代码示例来源:origin: TEAMMATES/teammates
@Override
protected void migrateEntity(Key<Course> key) throws Exception {
Course course = ofy().load().key(key).now();
course.setName(SanitizationHelper.desanitizeIfHtmlSanitized(course.getName()));
ofy().save().entity(course).now();
}
}
代码示例来源:origin: TEAMMATES/teammates
@Override
protected void migrateEntity(Key<Instructor> key) throws Exception {
Instructor instructor = ofy().load().key(key).now();
instructor.setDisplayedName(SanitizationHelper.desanitizeIfHtmlSanitized(instructor.getDisplayedName()));
ofy().save().entity(instructor).now();
}
}
代码示例来源:origin: stackoverflow.com
Date date = new Date();
Objectify ofy = ObjectifyService.ofy();
ObjectifyService.register(EntityDate.class);
EntityDate entityDate = new EntityDate();
entityDate.date = date;
ofy.save().entities(entityDate);
Query<EntityDate> ofyQuery = ofy.load().type(EntityDate.class).order("date");
ofyQuery = ofyQuery.filter("date <", date);
List<EntityDate> list = ofyQuery.list();
Logger.getLogger("EntityDate").info(list.toString());
代码示例来源:origin: TEAMMATES/teammates
ofy().save().entities(oldStudents).now();
ofy().save().entities(oldInstructors).now();
instructorsDb.putDocuments(
oldInstructors.stream().map(InstructorAttributes::valueOf).collect(Collectors.toList()));
ofy().save().entity(oldAccount).now();
} else {
println(String.format("Skip creation of new account as account (%s) already exists", newGoogleId));
ofy().save().entity(oldStudentProfile).now();
ofy().delete().key(oldStudentProfileKey).now();
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
private void save(final SegmentHunk hunk) {
ofy().save().entity(hunk);
crc.update(hunk.bytes, lastFlushIndex, writer.position - lastFlushIndex);
lastFlushIndex = writer.position;
}
代码示例来源:origin: TEAMMATES/teammates
@Override
protected void migrateEntity(Key<CourseStudent> key) throws Exception {
CourseStudent student = ofy().load().key(key).now();
student.setComments(SanitizationHelper.desanitizeIfHtmlSanitized(student.getComments()));
student.setName(SanitizationHelper.desanitizeIfHtmlSanitized(student.getName()));
student.setLastName(SanitizationHelper.desanitizeIfHtmlSanitized(student.getLastName()));
ofy().save().entity(student).now();
}
}
代码示例来源:origin: ArcBees/GWTP
public Key<T> put(T entity) {
return ofy().save().entity(entity).now();
}
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
/**
* Create a new segment with the specified name using the specified {@link Objectify}.
* The {@link Segment} contains one empty {@link SegmentHunk}.
* @param name The name of the segment to create
* @return A new {@link Segment} with one {@link SegmentHunk}
*/
protected Segment newSegment(String name) {
Segment segment = new Segment(indexKey, name);
SegmentHunk newHunk = segment.newHunk();//at least one segment
segment.lastModified = System.currentTimeMillis();
ofy().save().entities(segment, newHunk).now();
log.debug("Created segment '{}'.", name);
return segment;
}
代码示例来源:origin: instacount/appengine-counter
@Test
public void testGetCounter_Deleting() throws Exception
{
final String counterName = UUID.randomUUID().toString();
final CounterData counterData = impl.getOrCreateCounterData(counterName).getCounterData();
counterData.setCounterStatus(CounterStatus.DELETING);
ObjectifyService.ofy().save().entity(counterData).now();
final Counter counter = impl.getCounter(counterName).get();
assertThat(counter, is(not(nullValue())));
assertThat(counter.getCount(), is(BigInteger.ZERO));
assertThat(counter.getIndexes(), is(NO_INDEXES));
}
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
public void flush() throws IOException {
segment.lastModified = System.currentTimeMillis();
writer.flush();
hunk.bytes = writer.getBytes();
ofy().save().entity(segment);
save(hunk);
ofy().flush();
PendingFutures.completeAllPendingFutures();
/* nothing to do */
}
/*
代码示例来源:origin: instacount/appengine-counter
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
ObjectifyService.ofy().save().entity(counterShardDataKey);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
throw new RuntimeException("Abort the Transaction!");
}
});
代码示例来源:origin: instacount/appengine-counter
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
ObjectifyService.ofy().save().entity(counterShardDataKey);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
throw new RuntimeException("Abort the Transaction!");
}
});
代码示例来源:origin: instacount/appengine-counter
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
代码示例来源:origin: instacount/appengine-counter
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
代码示例来源:origin: instacount/appengine-counter
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
代码示例来源:origin: com.googlecode.luceneappengine/luceneappengine
@Override
public T run() {
T t = ofy().load().key(key).now();
if(t == null) {
t = builder.newInstance(key);
ofy().save().entity(t).now();
}
return t;
}
});
代码示例来源:origin: instacount/appengine-counter
@Override
public void vrun()
{
// Do something else as part of the TX.
final Key<CounterShardData> counterShardDataKey = CounterShardData.key(
CounterData.key(UUID.randomUUID().toString()), 0);
final CounterShardData counterShardData = new CounterShardData(counterShardDataKey);
ObjectifyService.ofy().save().entity(counterShardData);
// The actual test.
singleShardShardedCounterService.increment(counterName, 10L);
}
});
代码示例来源:origin: instacount/appengine-counter
@Test(expected = RuntimeException.class)
public void testDecrement_CounterIsBeingDeleted() throws InterruptedException
{
// Store this in the Datastore to trigger the exception below...
CounterData counterData = new CounterData(TEST_COUNTER1, 1);
counterData.setCounterStatus(CounterStatus.DELETING);
ObjectifyService.ofy().save().entity(counterData).now();
shardedCounterService.decrement(TEST_COUNTER1, 1);
}
内容来源于网络,如有侵权,请联系作者删除!