/** * Create a Ref based on the key */ public LiveRef(Key<T> key) { this(key, ObjectifyService.ofy()); }
protected Objectify ofy() { return ObjectifyService.ofy(); }
/** * Get the current objectify instance associated with this ref */ private Objectify ofy() { // If we have an expired transaction context, we need a new context if (ofy == null || (ofy.getTransaction() != null && !ofy.getTransaction().isActive())) ofy = ObjectifyService.ofy(); return ofy; }
@Override public String load(String courseId) { List<Instructor> instructors = ofy().load().type(Instructor.class).filter("courseId =", courseId).list(); for (Instructor instructor : instructors) { if (StringHelper.isEmpty(instructor.getGoogleId())) { continue; } Account account = ofy().load().key(Key.create(Account.class, instructor.getGoogleId())).now(); if (account != null && !StringHelper.isEmpty(account.getInstitute())) { return account.getInstitute(); } } return UNKNOWN_INSTITUTE; } });
@Override public Void run() { deleteSegment(ofy(), name); return null; } });
/** * Returns every available indexes created into your GAE application. * With {@link LuceneIndex} you can build {@link GaeDirectory} * using constructor {@link GaeDirectory#GaeDirectory(LuceneIndex)}. * @return A list of available indexes */ public static List<LuceneIndex> getAvailableIndexes() { return ofy().load().type(LuceneIndex.class).list(); } /**
@Override public JobStatus getJobStatus(UUID jobStatus) { return ofy().load().type(JobStatus.class).id(jobStatus.toString()).now(); }
@Override public long fileLength(String name) throws IOException { final Segment bigTableIndexFile = ofy().load().key(newSegmentKey(name)).now(); return bigTableIndexFile.length; } /*
@Override public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException { final String tempName = prefix + "_" + UUID.randomUUID().toString() + "_" + suffix; ensureOpen(); final Objectify begin = ofy(); Segment segment = begin.load().key(newSegmentKey(tempName)).now(); if(segment == null) { segment = newSegment(tempName); } return new SegmentIndexOutput(segment); }
protected List<E> loadInternal(Iterable<Key<E>> keys) { if (Expressive.isEmpty(keys)) { return Collections.<E> emptyList(); } Map<Key<E>, E> results = ofy().load().keys(keys); return Expressive.Transformers.transformAllUsing(Expressive.Transformers.usingLookup(results)).from(keys); }
@Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); try { return new SegmentIndexInput(ofy().load().key(newSegmentKey(name)).safe()); } catch (NotFoundException e) { throw new IOException(name, e); } } /*
@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 run() { Objectify objectify = ofy(); for(String name : listAll()) deleteSegment(objectify, name); objectify.delete().key(indexKey); objectify.delete().entities(((GaeLockFactory)lockFactory).getLocks(GaeDirectory.this)); return null; } });
@Override public IndexOutput createOutput(String name, IOContext context) throws IOException { ensureOpen(); final Objectify begin = ofy(); Segment segment = begin.load().key(newSegmentKey(name)).now(); if(segment == null) { segment = newSegment(name); } return new SegmentIndexOutput(segment); }
@Override public void deleteFile(String name) { final Objectify objectify = ofy(); final Segment segment = objectify.load().key(newSegmentKey(name)).now(); final long hunkCount = segment.hunkCount; for (int i = 1; i <= hunkCount; i++) { objectify.delete().key(newSegmentHunkKey(name, i)); } objectify.delete().key(newSegmentKey(name)); } @Override
@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); }