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(); } }
@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(); } }
@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(); } }
@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(); } }
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());
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();
private void save(final SegmentHunk hunk) { ofy().save().entity(hunk); crc.update(hunk.bytes, lastFlushIndex, writer.position - lastFlushIndex); lastFlushIndex = writer.position; }
@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(); } }
public Key<T> put(T entity) { return ofy().save().entity(entity).now(); }
/** * 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; }
@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)); }
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 */ } /*
@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!"); } });
@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!"); } });
@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); } });
@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); } });
@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); } });
@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; } });
@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); } });
@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); }