src/main/java/com/googlecode/objectify/impl/Round.java
public <T> Result<T> get(final Key<T> key) {
		assert !isExecuted();

		SessionValue<T> sv = getSession().get(key);
		if (sv == null) {
			log.trace("Adding to round (session miss): {}", key);

			this.pending.add(key.getRaw());

			Result<T> result = new ResultCache<T>() {
				@Override
				@SuppressWarnings("unchecked")
				public T nowUncached() {
					// Because clients could conceivably get() in the middle of our operations (see LoadCollectionRefsTest.specialListWorks()),
					// we need to check for early execution. This will perform poorly, but at least it will work.
					//assert Round.this.isExecuted();
					loadEngine.execute();
					return (T)translated.now().get(key);
				}

				@Override
				public String toString() {
					return "(Fetch result for " + key + ")";
				}
			};

			sv = new SessionValue<>(result, getLoadArrangement());
			getSession().add(key, sv);

		} else {
			log.trace("Adding to round (session hit): {}", key);

			if (sv.loadWith(getLoadArrangement())) {
				log.trace("New load group arrangement, checking for upgrades: {}", getLoadArrangement());

				// We are looking at a brand-new arrangement for something that already existed in the session.
				// We need to go through any Ref<?>s that might be in need of loading. We find those refs by
				// actually saving the entity into a custom SaveContext.
				T thing = sv.getResult().now();
				if (thing != null) {
					SaveContext saveCtx = new SaveContext() {
						@Override
						public boolean skipLifecycle() {
							return true;
						}

						@Override
						public com.google.cloud.datastore.Key saveRef(Ref<?> value, LoadConditions loadConditions) {
							com.google.cloud.datastore.Key key = super.saveRef(value, loadConditions);

							if (loadEngine.shouldLoad(loadConditions)) {
								log.trace("Upgrading key {}", key);
								loadEngine.load(value.key());
							}

							return key;
						}
					};

					// We throw away the saved entity and we are done
					loadEngine.ofy.factory().getMetadataForEntity(thing).save(thing, saveCtx);
				}
			}
		}

		return sv.getResult();
	}
public <T> Result<T> get(final Key<T> key) {
		assert !isExecuted();

		SessionValue<T> sv = getSession().get(key);
		if (sv == null) {
			log.trace("Adding to round (session miss): {}", key);

			this.pending.add(key.getRaw());

			Result<T> result = new ResultCache<T>() {
				@Override
				@SuppressWarnings("unchecked")
				public T nowUncached() {
					// Because clients could conceivably get() in the middle of our operations (see LoadCollectionRefsTest.specialListWorks()),
					// we need to check for early execution. This will perform poorly, but at least it will work.
					//assert Round.this.isExecuted();
					loadEngine.execute();
					return (T)translated.now().get(key);
				}

				@Override
				public String toString() {
					return "(Fetch result for " + key + ")";
				}
			};

			sv = new SessionValue<>(result, getLoadArrangement());
			getSession().add(key, sv);

		} else {
			log.trace("Adding to round (session hit): {}", key);

			if (sv.loadWith(getLoadArrangement())) {
				log.trace("New load group arrangement, checking for upgrades: {}", getLoadArrangement());

				// We are looking at a brand-new arrangement for something that already existed in the session.
				// We need to go through any Ref<?>s that might be in need of loading. We find those refs by
				// actually saving the entity into a custom SaveContext.
				T thing = sv.getResult().now();
				if (thing != null) {
					SaveContext saveCtx = new SaveContext() {
						@Override
						public boolean skipLifecycle() {
							return true;
						}

						@Override
						public com.google.cloud.datastore.Key saveRef(Ref<?> value, LoadConditions loadConditions) {
							com.google.cloud.datastore.Key key = super.saveRef(value, loadConditions);

							if (loadEngine.shouldLoad(loadConditions)) {
								log.trace("Upgrading key {}", key);
								loadEngine.load(value.key());
							}

							return key;
						}
					};

					// We throw away the saved entity and we are done
					loadEngine.ofy.factory().getMetadataForEntity(thing).save(thing, saveCtx);
				}
			}
		}

		return sv.getResult();
	}
public < T > Result < T > get ( final Key < T > key ) { assert ! isExecuted ( ) ; SessionValue < T > sv = getSession ( ) . get ( key ) ; if ( sv == null ) { log . trace ( "Adding to round (session miss): {}" , key ) ; this . pending . add ( key . getRaw ( ) ) ; Result < T > result = new ResultCache < T > ( ) { @ Override @ SuppressWarnings ( "unchecked" ) public T nowUncached ( ) { // Because clients could conceivably get() in the middle of our operations (see LoadCollectionRefsTest.specialListWorks()), // we need to check for early execution. This will perform poorly, but at least it will work. //assert Round.this.isExecuted(); loadEngine . execute ( ) ; return ( T ) translated . now ( ) . get ( key ) ; } @ Override public String toString ( ) { return "(Fetch result for " + key + ")" ; } } ; sv = new SessionValue <> ( result , getLoadArrangement ( ) ) ; getSession ( ) . add ( key , sv ) ; } else { log . trace ( "Adding to round (session hit): {}" , key ) ; if ( sv . loadWith ( getLoadArrangement ( ) ) ) { log . trace ( "New load group arrangement, checking for upgrades: {}" , getLoadArrangement ( ) ) ; // We are looking at a brand-new arrangement for something that already existed in the session. // We need to go through any Ref<?>s that might be in need of loading. We find those refs by // actually saving the entity into a custom SaveContext. T thing = sv . getResult ( ) . now ( ) ; if ( thing != null ) { SaveContext saveCtx = new SaveContext ( ) { @ Override public boolean skipLifecycle ( ) { return true ; } @ Override public com . google . cloud . datastore . Key saveRef ( Ref < ? > value , LoadConditions loadConditions ) { com . google . cloud . datastore . Key key = super . saveRef ( value , loadConditions ) ; if ( loadEngine . shouldLoad ( loadConditions ) ) { log . trace ( "Upgrading key {}" , key ) ; loadEngine . load ( value . key ( ) ) ; } return key ; } } ; // We throw away the saved entity and we are done loadEngine . ofy . factory ( ) . getMetadataForEntity ( thing ) . save ( thing , saveCtx ) ; } } } return sv . getResult ( ) ; }
Gets a result, using the session cache if possible.
Gets a result using the session cache if possible .