All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.objectify.impl.translate.SaveContext Maven / Gradle / Ivy

There is a newer version: 6.1.3
Show newest version
package com.googlecode.objectify.impl.translate;

import com.google.appengine.api.datastore.Key;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import com.googlecode.objectify.Ref;
import com.googlecode.objectify.impl.LoadConditions;
import com.googlecode.objectify.impl.Path;

import java.util.Collection;
import java.util.Map;

/**
 * The context of a save operation; might involve multiple entities (eg, batch save).
 *
 * @author Jeff Schnitzer 
 */
public class SaveContext
{
	/**
	 * Track all indexed values here. We may need to use some of this data to create synthetic
	 * indexes at the top level (ie, dot-separated indexes for v2 embedded saves).
	 */
	private final SetMultimap indexes = HashMultimap.create();

	/**
	 * @param object can be either a single thing or an iterable list of things to index at this path
	 */
	public void addIndex(Path path, Object object) {
		if (object instanceof Iterable)
			indexes.putAll(path, (Iterable)object);
		else
			indexes.put(path, object);
	}
	
	/** */
	public Map> getIndexes() {
		return indexes.asMap();
	}

	/**
	 * Subclass can ignore lifecycle methods.
	 */
	public boolean skipLifecycle() {
		return false;
	}

	/**
	 * Callback that we found a Ref in the object graph. Subclasses of this context may want to do something
	 * special with this.
	 */
	public Key saveRef(Ref value, LoadConditions loadConditions) {
		return value.key().getRaw();
	}

	/**
	 * Called at the beginning of each entity save. In a batch save, this will be called more than once.
	 */
	public void startOneEntity() {
		indexes.clear();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy