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

se.l4.silo.structured.StructuredEntity Maven / Gradle / Ivy

The newest version!
package se.l4.silo.structured;

import java.util.function.Function;

import se.l4.commons.serialization.Serializer;
import se.l4.commons.serialization.SerializerCollection;
import se.l4.commons.serialization.format.StreamingInput;
import se.l4.silo.DeleteResult;
import se.l4.silo.Entity;
import se.l4.silo.FetchResult;
import se.l4.silo.StoreResult;
import se.l4.silo.query.Query;
import se.l4.silo.query.QueryType;

/**
 * Entity for storing structured data. Anything that can be represented as
 * a {@link StreamingInput} is considered structured data.
 *
 * @author Andreas Holstenson
 *
 */
public interface StructuredEntity
	extends Entity
{
	/**
	 * Get data stored for the given identifier.
	 *
	 * @param id
	 * @return
	 */
	FetchResult get(Object id);

	/**
	 * Store new data and associate it with the given identifier.
	 *
	 * @param id
	 * @param out
	 * @return
	 */
	StoreResult store(Object id, StreamingInput out);

	/**
	 * Delete data associated with the given identifier.
	 *
	 * @param id
	 * @return
	 */
	DeleteResult delete(Object id);

	/**
	 * Query the the query engine.
	 *
	 * @param index
	 * @return
	 */
	> Q query(String engine, QueryType type);

	/**
	 * Stream everything in this entry.
	 *
	 * @return
	 */
	FetchResult stream();

	/**
	 * Get an entity that translates the structured data into objects. This
	 * will call {@link #asObject(Serializer)} with a serializer fetched
	 * from the current {@link SerializerCollection}.
	 *
	 * @param type
	 * @return
	 */
	 ObjectEntity asObject(Class type, Function identityMapper);

	/**
	 * Get an entity that translates the structured data into objects.
	 *
	 * @param serializer
	 * @return
	 */
	default  ObjectEntity asObject(Serializer serializer, Function identityMapper)
	{
		return new DefaultObjectEntity<>(this, serializer, identityMapper);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy